Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
CrudControllerCreator.php
Go to the documentation of this file.
1
<?php
2
namespace
Ubiquity\scaffolding\creators
;
3
4
use
Ubiquity\domains\DDDManager
;
5
use Ubiquity\scaffolding\ScaffoldController;
6
use
Ubiquity\controllers\Startup
;
7
18
class
CrudControllerCreator
extends
BaseControllerCreator
{
19
20
private
$resource
;
21
22
private
$crudDatas
;
23
24
private
$crudViewer
;
25
26
private
$crudEvents
;
27
28
private
$style
;
29
30
protected
$viewKey
;
31
32
public
function
__construct
($crudControllerName,
$resource
,
$crudDatas
=
null
,
$crudViewer
=
null
,
$crudEvents
=
null
, $crudViews =
null
,
$routePath
=
''
,
$useViewInheritance
=
false
,
$style
=
''
) {
33
parent::__construct($crudControllerName,
$routePath
, $crudViews,
$useViewInheritance
);
34
$this->resource =
$resource
;
35
$this->crudDatas =
$crudDatas
;
36
$this->crudViewer =
$crudViewer
;
37
$this->crudEvents =
$crudEvents
;
38
$this->templateName =
'crudController.tpl'
;
39
$this->style =
$style
;
40
$this->viewKey =
'CRUD'
;
41
}
42
43
public
function
create
(ScaffoldController
$scaffoldController
) {
44
$this->scaffoldController =
$scaffoldController
;
45
$resource
=
$this->resource
;
46
$crudControllerName =
$this->controllerName
;
47
$classContent =
''
;
48
$nsc = \trim($this->controllerNS,
'\\'
);
49
$messages = [];
50
51
// $scaffoldController->_createMethod ( 'public', '__construct', '', '', "\n\t\tparent::__construct();\n\$this->model=\"{$resource}\";" );
52
53
$domain = DDDManager::getActiveDomain();
54
if
($domain !=
''
) {
55
$classContent .=
$scaffoldController
->_createMethod(
'public'
,
'initialize'
,
''
,
''
,
"\t\tparent::initialize();\n\t\t\Ubiquity\domains\DDDManager::setDomain('"
. $domain .
"');"
);
56
}
57
$this->
createElements
($nsc, $crudControllerName,
$scaffoldController
, $messages, $classContent);
58
59
$routePath
=
$this->controllerName
;
60
$routeAnnot =
''
;
61
if
($this->routePath !=
null
) {
62
$routePath
=
$this->routePath
;
63
$routeAnnot = $this->
getRouteAnnotation
($this->routePath);
64
}
65
66
$uses
= $this->
getUsesStr
();
67
$messages[] =
$scaffoldController
->_createController($crudControllerName, [
68
'%routePath%'
=>
$routePath
,
69
'%route%'
=> $routeAnnot,
70
'%resource%'
=>
$resource
,
71
'%uses%'
=>
$uses
,
72
'%namespace%'
=> $this->
getNamespaceStr
(),
73
'%baseClass%'
=>
"\\Ubiquity\\controllers\\crud\\CRUDController"
,
74
'%content%'
=> $classContent,
75
'%style%'
=> $this->style
76
], $this->templateName);
77
echo \implode(
"\n"
, $messages);
78
}
79
80
protected
function
createElements
(
string
$nsc,
string
$crudControllerName, ScaffoldController
$scaffoldController
, array &$messages,
string
&$classContent) {
81
if
(isset($this->crudDatas)) {
82
$this->
addUses
(
"{$nsc}\\crud\\datas\\{$crudControllerName}Datas"
,
"Ubiquity\\controllers\\crud\\CRUDDatas"
);
83
84
$classContent .=
$scaffoldController
->_createMethod(
'protected'
,
'getAdminData'
,
''
,
': CRUDDatas'
,
"\t\treturn new {$crudControllerName}Datas(\$this);"
);
85
$messages[] = $this->
createCRUDDatasClass
();
86
}
87
88
if
(isset($this->crudViewer)) {
89
$this->
addUses
(
"{$nsc}\\crud\\viewers\\{$crudControllerName}Viewer"
,
"Ubiquity\\controllers\\crud\\viewers\\ModelViewer"
);
90
91
$classContent .=
$scaffoldController
->_createMethod(
'protected'
,
'getModelViewer'
,
''
,
': ModelViewer'
,
"\t\treturn new {$crudControllerName}Viewer(\$this,\$this->style);"
);
92
$messages[] = $this->
createModelViewerClass
();
93
}
94
if
(isset($this->crudEvents)) {
95
$this->
addUses
(
"{$nsc}\\crud\\events\\{$crudControllerName}Events"
,
"Ubiquity\\controllers\\crud\\CRUDEvents"
);
96
97
$classContent .=
$scaffoldController
->_createMethod(
'protected'
,
'getEvents'
,
''
,
': CRUDEvents'
,
"\t\treturn new {$crudControllerName}Events(\$this);"
);
98
$messages[] = $this->
createEventsClass
();
99
}
100
101
if
(isset($this->views)) {
102
$this->
addViews
($messages, $classContent);
103
}
104
}
105
106
protected
function
addViews
(&$messages, &$classContent) {
107
$crudControllerName =
$this->controllerName
;
108
$crudViews = \explode(
','
, $this->views);
109
$nsc = \trim($this->controllerNS,
'\\'
);
110
$this->
addUses
(
"{$nsc}\\crud\\files\\{$crudControllerName}Files"
,
"Ubiquity\\controllers\\crud\\CRUDFiles"
);
111
$classContent .= $this->scaffoldController->_createMethod(
'protected'
,
'getFiles'
,
''
,
': CRUDFiles'
,
"\t\treturn new {$crudControllerName}Files();"
);
112
$classFilesContent = [];
113
$viewNamespace = DDDManager::getViewNamespace();
114
foreach
($crudViews as $file) {
115
if
(isset(ScaffoldController::$views[$this->viewKey][$file])) {
116
$frameworkViewname = ScaffoldController::$views[
$this->viewKey
][$file];
117
$this->scaffoldController->createAuthCrudView($frameworkViewname, $crudControllerName, $file, $this->useViewInheritance);
118
$classFilesContent[] = $this->scaffoldController->_createMethod(
'public'
,
'getView'
. \ucfirst($file),
''
,
': string'
,
"\t\treturn \""
. $viewNamespace . $crudControllerName .
"/"
. $file .
".html\";"
);
119
}
120
}
121
$messages[] = $this->
createCRUDFilesClass
(\implode(
''
, $classFilesContent));
122
}
123
124
protected
function
createCRUDDatasClass
() {
125
$ns = $this->controllerNS .
"crud\\datas"
;
126
$uses
=
"\nuse Ubiquity\\controllers\\crud\\CRUDDatas;"
;
127
return
$this->scaffoldController->_createClass(
'class.tpl'
, $this->controllerName .
'Datas'
, $ns,
$uses
,
'extends CRUDDatas'
,
"\t//use override/implement Methods"
);
128
}
129
130
protected
function
createModelViewerClass
() {
131
$ns = $this->controllerNS .
"crud\\viewers"
;
132
$uses
=
"\nuse Ubiquity\\controllers\\crud\\viewers\\ModelViewer;"
;
133
return
$this->scaffoldController->_createClass(
'class.tpl'
, $this->controllerName .
'Viewer'
, $ns,
$uses
,
'extends ModelViewer'
,
"\t//use override/implement Methods"
);
134
}
135
136
protected
function
createEventsClass
() {
137
$ns = $this->controllerNS .
"crud\\events"
;
138
$uses
=
"\nuse Ubiquity\\controllers\\crud\\CRUDEvents;"
;
139
return
$this->scaffoldController->_createClass(
'class.tpl'
, $this->controllerName .
'Events'
, $ns,
$uses
,
'extends CRUDEvents'
,
"\t//use override/implement Methods"
);
140
}
141
142
public
function
createCRUDFilesClass
($classContent =
""
) {
143
$ns = $this->controllerNS .
"crud\\files"
;
144
$uses
=
"\nuse Ubiquity\\controllers\\crud\\CRUDFiles;"
;
145
return
$this->scaffoldController->_createClass(
'class.tpl'
, $this->controllerName .
'Files'
, $ns,
$uses
,
'extends CRUDFiles'
, $classContent);
146
}
147
}
148
Ubiquity\controllers\Startup
Starts the framework.
Definition
Startup.php:19
Ubiquity\creator\HasUsesTrait\getUsesStr
getUsesStr()
Definition
HasUsesTrait.php:20
Ubiquity\creator\HasUsesTrait\addUses
addUses(... $classnames)
Definition
HasUsesTrait.php:14
Ubiquity\creator\HasUsesTrait\$uses
$uses
Definition
HasUsesTrait.php:5
Ubiquity\domains\DDDManager
Manager for a Domain Driven Design approach.
Definition
DDDManager.php:20
Ubiquity\scaffolding\creators\BaseControllerCreator
Definition
BaseControllerCreator.php:19
Ubiquity\scaffolding\creators\BaseControllerCreator\$routePath
$routePath
Definition
BaseControllerCreator.php:23
Ubiquity\scaffolding\creators\BaseControllerCreator\$controllerName
$controllerName
Definition
BaseControllerCreator.php:21
Ubiquity\scaffolding\creators\BaseControllerCreator\$scaffoldController
$scaffoldController
Definition
BaseControllerCreator.php:37
Ubiquity\scaffolding\creators\BaseControllerCreator\getRouteAnnotation
getRouteAnnotation($path, $automated=true, $inherited=true)
Definition
BaseControllerCreator.php:56
Ubiquity\scaffolding\creators\BaseControllerCreator\$useViewInheritance
$useViewInheritance
Definition
BaseControllerCreator.php:31
Ubiquity\scaffolding\creators\BaseControllerCreator\getNamespaceStr
getNamespaceStr()
Definition
BaseControllerCreator.php:49
Ubiquity\scaffolding\creators\CrudControllerCreator
Definition
CrudControllerCreator.php:18
Ubiquity\scaffolding\creators\CrudControllerCreator\$viewKey
$viewKey
Definition
CrudControllerCreator.php:30
Ubiquity\scaffolding\creators\CrudControllerCreator\$crudDatas
$crudDatas
Definition
CrudControllerCreator.php:22
Ubiquity\scaffolding\creators\CrudControllerCreator\createEventsClass
createEventsClass()
Definition
CrudControllerCreator.php:136
Ubiquity\scaffolding\creators\CrudControllerCreator\create
create(ScaffoldController $scaffoldController)
Definition
CrudControllerCreator.php:43
Ubiquity\scaffolding\creators\CrudControllerCreator\createModelViewerClass
createModelViewerClass()
Definition
CrudControllerCreator.php:130
Ubiquity\scaffolding\creators\CrudControllerCreator\__construct
__construct($crudControllerName, $resource, $crudDatas=null, $crudViewer=null, $crudEvents=null, $crudViews=null, $routePath='', $useViewInheritance=false, $style='')
Definition
CrudControllerCreator.php:32
Ubiquity\scaffolding\creators\CrudControllerCreator\createCRUDFilesClass
createCRUDFilesClass($classContent="")
Definition
CrudControllerCreator.php:142
Ubiquity\scaffolding\creators\CrudControllerCreator\$style
$style
Definition
CrudControllerCreator.php:28
Ubiquity\scaffolding\creators\CrudControllerCreator\createElements
createElements(string $nsc, string $crudControllerName, ScaffoldController $scaffoldController, array &$messages, string &$classContent)
Definition
CrudControllerCreator.php:80
Ubiquity\scaffolding\creators\CrudControllerCreator\addViews
addViews(&$messages, &$classContent)
Definition
CrudControllerCreator.php:106
Ubiquity\scaffolding\creators\CrudControllerCreator\createCRUDDatasClass
createCRUDDatasClass()
Definition
CrudControllerCreator.php:124
Ubiquity\scaffolding\creators\CrudControllerCreator\$resource
$resource
Definition
CrudControllerCreator.php:20
Ubiquity\scaffolding\creators\CrudControllerCreator\$crudViewer
$crudViewer
Definition
CrudControllerCreator.php:24
Ubiquity\scaffolding\creators\CrudControllerCreator\$crudEvents
$crudEvents
Definition
CrudControllerCreator.php:26
Ubiquity\scaffolding\creators
Definition
AuthControllerCreator.php:2
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity-dev
src
Ubiquity
scaffolding
creators
CrudControllerCreator.php
Generated on Sun Dec 10 2023 15:04:08 for
Ubiquity
by
doxygen
1.9.8