ActionFactory.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Action Factory
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\App;
  9. /**
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class ActionFactory
  14. {
  15. /**
  16. * @var \Magento\Framework\ObjectManagerInterface
  17. */
  18. protected $_objectManager;
  19. /**
  20. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  21. */
  22. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  23. {
  24. $this->_objectManager = $objectManager;
  25. }
  26. /**
  27. * Create action
  28. *
  29. * @param string $actionName
  30. * @return ActionInterface
  31. * @throws \InvalidArgumentException
  32. */
  33. public function create($actionName)
  34. {
  35. if (!is_subclass_of($actionName, \Magento\Framework\App\ActionInterface::class)) {
  36. throw new \InvalidArgumentException(
  37. 'The action name provided is invalid. Verify the action name and try again.'
  38. );
  39. }
  40. return $this->_objectManager->create($actionName);
  41. }
  42. }