Module.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. use Magento\Framework\Component\ComponentRegistrar;
  8. use Magento\Framework\Component\ComponentRegistrarInterface;
  9. /**
  10. * Fallback Rule Module
  11. *
  12. * Propagates all parameters necessary for modular rule
  13. */
  14. class Module implements RuleInterface
  15. {
  16. /**
  17. * Rule
  18. *
  19. * @var RuleInterface
  20. */
  21. protected $rule;
  22. /**
  23. * Component registrar
  24. *
  25. * @var ComponentRegistrarInterface
  26. */
  27. private $componentRegistrar;
  28. /**
  29. * Constructors
  30. *
  31. * @param RuleInterface $rule
  32. * @param ComponentRegistrarInterface $componentRegistrar
  33. */
  34. public function __construct(RuleInterface $rule, ComponentRegistrarInterface $componentRegistrar)
  35. {
  36. $this->rule = $rule;
  37. $this->componentRegistrar = $componentRegistrar;
  38. }
  39. /**
  40. * Propagate parameters necessary for modular rule basing on module_name parameter
  41. *
  42. * @param array $params
  43. * @return array
  44. * @throws \InvalidArgumentException
  45. */
  46. public function getPatternDirs(array $params)
  47. {
  48. if (!array_key_exists('module_name', $params)) {
  49. throw new \InvalidArgumentException(
  50. 'Required parameter "module_name" is not specified.'
  51. );
  52. }
  53. $params['module_dir'] = $this->componentRegistrar->getPath(
  54. ComponentRegistrar::MODULE,
  55. $params['module_name']
  56. );
  57. if (empty($params['module_dir'])) {
  58. return [];
  59. }
  60. return $this->rule->getPatternDirs($params);
  61. }
  62. }