ExtensionPool.php 1.4 KB

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