2021-05-10 00:23:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
2022-05-17 09:51:50 +00:00
|
|
|
namespace RectorPrefix20220517\Symfony\Component\Config\Definition;
|
2021-05-10 00:23:30 +00:00
|
|
|
|
2022-05-17 09:51:50 +00:00
|
|
|
use RectorPrefix20220517\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
2021-05-10 00:23:30 +00:00
|
|
|
/**
|
|
|
|
* This node represents a numeric value in the config tree.
|
|
|
|
*
|
|
|
|
* @author David Jeanmonod <david.jeanmonod@gmail.com>
|
|
|
|
*/
|
2022-05-17 09:51:50 +00:00
|
|
|
class NumericNode extends \RectorPrefix20220517\Symfony\Component\Config\Definition\ScalarNode
|
2021-05-10 00:23:30 +00:00
|
|
|
{
|
|
|
|
protected $min;
|
|
|
|
protected $max;
|
2021-06-17 14:59:13 +00:00
|
|
|
/**
|
2022-04-26 08:13:18 +00:00
|
|
|
* @param int|float $min
|
|
|
|
* @param int|float $max
|
2021-06-17 14:59:13 +00:00
|
|
|
*/
|
2022-05-17 09:51:50 +00:00
|
|
|
public function __construct(?string $name, \RectorPrefix20220517\Symfony\Component\Config\Definition\NodeInterface $parent = null, $min = null, $max = null, string $pathSeparator = \RectorPrefix20220517\Symfony\Component\Config\Definition\BaseNode::DEFAULT_PATH_SEPARATOR)
|
2021-05-10 00:23:30 +00:00
|
|
|
{
|
|
|
|
parent::__construct($name, $parent, $pathSeparator);
|
|
|
|
$this->min = $min;
|
|
|
|
$this->max = $max;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
2022-02-14 01:03:53 +00:00
|
|
|
* @param mixed $value
|
|
|
|
* @return mixed
|
2021-05-10 00:23:30 +00:00
|
|
|
*/
|
|
|
|
protected function finalizeValue($value)
|
|
|
|
{
|
|
|
|
$value = parent::finalizeValue($value);
|
|
|
|
$errorMsg = null;
|
|
|
|
if (isset($this->min) && $value < $this->min) {
|
|
|
|
$errorMsg = \sprintf('The value %s is too small for path "%s". Should be greater than or equal to %s', $value, $this->getPath(), $this->min);
|
|
|
|
}
|
|
|
|
if (isset($this->max) && $value > $this->max) {
|
|
|
|
$errorMsg = \sprintf('The value %s is too big for path "%s". Should be less than or equal to %s', $value, $this->getPath(), $this->max);
|
|
|
|
}
|
|
|
|
if (isset($errorMsg)) {
|
2022-05-17 09:51:50 +00:00
|
|
|
$ex = new \RectorPrefix20220517\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException($errorMsg);
|
2021-05-10 00:23:30 +00:00
|
|
|
$ex->setPath($this->getPath());
|
|
|
|
throw $ex;
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
2022-02-14 01:03:53 +00:00
|
|
|
* @param mixed $value
|
2021-05-10 00:23:30 +00:00
|
|
|
*/
|
2022-02-14 01:03:53 +00:00
|
|
|
protected function isValueEmpty($value) : bool
|
2021-05-10 00:23:30 +00:00
|
|
|
{
|
|
|
|
// a numeric value cannot be empty
|
|
|
|
return \false;
|
|
|
|
}
|
|
|
|
}
|