ActionPool.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Model\ResourceModel\Db\Relation;
  7. use Magento\Framework\ObjectManagerInterface as ObjectManager;
  8. /**
  9. * Class ActionPool
  10. */
  11. class ActionPool
  12. {
  13. /**
  14. * @var ObjectManager
  15. */
  16. protected $objectManager;
  17. /**
  18. * @var array
  19. */
  20. protected $relationActions;
  21. /**
  22. * @param ObjectManager $objectManager
  23. * @param array $relationActions
  24. */
  25. public function __construct(
  26. ObjectManager $objectManager,
  27. array $relationActions = []
  28. ) {
  29. $this->objectManager = $objectManager;
  30. $this->relationActions = $relationActions;
  31. }
  32. /**
  33. * @param string $entityType
  34. * @param string $actionName
  35. * @return object[]
  36. * @throws \Exception
  37. */
  38. public function getActions($entityType, $actionName)
  39. {
  40. $actions = [];
  41. if (!isset($this->relationActions[$entityType][$actionName])) {
  42. return $actions;
  43. }
  44. foreach ($this->relationActions[$entityType][$actionName] as $actionClassName) {
  45. $action = $this->objectManager->get($actionClassName);
  46. $actions[] = $action;
  47. }
  48. return $actions;
  49. }
  50. }