ScalarNode.php 1.1 KB

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