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

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.     public function __construct(?string $nameNodeInterface $parent nullint|float $min nullint|float $max nullstring $pathSeparator BaseNode::DEFAULT_PATH_SEPARATOR)
  22.     {
  23.         parent::__construct($name$parent$pathSeparator);
  24.         $this->min $min;
  25.         $this->max $max;
  26.     }
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     protected function finalizeValue(mixed $value): mixed
  31.     {
  32.         $value parent::finalizeValue($value);
  33.         $errorMsg null;
  34.         if (isset($this->min) && $value $this->min) {
  35.             $errorMsg sprintf('The value %s is too small for path "%s". Should be greater than or equal to %s'$value$this->getPath(), $this->min);
  36.         }
  37.         if (isset($this->max) && $value $this->max) {
  38.             $errorMsg sprintf('The value %s is too big for path "%s". Should be less than or equal to %s'$value$this->getPath(), $this->max);
  39.         }
  40.         if (isset($errorMsg)) {
  41.             $ex = new InvalidConfigurationException($errorMsg);
  42.             $ex->setPath($this->getPath());
  43.             throw $ex;
  44.         }
  45.         return $value;
  46.     }
  47.     /**
  48.      * {@inheritdoc}
  49.      */
  50.     protected function isValueEmpty(mixed $value): bool
  51.     {
  52.         // a numeric value cannot be empty
  53.         return false;
  54.     }
  55. }