Skip to content

Commit cbf621b

Browse files
author
vpaladiychuk
committed
Merge branch 'MAGETWO-34988' into MAGETWO-34990
2 parents e48aa7b + 2bb30bc commit cbf621b

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

lib/internal/Magento/Framework/App/FrontController.php

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
namespace Magento\Framework\App;
99

10+
/**
11+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12+
*/
1013
class FrontController implements FrontControllerInterface
1114
{
1215
/**
@@ -64,33 +67,8 @@ public function dispatch(RequestInterface $request)
6467
$routingCycleCounter = 0;
6568
$result = null;
6669
while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
67-
/** @var \Magento\Framework\App\RouterInterface $router */
68-
foreach ($this->_routerList as $router) {
69-
try {
70-
$actionInstance = $router->match($request);
71-
if ($actionInstance) {
72-
$request->setDispatched(true);
73-
$actionInstance->getResponse()->setNoCacheHeaders();
74-
$result = $actionInstance->dispatch($request);
75-
break;
76-
}
77-
} catch (Action\NotFoundException $e) {
78-
$request->initForward();
79-
$request->setActionName('noroute');
80-
$request->setDispatched(false);
81-
break;
82-
} catch (\Magento\Framework\LocalizedException $e) {
83-
$result = $this->handleException($e, $actionInstance, $e->getMessage());
84-
break;
85-
} catch (\Exception $e) {
86-
// @todo Message should be clarified
87-
$message = $this->appState->getMode() == State::MODE_DEVELOPER
88-
? $e->getMessage()
89-
: (string)new \Magento\Framework\Phrase('An error occurred while processing your request');
90-
$result = $this->handleException($e, $actionInstance, $message);
91-
break;
92-
}
93-
}
70+
$result = $this->matchAction($request);
71+
9472
}
9573
\Magento\Framework\Profiler::stop('routers_match');
9674
if ($routingCycleCounter > 100) {
@@ -113,4 +91,42 @@ protected function handleException($e, $actionInstance, $message)
11391
$this->logger->critical($e->getMessage());
11492
return $actionInstance->getDefaultRedirect();
11593
}
94+
95+
/**
96+
* Match action, dispatch
97+
*
98+
* @param RequestInterface $request
99+
* @return \Magento\Framework\Controller\Result\Redirect
100+
*/
101+
protected function matchAction(RequestInterface $request)
102+
{
103+
/** @var \Magento\Framework\App\RouterInterface $router */
104+
foreach ($this->_routerList as $router) {
105+
try {
106+
$actionInstance = $router->match($request);
107+
if ($actionInstance) {
108+
$request->setDispatched(true);
109+
$actionInstance->getResponse()->setNoCacheHeaders();
110+
$result = $actionInstance->dispatch($request);
111+
break;
112+
}
113+
} catch (Action\NotFoundException $e) {
114+
$request->initForward();
115+
$request->setActionName('noroute');
116+
$request->setDispatched(false);
117+
break;
118+
} catch (\Magento\Framework\LocalizedException $e) {
119+
$result = $this->handleException($e, $actionInstance, $e->getMessage());
120+
break;
121+
} catch (\Exception $e) {
122+
// @todo Message should be clarified
123+
$message = $this->appState->getMode() == State::MODE_DEVELOPER
124+
? $e->getMessage()
125+
: (string)new \Magento\Framework\Phrase('An error occurred while processing your request');
126+
$result = $this->handleException($e, $actionInstance, $message);
127+
break;
128+
}
129+
}
130+
return $result;
131+
}
116132
}

0 commit comments

Comments
 (0)