FloatNode.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\InvalidTypeException;
  12. /**
  13. * This node represents a float value in the config tree.
  14. *
  15. * @author Jeanmonod David <david.jeanmonod@gmail.com>
  16. */
  17. class FloatNode extends NumericNode
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected function validateType($value)
  23. {
  24. // Integers are also accepted, we just cast them
  25. if (\is_int($value)) {
  26. $value = (float) $value;
  27. }
  28. if (!\is_float($value)) {
  29. $ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "float", but got "%s".', $this->getPath(), get_debug_type($value)));
  30. if ($hint = $this->getInfo()) {
  31. $ex->addHint($hint);
  32. }
  33. $ex->setPath($this->getPath());
  34. throw $ex;
  35. }
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. protected function getValidPlaceholderTypes(): array
  41. {
  42. return ['float'];
  43. }
  44. }