ActionFactory.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Mview;
  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. * @throws \InvalidArgumentException
  25. * @return ActionInterface
  26. */
  27. public function get($className)
  28. {
  29. $action = $this->objectManager->get($className);
  30. if (!$action instanceof ActionInterface) {
  31. throw new \InvalidArgumentException(
  32. $className . ' doesn\'t implement \Magento\Framework\Mview\ActionInterface'
  33. );
  34. }
  35. return $action;
  36. }
  37. }