Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
AuthControllerCreator.php
Go to the documentation of this file.
1<?php
3
5use Ubiquity\scaffolding\ScaffoldController;
6
18
19 private $baseClass;
20
23 $this->baseClass = $baseClass;
24 }
25
26 public function create(ScaffoldController $scaffoldController) {
27 $this->scaffoldController = $scaffoldController;
28 $classContent = '';
29 $rClass=new \ReflectionClass($this->baseClass);
30 if ($rClass->isAbstract()) {
31 $controllerTemplate = "authController.tpl";
32 $this->uses = [
33 "Ubiquity\\utils\\http\\USession" => true,
34 "Ubiquity\\utils\\http\\URequest" => true
35 ];
36 if($this->baseClass=='\\Ubiquity\\controllers\\auth\\AuthControllerConfig'){
37 $filename=\lcfirst($this->controllerName);
38 $classContent.=$scaffoldController->_createMethod('protected','getConfigFilename','',': string ',"\t\treturn '$filename';");
39 $completeClassname = $this->controllerNS . "auth\\".$this->controllerName;
40 if(\method_exists($this->baseClass,'init')){
41 \call_user_func($this->baseClass."::init",$filename);
42 }
43 }
44 } else {
45 $controllerTemplate = 'authController_.tpl';
46 }
47
48 $messages = [];
49 if (isset($this->views)) {
50 $this->addViews($messages, $classContent);
51 }
52
54 $routeAnnot = '';
55
56 if ($this->routePath != null) {
57 $routeAnnot = $this->getRouteAnnotation($this->routePath);
59 }
60 $messages[] = $scaffoldController->_createController($this->controllerName, [
61 '%routePath%' => $routePath,
62 '%route%' => $routeAnnot,
63 '%uses%' => $this->getUsesStr(),
64 '%namespace%' => $this->getNamespaceStr(),
65 '%baseClass%' => $this->baseClass,
66 '%content%' => $classContent
67 ], $controllerTemplate);
68 echo implode("\n", $messages);
69 }
70
71 protected function addViews(&$messages, &$classContent) {
73 $authControllerName = $this->controllerName;
74 $authViews = \explode(',', $this->views);
75 $this->addUse("controllers\\auth\\files\\{$authControllerName}Files");
76 $this->addUse("Ubiquity\\controllers\\auth\\AuthFiles");
77 $classContent .= $scaffoldController->_createMethod('protected', 'getFiles', '', ': AuthFiles', "\t\treturn new {$authControllerName}Files();");
78 $classFilesContent = [];
79 foreach ($authViews as $file) {
80 if (isset(ScaffoldController::$views['auth'][$file])) {
81 $frameworkViewname = ScaffoldController::$views["auth"][$file];
82 $scaffoldController->createAuthCrudView($frameworkViewname, $authControllerName, $file, $this->useViewInheritance);
83 $classFilesContent[] = $scaffoldController->_createMethod('public', 'getView' . \ucfirst($file), '', ': string', "\t\treturn \"" . $authControllerName . "/" . $file . ".html\";");
84 }
85 }
86 $messages[] = $this->createAuthFilesClass($scaffoldController, \implode('', $classFilesContent));
87 }
88
89 protected function createAuthFilesClass(ScaffoldController $scaffoldController, $classContent = '') {
90 $ns = Startup::getNS('controllers') . "auth\\files";
91 $uses = "\nuse Ubiquity\\controllers\\auth\\AuthFiles;";
92 return $scaffoldController->_createClass('class.tpl', $this->controllerName . 'Files', $ns, $uses, 'extends AuthFiles', $classContent);
93 }
94}
95
Starts the framework.
Definition Startup.php:19
__construct($controllerName, $baseClass, $views=null, $routePath='', $useViewInheritance=false)
createAuthFilesClass(ScaffoldController $scaffoldController, $classContent='')
getRouteAnnotation($path, $automated=true, $inherited=true)