// lib/internal/Magento/Framework/App/FrontController.php - dispatch() while (!$request->isDispatched() && $routingCycleCounter++ < 100) { /** @var \Magento\Framework\App\RouterInterface $router */ foreach ($this->_routerList as $router) { try { $actionInstance = $router->match($request); if ($actionInstance) { $request->setDispatched(true); $actionInstance->getResponse()->setNoCacheHeaders(); $result = $actionInstance->dispatch($request); break; } } catch (Action\NotFoundException $e) { $request->initForward(); $request->setActionName('noroute'); $request->setDispatched(false); break; } } } \Magento\Framework\Profiler::stop('routers_match'); if ($routingCycleCounter > 100) { throw new \LogicException('Front controller reached 100 router match iterations'); }Routers which want to get involved in the routing process should be injected into the shared Magento\Framework\App\RouterList object. Due to Magento 2 its dependency injection system, each and every module is allowed to do this. For example, the Magento_Core Magento_Store module supplies the Base and DefaultRouter:
<!-- Magento/Core/etc/frontend/di.xml --> Magento\Core\App\Router\Base false 20 Magento\Framework\App\Router\DefaultRouter false 100Routers are listed based on the sortOrder item, this happens in ascending order. Given those two routers, the Base router comes before the DefaultRouter. In a default Magento 2 installation, the DefaultRouterhas the lowest priority (highest sortOrder) which means it will be the last to be asked for matches in the FrontController. The DefaultRouter is the building stone of the NoRouteHandler system.
// lib/internal/Magento/Framework/App/Router/DefaultRouter.php - match() foreach ($this->noRouteHandlerList->getHandlers() as $noRouteHandler) { if ($noRouteHandler->process($request)) { break; } } return $this->actionFactory->create('Magento\Framework\App\Action\Forward', ['request' => $request])
// lib/internal/Magento/Framework/App/Action/Forward.php - dispatch() $request->setDispatched(false);This means that the ! $request->isDispatched() condition in the outer while-loop of theFrontController is still in effect. Because earlier the foreach-loop was break;‘d out of, the matching-process immediately begins all over again.
// Magento/Core/App/Router/NoRouteHandler.php -- process() $noRoutePath = $this->_config->getValue('web/default/no_route', 'default'); if ($noRoutePath) { $noRoute = explode('/', $noRoutePath); } else { $noRoute = []; } $moduleName = isset($noRoute[0]) ? $noRoute[0] : 'core'; $actionPath = isset($noRoute[1]) ? $noRoute[1] : 'index'; $actionName = isset($noRoute[2]) ? $noRoute[2] : 'index'; $request->setModuleName($moduleName)->setControllerName($actionPath)->setActionName($actionName); return true;In Magento 1.X, there is no NoRouteHandler fallback: it is what the default router (Mage_Core_Controller_Varien_Router_Default) is responsible for. Splitting this logic from the router adheres to the separation of concerns principle and by putting the no route handlers in a list, modifying the “noroute” logic is a lot more elegant.
Vendor\Module\App\Router\NoRouteHandler 1Take note that the sortOrder should be lower than that of Magento’s default NoRouteHandler (injected inMagento/Core/etc/di.xml with a sortOrder of 100). In your custom NoRouteHandler you can do whatever you want. To comply with the standard set by the Magento 2 core code, you should arguably keep your NoRouteHandler as lightweight as possible; alter the request and point it to a “fatter” controller.
class NoRouteHandler implements NoRouteHandlerInterface { /** * Check and process no route request * * @param \Magento\Framework\App\RequestInterface $request * @return bool */public function process(\Magento\Framework\App\RequestInterface $request) { // Be sure to return a true-value if you do not want the Default router to consider other no route handlers return true; } }
In the highly competitive modern workplace, trust, and employee loyalty are crucial factors for long-term… Read More
In the ever-evolving world of small business developing and implementing effective marketing strategies is critical to… Read More
With one of the highest internet penetration rates, the UAE has set out to revolutionize… Read More
Artificial Intelligence (AI) has been continually evolving, leading to remarkable advancements in various industries. Among… Read More
Extensions, extensions and lots of extensions. We all love extensions, don’t we? After all, extensions… Read More
Software quality is crucial to a firm's success across industries in the quickly changing digital… Read More
View Comments
How i can stop execution in magento 2.2 which not allow to use die or exit??
$writer = new XMLWriter();
$writer->openURI('php://output');
$writer->startDocument("1.0");
$this->_writeOrders($orders, $writer, $storeId);
$writer->flush();
//die();