ScalarNode.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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(
  33. 'Invalid type for path "%s". Expected scalar, but got %s.',
  34. $this->getPath(),
  35. gettype($value)
  36. ));
  37. if ($hint = $this->getInfo()) {
  38. $ex->addHint($hint);
  39. }
  40. $ex->setPath($this->getPath());
  41. throw $ex;
  42. }
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. protected function isValueEmpty($value)
  48. {
  49. return null === $value || '' === $value;
  50. }
  51. }