vendor/symfony/config/Definition/NumericNode.php line 30

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Config\Definition;
  11. use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
  12. /**
  13.  * This node represents a numeric value in the config tree.
  14.  *
  15.  * @author David Jeanmonod <david.jeanmonod@gmail.com>
  16.  */
  17. class NumericNode extends ScalarNode
  18. {
  19.     protected $min;
  20.     protected $max;
  21.     /**
  22.      * @param int|float|null $min
  23.      * @param int|float|null $max
  24.      */
  25.     public function __construct(?string $nameNodeInterface $parent null$min null$max nullstring $pathSeparator BaseNode::DEFAULT_PATH_SEPARATOR)
  26.     {
  27.         parent::__construct($name$parent$pathSeparator);
  28.         $this->min $min;
  29.         $this->max $max;
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     protected function finalizeValue($value)
  35.     {
  36.         $value parent::finalizeValue($value);
  37.         $errorMsg null;
  38.         if (isset($this->min) && $value $this->min) {
  39.             $errorMsg sprintf('The value %s is too small for path "%s". Should be greater than or equal to %s'$value$this->getPath(), $this->min);
  40.         }
  41.         if (isset($this->max) && $value $this->max) {
  42.             $errorMsg sprintf('The value %s is too big for path "%s". Should be less than or equal to %s'$value$this->getPath(), $this->max);
  43.         }
  44.         if (isset($errorMsg)) {
  45.             $ex = new InvalidConfigurationException($errorMsg);
  46.             $ex->setPath($this->getPath());
  47.             throw $ex;
  48.         }
  49.         return $value;
  50.     }
  51.     /**
  52.      * {@inheritdoc}
  53.      */
  54.     protected function isValueEmpty($value)
  55.     {
  56.         // a numeric value cannot be empty
  57.         return false;
  58.     }
  59. }