ActionFactory.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Indexer;
  7. class ActionFactory
  8. {
  9. /**
  10. * @var \Magento\Framework\ObjectManagerInterface
  11. */
  12. protected $objectManager;
  13. /**
  14. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  15. */
  16. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  17. {
  18. $this->objectManager = $objectManager;
  19. }
  20. /**
  21. * Get action class instance by class name
  22. *
  23. * @param string $className
  24. * @param [] $arguments
  25. * @throws \InvalidArgumentException
  26. * @return ActionInterface
  27. */
  28. public function create($className, $arguments = [])
  29. {
  30. $action = $this->objectManager->create($className, $arguments);
  31. if (!$action instanceof ActionInterface) {
  32. throw new \InvalidArgumentException(
  33. $className . ' doesn\'t implement \Magento\Framework\Indexer\ActionInterface'
  34. );
  35. }
  36. return $action;
  37. }
  38. }