Skip to content

Instantly share code, notes, and snippets.

@tiagosampaio
Created April 19, 2016 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagosampaio/b16bfa825b0280a1165134f67be90ac1 to your computer and use it in GitHub Desktop.
Save tiagosampaio/b16bfa825b0280a1165134f67be90ac1 to your computer and use it in GitHub Desktop.
Magento 2 - Request Flow / Bootstrap - Magento\Framework\App\FrontController
<?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