Boolean.php 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Data\Argument\Interpreter;
  7. use Magento\Framework\Data\Argument\InterpreterInterface;
  8. use Magento\Framework\Stdlib\BooleanUtils;
  9. /**
  10. * Interpreter of boolean data type, such as boolean itself or boolean string
  11. */
  12. class Boolean implements InterpreterInterface
  13. {
  14. /**
  15. * @var BooleanUtils
  16. */
  17. private $booleanUtils;
  18. /**
  19. * @param BooleanUtils $booleanUtils
  20. */
  21. public function __construct(BooleanUtils $booleanUtils)
  22. {
  23. $this->booleanUtils = $booleanUtils;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. * @return bool
  28. * @throws \InvalidArgumentException
  29. */
  30. public function evaluate(array $data)
  31. {
  32. if (!isset($data['value'])) {
  33. throw new \InvalidArgumentException('Boolean value is missing.');
  34. }
  35. $value = $data['value'];
  36. return $this->booleanUtils->toBoolean($value);
  37. }
  38. }