Factory.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\Controller\Router\Route;
  7. use Magento\Framework\App\RouterInterface;
  8. use Magento\Framework\ObjectManagerInterface as ObjectManager;
  9. class Factory
  10. {
  11. /**
  12. * @var ObjectManager
  13. */
  14. protected $objectManager;
  15. /**
  16. * @param ObjectManager $objectManager
  17. */
  18. public function __construct(ObjectManager $objectManager)
  19. {
  20. $this->objectManager = $objectManager;
  21. }
  22. /**
  23. * Create route instance.
  24. *
  25. * @param string $routeClass
  26. * @param string $route Map used to match with later submitted URL path
  27. * @return RouterInterface
  28. * @throws \LogicException If specified route class does not implement proper interface.
  29. */
  30. public function createRoute($routeClass, $route)
  31. {
  32. $route = $this->objectManager->create($routeClass, ['route' => $route]);
  33. if (!$route instanceof RouterInterface) {
  34. throw new \LogicException('Route must implement "Magento\Framework\App\RouterInterface".');
  35. }
  36. return $route;
  37. }
  38. }