17 public static function createAction($controller, $action, $parameters =
"", $content =
"", $createView =
false, $route = []) {
20 $r = new \ReflectionClass ( $controller );
21 $ctrlFilename = $r->getFileName ();
24 $fileContent = \trim ( $fileContent );
25 $posLast = \strrpos ( $fileContent,
"}" );
26 if ($posLast !==
false) {
29 $content .=
"\n\t\t\$this->loadView('" . $viewname .
"');\n";
30 $msgContent [] =
"<br>Created view : <b>" . $viewname .
"</b>";
32 $routeAnnotation =
"";
33 if (isset ( $route [
"path"] )) {
35 $path = $route [
"path"];
36 $routeProperties = [
'"' . $path .
'"' ];
37 $methods = $route [
"methods"];
39 $routeProperties [] =
'"methods"=>' . self::getMethods ( $methods );
41 if ($route [
"cache"]) {
42 $routeProperties [] =
'"cache"=>true';
43 if (isset ( $route [
"duration"] )) {
44 $duration = $route [
"duration"];
45 if (\ctype_digit ( $duration )) {
46 $routeProperties [] =
'"duration"=>' . $duration;
50 $routeProperties = \implode (
",", $routeProperties );
54 $actionContent =
UFileSystem::openReplaceInTemplateFile ( self::$baseDir .
"/admin/templates/action.tpl", [
"%route%" =>
"\n" . $routeAnnotation,
"%actionName%" => $action,
"%parameters%" => $parameters,
"%content%" => $content ] );
55 $fileContent = \substr_replace ( $fileContent,
"\n%content%", $posLast - 1, 0 );
57 $msgContent = [
"Errors parsing action content!" ];
61 $msgContent [] =
"The action <b>{$action}</b> is created in controller <b>{$controller}</b>";
65 return compact ( $msgContent, $hasErrors );
68 public static function createView($controller, $action) {
69 $viewName = $controller .
"/" . $action .
".html";
76 $methods = \explode (
",", $strMethods );
78 foreach ( $methods as $method ) {
79 $result [] =
'"' . $method .
'"';
81 return "[" . \implode (
",", $result ) .
"]";
static getClassCode($classname)
static indent($code, $count=2)
static createAction($controller, $action, $parameters="", $content="", $createView=false, $route=[])
static isValidCode($code)
static createView($controller, $action)
static openReplaceWriteFromTemplateFile($source, $destination, $keyAndValues)
static openReplaceInTemplateFile($source, $keyAndValues)
static getMethods($strMethods)
static cleanParameters($parameters)
static replaceWriteFromContent($content, $destination, $keyAndValues)
static getClassSimpleName($classnameWithNamespace)