BaseStringUtils.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 string data type.
  11. */
  12. class BaseStringUtils implements InterpreterInterface
  13. {
  14. /**
  15. * @var BooleanUtils
  16. */
  17. private $booleanUtils;
  18. /**
  19. * BaseStringUtils constructor.
  20. *
  21. * @param BooleanUtils $booleanUtils
  22. */
  23. public function __construct(BooleanUtils $booleanUtils)
  24. {
  25. $this->booleanUtils = $booleanUtils;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. * @return string
  30. * @throws \InvalidArgumentException
  31. */
  32. public function evaluate(array $data)
  33. {
  34. if (isset($data['value'])) {
  35. $result = $data['value'];
  36. if (!is_string($result)) {
  37. throw new \InvalidArgumentException('String value is expected.');
  38. }
  39. } else {
  40. $result = '';
  41. }
  42. return $result;
  43. }
  44. }