7
7
*/
8
8
namespace Magento \Framework \App ;
9
9
10
+ /**
11
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12
+ */
10
13
class FrontController implements FrontControllerInterface
11
14
{
12
15
/**
@@ -64,33 +67,8 @@ public function dispatch(RequestInterface $request)
64
67
$ routingCycleCounter = 0 ;
65
68
$ result = null ;
66
69
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
+
94
72
}
95
73
\Magento \Framework \Profiler::stop ('routers_match ' );
96
74
if ($ routingCycleCounter > 100 ) {
@@ -113,4 +91,42 @@ protected function handleException($e, $actionInstance, $message)
113
91
$ this ->logger ->critical ($ e ->getMessage ());
114
92
return $ actionInstance ->getDefaultRedirect ();
115
93
}
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
+ }
116
132
}
0 commit comments