ValidatorPool.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 ValidatorPool
  10. */
  11. class ValidatorPool
  12. {
  13. /**
  14. * @var ObjectManagerInterface
  15. */
  16. protected $objectManager;
  17. /**
  18. * @var object[]
  19. */
  20. protected $validators;
  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 object[]
  36. * @throws \Exception
  37. */
  38. public function getValidators($entityType, $actionName)
  39. {
  40. $actions = [];
  41. foreach ($this->validators as $name => $actionGroup) {
  42. if (isset($actionGroup[$entityType][$actionName])) {
  43. $actions[$name] = $this->objectManager->get($actionGroup[$entityType][$actionName]);
  44. } elseif (isset($actionGroup['default'][$actionName])) {
  45. $actions[$name] = $this->objectManager->get($actionGroup['default'][$actionName]);
  46. }
  47. }
  48. return $actions;
  49. }
  50. }