12
12
use Zend \EventManager \AbstractListenerAggregate ;
13
13
use Zend \EventManager \EventManagerInterface as Events ;
14
14
use Zend \Mvc \MvcEvent ;
15
- use Zend \Mvc \ModuleRouteListener ;
16
15
use Zend \Stdlib \StringUtils ;
17
16
use Zend \View \Model \ModelInterface as ViewModel ;
18
17
@@ -73,28 +72,6 @@ public function injectTemplate(MvcEvent $e)
73
72
}
74
73
75
74
$ template = $ this ->mapController ($ controller );
76
- if (!$ template ) {
77
- $ module = $ this ->deriveModuleNamespace ($ controller );
78
-
79
- if ($ namespace = $ routeMatch ->getParam (ModuleRouteListener::MODULE_NAMESPACE )) {
80
- $ controllerSubNs = $ this ->deriveControllerSubNamespace ($ namespace );
81
- if (!empty ($ controllerSubNs )) {
82
- if (!empty ($ module )) {
83
- $ module .= '/ ' . $ controllerSubNs ;
84
- } else {
85
- $ module = $ controllerSubNs ;
86
- }
87
- }
88
- }
89
-
90
- $ controller = $ this ->deriveControllerClass ($ controller );
91
- $ template = $ this ->inflectName ($ module );
92
-
93
- if (!empty ($ template )) {
94
- $ template .= '/ ' ;
95
- }
96
- $ template .= $ this ->inflectName ($ controller );
97
- }
98
75
99
76
$ action = $ routeMatch ->getParam ('action ' );
100
77
if (null !== $ action ) {
@@ -124,10 +101,7 @@ public function setControllerMap(array $map)
124
101
*/
125
102
public function mapController ($ controller )
126
103
{
127
- if (! is_string ($ controller )) {
128
- return false ;
129
- }
130
-
104
+ $ mapped = '' ;
131
105
foreach ($ this ->controllerMap as $ namespace => $ replacement ) {
132
106
if (// Allow disabling rule by setting value to false since config
133
107
// merging have no feature to remove entries
@@ -138,27 +112,26 @@ public function mapController($controller)
138
112
continue ;
139
113
}
140
114
141
- $ map = '' ;
142
115
// Map namespace to $replacement if its value is string
143
116
if (is_string ($ replacement )) {
144
- $ map = rtrim ($ replacement , '/ ' ) . '/ ' ;
117
+ $ mapped = rtrim ($ replacement , '/ ' ) . '/ ' ;
145
118
$ controller = substr ($ controller , strlen ($ namespace ) + 1 ) ?: '' ;
119
+ break ;
146
120
}
121
+ }
147
122
148
- //strip Controller namespace(s) (but not classname)
149
- $ parts = explode ('\\' , $ controller );
150
- array_pop ($ parts );
151
- $ parts = array_diff ($ parts , ['Controller ' ]);
152
- //strip trailing Controller in class name
153
- $ parts [] = $ this ->deriveControllerClass ($ controller );
154
- $ controller = implode ('/ ' , $ parts );
123
+ //strip Controller namespace(s) (but not classname)
124
+ $ parts = explode ('\\' , $ controller );
125
+ array_pop ($ parts );
126
+ $ parts = array_diff ($ parts , ['Controller ' ]);
127
+ //strip trailing Controller in class name
128
+ $ parts [] = $ this ->deriveControllerClass ($ controller );
129
+ $ controller = implode ('/ ' , $ parts );
155
130
156
- $ template = trim ($ map . $ controller , '/ ' );
131
+ $ template = trim ($ mapped . $ controller , '/ ' );
157
132
158
- // inflect CamelCase to dash
159
- return $ this ->inflectName ($ template );
160
- }
161
- return false ;
133
+ // inflect CamelCase to dash
134
+ return $ this ->inflectName ($ template );
162
135
}
163
136
164
137
/**
@@ -183,40 +156,6 @@ protected function inflectName($name)
183
156
return strtolower ($ name );
184
157
}
185
158
186
- /**
187
- * Determine the top-level namespace of the controller
188
- *
189
- * @param string $controller
190
- * @return string
191
- */
192
- protected function deriveModuleNamespace ($ controller )
193
- {
194
- if (!strstr ($ controller , '\\' )) {
195
- return '' ;
196
- }
197
- $ module = substr ($ controller , 0 , strpos ($ controller , '\\' ));
198
- return $ module ;
199
- }
200
-
201
- /**
202
- * @param $namespace
203
- * @return string
204
- */
205
- protected function deriveControllerSubNamespace ($ namespace )
206
- {
207
- if (!strstr ($ namespace , '\\' )) {
208
- return '' ;
209
- }
210
- $ nsArray = explode ('\\' , $ namespace );
211
-
212
- // Remove the first two elements representing the module and controller directory.
213
- $ subNsArray = array_slice ($ nsArray , 2 );
214
- if (empty ($ subNsArray )) {
215
- return '' ;
216
- }
217
- return implode ('/ ' , $ subNsArray );
218
- }
219
-
220
159
/**
221
160
* Determine the name of the controller
222
161
*
0 commit comments