NamedParams.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Layout\Argument\Interpreter;
  7. use Magento\Framework\Data\Argument\InterpreterInterface;
  8. /**
  9. * Interpreter of named parameters
  10. */
  11. class NamedParams implements InterpreterInterface
  12. {
  13. /**
  14. * Interpreter of individual parameter
  15. *
  16. * @var InterpreterInterface
  17. */
  18. private $paramInterpreter;
  19. /**
  20. * @param InterpreterInterface $paramInterpreter
  21. */
  22. public function __construct(InterpreterInterface $paramInterpreter)
  23. {
  24. $this->paramInterpreter = $paramInterpreter;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. * @return array
  29. * @throws \InvalidArgumentException
  30. */
  31. public function evaluate(array $data)
  32. {
  33. $params = isset($data['param']) ? $data['param'] : [];
  34. if (!is_array($params)) {
  35. throw new \InvalidArgumentException('Layout argument parameters are expected to be an array.');
  36. }
  37. $result = [];
  38. foreach ($params as $paramKey => $paramData) {
  39. if (!is_array($paramData)) {
  40. throw new \InvalidArgumentException('Parameter data of layout argument is expected to be an array.');
  41. }
  42. $result[$paramKey] = $this->paramInterpreter->evaluate($paramData);
  43. }
  44. return $result;
  45. }
  46. }