BooleanNode.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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('Invalid type for path "%s". Expected boolean, but got %s.', $this->getPath(), \gettype($value)));
  26. if ($hint = $this->getInfo()) {
  27. $ex->addHint($hint);
  28. }
  29. $ex->setPath($this->getPath());
  30. throw $ex;
  31. }
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. protected function isValueEmpty($value)
  37. {
  38. // a boolean value cannot be empty
  39. return false;
  40. }
  41. }