BooleanNode.php 939 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 Boolean value in the config tree.
  14. *
  15. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16. */
  17. class BooleanNode extends ScalarNode
  18. {
  19. /**
  20. * {@inheritDoc}
  21. */
  22. protected function validateType($value)
  23. {
  24. if (!is_bool($value)) {
  25. $ex = new InvalidTypeException(sprintf(
  26. 'Invalid type for path "%s". Expected boolean, but got %s.',
  27. $this->getPath(),
  28. gettype($value)
  29. ));
  30. $ex->setPath($this->getPath());
  31. throw $ex;
  32. }
  33. }
  34. }