16 use Psr\Log\LoggerInterface;
37 private $requestValidator;
52 private $validatedRequest =
false;
64 ?RequestValidator $requestValidator =
null,
65 ?MessageManager $messageManager =
null,
66 ?LoggerInterface $logger =
null 68 $this->_routerList = $routerList;
70 $this->requestValidator = $requestValidator
72 $this->messages = $messageManager
74 $this->logger = $logger
87 \Magento\Framework\Profiler::start(
'routers_match');
88 $this->validatedRequest =
false;
89 $routingCycleCounter = 0;
91 while (!
$request->isDispatched() && $routingCycleCounter++ < 100) {
93 foreach ($this->_routerList as $router) {
95 $actionInstance = $router->match(
$request);
96 if ($actionInstance) {
97 $result = $this->processRequest(
103 }
catch (\
Magento\Framework\Exception\NotFoundException $e) {
111 \Magento\Framework\Profiler::stop(
'routers_match');
112 if ($routingCycleCounter > 100) {
113 throw new \LogicException(
'Front controller reached 100 router match iterations');
125 private function processRequest(
127 ActionInterface $actionInstance
130 $this->response->setNoCacheHeaders();
134 if (!$this->validatedRequest) {
136 $this->requestValidator->validate(
140 }
catch (InvalidRequestException $exception) {
142 $this->logger->debug(
143 'Request validation failed for action "' 144 .get_class($actionInstance) .
'"' 146 $result = $exception->getReplaceResult();
147 if ($messages = $exception->getMessages()) {
149 $this->messages->addErrorMessage(
$message);
153 $this->validatedRequest =
true;
158 if ($actionInstance instanceof AbstractAction) {
161 $result = $actionInstance->execute();
166 if (
$result instanceof NotFoundException) {
dispatch(RequestInterface $request)
__construct(RouterListInterface $routerList, ResponseInterface $response, ?RequestValidator $requestValidator=null, ?MessageManager $messageManager=null, ?LoggerInterface $logger=null)