Composite.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Design\Fallback\Rule;
  7. /**
  8. * Composite Rules
  9. *
  10. * Composite rule that represents sequence of child fallback rules
  11. */
  12. class Composite implements RuleInterface
  13. {
  14. /**
  15. * Rules
  16. *
  17. * @var RuleInterface[]
  18. */
  19. protected $rules = [];
  20. /**
  21. * Constructors
  22. *
  23. * @param RuleInterface[] $rules
  24. * @throws \InvalidArgumentException
  25. */
  26. public function __construct(array $rules)
  27. {
  28. foreach ($rules as $rule) {
  29. if (!$rule instanceof RuleInterface) {
  30. throw new \InvalidArgumentException('Each item should implement the fallback rule interface.');
  31. }
  32. }
  33. $this->rules = $rules;
  34. }
  35. /**
  36. * Retrieve sequentially combined directory patterns from child fallback rules
  37. *
  38. * @param array $params
  39. * @return array
  40. */
  41. public function getPatternDirs(array $params)
  42. {
  43. $result = [];
  44. foreach ($this->rules as $rule) {
  45. $result = array_merge($result, $rule->getPatternDirs($params));
  46. }
  47. return $result;
  48. }
  49. }