@@ -165,24 +165,40 @@ public function _newAction($controller, $action, $parameters = null, $content =
165
165
if ($ classCode !== false ) {
166
166
$ fileContent = \implode ('' , $ classCode );
167
167
$ fileContent = \trim ($ fileContent );
168
- $ posLast = \strrpos ($ fileContent , '} ' );
169
- if ($ posLast !== false ) {
170
168
if ($ createView ) {
171
169
$ viewname = $ this ->_createViewOp (ClassUtils::getClassSimpleName ($ controller ), $ action , $ theme );
172
170
$ content .= "\n\t\t\$this->loadView(' " . $ viewname . "'); \n" ;
173
171
$ msgContent .= "<br>Created view : <b> " . $ viewname . "</b> " ;
174
172
}
175
173
$ routeAnnotation = $ this ->generateRouteAnnotation ($ routeInfo );
174
+
176
175
if ($ routeAnnotation != '' ) {
177
176
$ msgContent .= $ this ->_addMessageForRouteCreation ($ routeInfo ["path " ]);
177
+ if (\count ($ this ->getUses ())>0 ){
178
+ $ namespace ='namespace ' .$ r ->getNamespaceName ()."; \n" ;
179
+ $ posUses = \strpos ($ fileContent , $ namespace );
180
+ if ($ posUses !==false ){
181
+ $ posUses +=strlen ($ namespace );
182
+ $ uses =$ this ->uses ;
183
+ foreach ($ uses as $ use =>$ _ ){
184
+ if (\strpos ($ fileContent , 'use ' .$ use )!==false ){
185
+ unset($ this ->uses [$ use ]);
186
+ }
187
+ }
188
+ if (\count ($ this ->getUses ())>0 ){
189
+ $ fileContent = \substr_replace ($ fileContent , "\n" .$ this ->getUsesStr (), $ posUses - 1 , 0 );
190
+ }
191
+ }
192
+ }
178
193
}
179
194
$ parameters = CodeUtils::cleanParameters ($ parameters );
180
195
$ actionContent = UFileSystem::openReplaceInTemplateFile ($ templateDir . "action.tpl " , [
181
- '%route% ' => "\n" . $ routeAnnotation ?? '' ,
196
+ '%route% ' => "\n\t " . $ routeAnnotation ?? '' ,
182
197
'%actionName% ' => $ action ,
183
198
'%parameters% ' => $ parameters ,
184
199
'%content% ' => $ content
185
200
]);
201
+ $ posLast = \strrpos ($ fileContent , '} ' );
186
202
$ fileContent = \substr_replace ($ fileContent , "\n%content% " , $ posLast - 1 , 0 );
187
203
if (! CodeUtils::isValidCode ('<?php ' . $ content )) {
188
204
echo $ this ->showSimpleMessage ("Errors parsing action content! " , "warning " , "Creation " , "warning circle " , null , "msgControllers " );
@@ -195,7 +211,7 @@ public function _newAction($controller, $action, $parameters = null, $content =
195
211
echo $ this ->showSimpleMessage ($ msgContent , "success " , "Creation " , "info circle " , null , "msgControllers " );
196
212
}
197
213
}
198
- }
214
+
199
215
} else {
200
216
echo $ this ->showSimpleMessage ("The action {$ action } already exists in {$ controller }! " , "error " , "Creation " , "warning circle " , null , "msgControllers " );
201
217
}
@@ -228,7 +244,7 @@ protected function generateRouteAnnotation($routeInfo) {
228
244
}
229
245
230
246
231
- return CacheManager::getAnnotationsEngineInstance ()->getAnnotation ($ this ,$ name ,$ routeProperties )->asAnnotation ();;
247
+ return CacheManager::getAnnotationsEngineInstance ()->getAnnotation ($ this ,$ name ,$ routeProperties )->asAnnotation ();
232
248
}
233
249
return '' ;
234
250
}
0 commit comments