Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
IndexCrudControllerCreator.php
Go to the documentation of this file.
1<?php
3
8use Ubiquity\scaffolding\ScaffoldController;
9
11
12 public function __construct($crudControllerName, $crudDatas = null, $crudViewer = null, $crudEvents = null, $crudViews = null, $routePath = '', $useViewInheritance = false, $style = '') {
13 parent::__construct($crudControllerName, null, $crudDatas, $crudViewer, $crudEvents, $crudViews, $routePath, $useViewInheritance, $style);
14 $this->templateName = 'indexCrudController.tpl';
15 $this->viewKey = 'indexCRUD';
16 }
17
18 public function create(ScaffoldController $scaffoldController) {
19 $this->scaffoldController = $scaffoldController;
20 $crudControllerName = $this->controllerName;
21 $classContent = '';
22 $nsc = \trim($this->controllerNS, '\\');
23 $messages = [];
24 $domain = DDDManager::getActiveDomain();
25 $initializeContent = '';
26 $routeNamePrefix = '';
27 if ($domain != '') {
28 $initializeContent = "\t\t\Ubiquity\domains\DDDManager::setDomain('" . $domain . "');";
29 $routeNamePrefix = $domain . '.';
30 }
31 if (($aDb = $this->scaffoldController->getActiveDb()) != null) {
32 if ($aDb !== 'default') {
33 $ns = CacheManager::getModelsNamespace($aDb);
34 $routeNamePrefix .= $aDb . '.';
35 if (isset($ns)) {
36 $classContent .= $scaffoldController->_createMethod('protected', 'getModelName', '', ': string ', "\t\treturn '" . $ns . "\\\\'.\ucfirst(\$this->resource);");
37 $classContent .= $scaffoldController->_createMethod('protected', 'getIndexModels', '', ': array ', "\t\treturn \Ubiquity\orm\DAO::getModels('" . $aDb . "');");
38 $initializeContent .= "\n\t\t\Ubiquity\orm\DAO::start();";
39 }
40 }
41 }
42 if ($routeNamePrefix != '') {
43 $classContent .= $scaffoldController->_createMethod('protected', 'getRouteNamePrefix', '', ': string ', "\t\treturn '" . $routeNamePrefix . "';");
44 }
45 if ($initializeContent !== '') {
46 $classContent .= $scaffoldController->_createMethod('public', 'initialize', '', '', $initializeContent . "\n\t\tparent::initialize();");
47 }
48 $this->createElements($nsc, $crudControllerName, $scaffoldController, $messages, $classContent);
49
50 $this->routePath ??= '{resource}';
51 $routePath = \rtrim($this->routePath, '/');
52 $routeAnnotation = $this->getRouteAnnotation($routePath);
53
54 $uses = $this->getUsesStr();
55 $messages[] = $scaffoldController->_createController($crudControllerName, [
56 '%indexRoute%' => $this->getAnnotation('route', [
57 'name' => $routeNamePrefix . 'crud.index',
58 'priority' => - 1
59 ]),
60 '%homeRoute%' => $this->getAnnotation('route', [
61 'path' => $this->getHome($routePath),
62 'name' => $routeNamePrefix . 'crud.home',
63 'priority' => 100
64 ]),
65 '%routePath%' => '"' . \str_replace('{resource}', '".$this->resource."', $routePath) . '"',
66 '%route%' => $routeAnnotation,
67 '%uses%' => $uses,
68 '%namespace%' => $this->getNamespaceStr(),
69 '%baseClass%' => "\\Ubiquity\\controllers\\crud\\MultiResourceCRUDController",
70 '%content%' => $classContent
71 ], $this->templateName);
72 echo \implode("\n", $messages);
73 }
74
75 protected function getHome($path) {
76 return '#/' . \str_replace('{resource}', 'home', $path);
77 }
78}
79
Manager for caches (Router, Rest, models).
Starts the framework.
Definition Startup.php:19
Manager for a Domain Driven Design approach.
getRouteAnnotation($path, $automated=true, $inherited=true)
createElements(string $nsc, string $crudControllerName, ScaffoldController $scaffoldController, array &$messages, string &$classContent)
__construct($crudControllerName, $crudDatas=null, $crudViewer=null, $crudEvents=null, $crudViews=null, $routePath='', $useViewInheritance=false, $style='')