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

  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.     protected function finalizeValue(mixed $value): mixed
  28.     {
  29.         $value parent::finalizeValue($value);
  30.         $errorMsg null;
  31.         if (isset($this->min) && $value $this->min) {
  32.             $errorMsg sprintf('The value %s is too small for path "%s". Should be greater than or equal to %s'$value$this->getPath(), $this->min);
  33.         }
  34.         if (isset($this->max) && $value $this->max) {
  35.             $errorMsg sprintf('The value %s is too big for path "%s". Should be less than or equal to %s'$value$this->getPath(), $this->max);
  36.         }
  37.         if (isset($errorMsg)) {
  38.             $ex = new InvalidConfigurationException($errorMsg);
  39.             $ex->setPath($this->getPath());
  40.             throw $ex;
  41.         }
  42.         return $value;
  43.     }
  44.     protected function isValueEmpty(mixed $value): bool
  45.     {
  46.         // a numeric value cannot be empty
  47.         return false;
  48.     }
  49. }