Created
April 19, 2016 23:14
-
-
Save tiagosampaio/b16bfa825b0280a1165134f67be90ac1 to your computer and use it in GitHub Desktop.
Magento 2 - Request Flow / Bootstrap - Magento\Framework\App\FrontController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Front controller responsible for dispatching application requests | |
* | |
* Copyright © 2015 Magento. All rights reserved. | |
* See COPYING.txt for license details. | |
*/ | |
namespace Magento\Framework\App; | |
class FrontController implements FrontControllerInterface | |
{ | |
/** | |
* @var RouterList | |
*/ | |
protected $_routerList; | |
/** | |
* @var \Magento\Framework\App\Response\Http | |
*/ | |
protected $response; | |
/** | |
* @param RouterList $routerList | |
* @param \Magento\Framework\App\Response\Http $response | |
*/ | |
public function __construct( | |
RouterList $routerList, | |
\Magento\Framework\App\Response\Http $response | |
) { | |
$this->_routerList = $routerList; | |
$this->response = $response; | |
} | |
/** | |
* Perform action and generate response | |
* | |
* @param RequestInterface $request | |
* @return ResponseInterface|\Magento\Framework\Controller\ResultInterface | |
* @throws \LogicException | |
*/ | |
public function dispatch(RequestInterface $request) | |
{ | |
\Magento\Framework\Profiler::start('routers_match'); | |
$routingCycleCounter = 0; | |
$result = null; | |
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); | |
$this->response->setNoCacheHeaders(); | |
if ($actionInstance instanceof \Magento\Framework\App\Action\AbstractAction) { | |
$result = $actionInstance->dispatch($request); | |
} else { | |
$result = $actionInstance->execute(); | |
} | |
break; | |
} | |
} catch (\Magento\Framework\Exception\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'); | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment