ScalarNode.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 scalar value in the config tree.
  14. *
  15. * The following values are considered scalars:
  16. * * booleans
  17. * * strings
  18. * * null
  19. * * integers
  20. * * floats
  21. *
  22. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  23. */
  24. class ScalarNode extends VariableNode
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. protected function validateType($value)
  30. {
  31. if (!is_scalar($value) && null !== $value) {
  32. $ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected scalar, but got %s.', $this->getPath(), \gettype($value)));
  33. if ($hint = $this->getInfo()) {
  34. $ex->addHint($hint);
  35. }
  36. $ex->setPath($this->getPath());
  37. throw $ex;
  38. }
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function isValueEmpty($value)
  44. {
  45. return null === $value || '' === $value;
  46. }
  47. }