@@ -181,6 +181,9 @@ |
||
181 | 181 | |
182 | 182 | protected $errorMsg; |
183 | 183 | |
184 | + /** |
|
185 | + * @param string $msg |
|
186 | + */ |
|
184 | 187 | private function displayErrorMsg($msg) |
185 | 188 | { |
186 | 189 | $this->errorMsg = $msg; |
@@ -15,173 +15,173 @@ |
||
15 | 15 | */ |
16 | 16 | class TdbmInstallController extends Controller |
17 | 17 | { |
18 | - /** |
|
19 | - * @var HtmlBlock |
|
20 | - */ |
|
21 | - public $content; |
|
22 | - |
|
23 | - public $selfedit; |
|
24 | - |
|
25 | - /** |
|
26 | - * The active MoufManager to be edited/viewed. |
|
27 | - * |
|
28 | - * @var MoufManager |
|
29 | - */ |
|
30 | - public $moufManager; |
|
31 | - |
|
32 | - /** |
|
33 | - * The template used by the main page for mouf. |
|
34 | - * |
|
35 | - * @Property |
|
36 | - * @Compulsory |
|
37 | - * |
|
38 | - * @var TemplateInterface |
|
39 | - */ |
|
40 | - public $template; |
|
41 | - |
|
42 | - /** |
|
43 | - * Displays the first install screen. |
|
44 | - * |
|
45 | - * @Action |
|
46 | - * @Logged |
|
47 | - * |
|
48 | - * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only) |
|
49 | - */ |
|
50 | - public function defaultAction($selfedit = 'false') |
|
51 | - { |
|
52 | - $this->selfedit = $selfedit; |
|
53 | - |
|
54 | - if ($selfedit == 'true') { |
|
55 | - $this->moufManager = MoufManager::getMoufManager(); |
|
56 | - } else { |
|
57 | - $this->moufManager = MoufManager::getMoufManagerHiddenInstance(); |
|
58 | - } |
|
59 | - |
|
60 | - $this->content->addFile(dirname(__FILE__).'/../../../../views/installStep1.php', $this); |
|
61 | - $this->template->toHtml(); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Skips the install process. |
|
66 | - * |
|
67 | - * @Action |
|
68 | - * @Logged |
|
69 | - * |
|
70 | - * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only) |
|
71 | - */ |
|
72 | - public function skip($selfedit = 'false') |
|
73 | - { |
|
74 | - InstallUtils::continueInstall($selfedit == 'true'); |
|
75 | - } |
|
76 | - |
|
77 | - protected $daoNamespace; |
|
78 | - protected $beanNamespace; |
|
79 | - protected $autoloadDetected; |
|
80 | - protected $storeInUtc; |
|
81 | - protected $useCustomComposer = false; |
|
82 | - |
|
83 | - /** |
|
84 | - * Displays the second install screen. |
|
85 | - * |
|
86 | - * @Action |
|
87 | - * @Logged |
|
88 | - * |
|
89 | - * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only) |
|
90 | - */ |
|
91 | - public function configure($selfedit = 'false') |
|
92 | - { |
|
93 | - $this->selfedit = $selfedit; |
|
94 | - |
|
95 | - if ($selfedit == 'true') { |
|
96 | - $this->moufManager = MoufManager::getMoufManager(); |
|
97 | - } else { |
|
98 | - $this->moufManager = MoufManager::getMoufManagerHiddenInstance(); |
|
99 | - } |
|
100 | - |
|
101 | - // Let's start by performing basic checks about the instances we assume to exist. |
|
102 | - if (!$this->moufManager->instanceExists('dbalConnection')) { |
|
103 | - $this->displayErrorMsg("The TDBM install process assumes your database connection instance is already created, and that the name of this instance is 'dbalConnection'. Could not find the 'dbalConnection' instance."); |
|
104 | - |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - $this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace_tdbmService'); |
|
109 | - $this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace_tdbmService'); |
|
110 | - |
|
111 | - if ($this->daoNamespace == null && $this->beanNamespace == null) { |
|
112 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
113 | - |
|
114 | - $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
115 | - if ($autoloadNamespaces) { |
|
116 | - $this->autoloadDetected = true; |
|
117 | - $rootNamespace = $autoloadNamespaces[0]; |
|
118 | - $this->daoNamespace = $rootNamespace.'Model\\Dao'; |
|
119 | - $this->beanNamespace = $rootNamespace.'Model\\Bean'; |
|
120 | - } else { |
|
121 | - $this->autoloadDetected = false; |
|
122 | - $this->daoNamespace = 'YourApplication\\Model\\Dao'; |
|
123 | - $this->beanNamespace = 'YourApplication\\Model\\Bean'; |
|
124 | - } |
|
125 | - } else { |
|
126 | - $this->autoloadDetected = true; |
|
127 | - } |
|
128 | - $this->defaultPath = true; |
|
129 | - $this->storePath = ''; |
|
130 | - |
|
131 | - $this->castDatesToDateTime = true; |
|
132 | - |
|
133 | - $this->content->addFile(dirname(__FILE__).'/../../../../views/installStep2.php', $this); |
|
134 | - $this->template->toHtml(); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * This action generates the TDBM instance, then the DAOs and Beans. |
|
139 | - * |
|
140 | - * @Action |
|
141 | - * |
|
142 | - * @param string $daonamespace |
|
143 | - * @param string $beannamespace |
|
144 | - * @param int $storeInUtc |
|
145 | - * @param string $selfedit |
|
146 | - * |
|
147 | - * @throws \Mouf\MoufException |
|
148 | - */ |
|
149 | - public function generate($daonamespace, $beannamespace, $storeInUtc = 0, $selfedit = 'false', $defaultPath = false, $storePath = '') |
|
150 | - { |
|
151 | - $this->selfedit = $selfedit; |
|
152 | - |
|
153 | - if ($selfedit == 'true') { |
|
154 | - $this->moufManager = MoufManager::getMoufManager(); |
|
155 | - } else { |
|
156 | - $this->moufManager = MoufManager::getMoufManagerHiddenInstance(); |
|
157 | - } |
|
158 | - |
|
159 | - if (!$this->moufManager->instanceExists('doctrineApcCache')) { |
|
160 | - $doctrineApcCache = $this->moufManager->createInstance('Doctrine\\Common\\Cache\\ApcCache')->setName('doctrineApcCache'); |
|
161 | - // TODO: set namespace |
|
162 | - } else { |
|
163 | - $doctrineApcCache = $this->moufManager->getInstanceDescriptor('doctrineApcCache'); |
|
164 | - } |
|
165 | - |
|
166 | - if (!$this->moufManager->instanceExists('tdbmService')) { |
|
167 | - $tdbmService = $this->moufManager->createInstance('Mouf\\Database\\TDBM\\TDBMService')->setName('tdbmService'); |
|
168 | - $tdbmService->getConstructorArgumentProperty('connection')->setValue($this->moufManager->getInstanceDescriptor('dbalConnection')); |
|
169 | - $tdbmService->getConstructorArgumentProperty('cache')->setValue($doctrineApcCache); |
|
170 | - } |
|
171 | - |
|
172 | - $this->moufManager->rewriteMouf(); |
|
173 | - |
|
174 | - TdbmController::generateDaos($this->moufManager, 'tdbmService', $daonamespace, $beannamespace, 'DaoFactory', 'daoFactory', $selfedit, $storeInUtc, $defaultPath, $storePath); |
|
175 | - |
|
176 | - InstallUtils::continueInstall($selfedit == 'true'); |
|
177 | - } |
|
178 | - |
|
179 | - protected $errorMsg; |
|
180 | - |
|
181 | - private function displayErrorMsg($msg) |
|
182 | - { |
|
183 | - $this->errorMsg = $msg; |
|
184 | - $this->content->addFile(dirname(__FILE__).'/../../../../views/installError.php', $this); |
|
185 | - $this->template->toHtml(); |
|
186 | - } |
|
18 | + /** |
|
19 | + * @var HtmlBlock |
|
20 | + */ |
|
21 | + public $content; |
|
22 | + |
|
23 | + public $selfedit; |
|
24 | + |
|
25 | + /** |
|
26 | + * The active MoufManager to be edited/viewed. |
|
27 | + * |
|
28 | + * @var MoufManager |
|
29 | + */ |
|
30 | + public $moufManager; |
|
31 | + |
|
32 | + /** |
|
33 | + * The template used by the main page for mouf. |
|
34 | + * |
|
35 | + * @Property |
|
36 | + * @Compulsory |
|
37 | + * |
|
38 | + * @var TemplateInterface |
|
39 | + */ |
|
40 | + public $template; |
|
41 | + |
|
42 | + /** |
|
43 | + * Displays the first install screen. |
|
44 | + * |
|
45 | + * @Action |
|
46 | + * @Logged |
|
47 | + * |
|
48 | + * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only) |
|
49 | + */ |
|
50 | + public function defaultAction($selfedit = 'false') |
|
51 | + { |
|
52 | + $this->selfedit = $selfedit; |
|
53 | + |
|
54 | + if ($selfedit == 'true') { |
|
55 | + $this->moufManager = MoufManager::getMoufManager(); |
|
56 | + } else { |
|
57 | + $this->moufManager = MoufManager::getMoufManagerHiddenInstance(); |
|
58 | + } |
|
59 | + |
|
60 | + $this->content->addFile(dirname(__FILE__).'/../../../../views/installStep1.php', $this); |
|
61 | + $this->template->toHtml(); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Skips the install process. |
|
66 | + * |
|
67 | + * @Action |
|
68 | + * @Logged |
|
69 | + * |
|
70 | + * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only) |
|
71 | + */ |
|
72 | + public function skip($selfedit = 'false') |
|
73 | + { |
|
74 | + InstallUtils::continueInstall($selfedit == 'true'); |
|
75 | + } |
|
76 | + |
|
77 | + protected $daoNamespace; |
|
78 | + protected $beanNamespace; |
|
79 | + protected $autoloadDetected; |
|
80 | + protected $storeInUtc; |
|
81 | + protected $useCustomComposer = false; |
|
82 | + |
|
83 | + /** |
|
84 | + * Displays the second install screen. |
|
85 | + * |
|
86 | + * @Action |
|
87 | + * @Logged |
|
88 | + * |
|
89 | + * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only) |
|
90 | + */ |
|
91 | + public function configure($selfedit = 'false') |
|
92 | + { |
|
93 | + $this->selfedit = $selfedit; |
|
94 | + |
|
95 | + if ($selfedit == 'true') { |
|
96 | + $this->moufManager = MoufManager::getMoufManager(); |
|
97 | + } else { |
|
98 | + $this->moufManager = MoufManager::getMoufManagerHiddenInstance(); |
|
99 | + } |
|
100 | + |
|
101 | + // Let's start by performing basic checks about the instances we assume to exist. |
|
102 | + if (!$this->moufManager->instanceExists('dbalConnection')) { |
|
103 | + $this->displayErrorMsg("The TDBM install process assumes your database connection instance is already created, and that the name of this instance is 'dbalConnection'. Could not find the 'dbalConnection' instance."); |
|
104 | + |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + $this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace_tdbmService'); |
|
109 | + $this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace_tdbmService'); |
|
110 | + |
|
111 | + if ($this->daoNamespace == null && $this->beanNamespace == null) { |
|
112 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
113 | + |
|
114 | + $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
115 | + if ($autoloadNamespaces) { |
|
116 | + $this->autoloadDetected = true; |
|
117 | + $rootNamespace = $autoloadNamespaces[0]; |
|
118 | + $this->daoNamespace = $rootNamespace.'Model\\Dao'; |
|
119 | + $this->beanNamespace = $rootNamespace.'Model\\Bean'; |
|
120 | + } else { |
|
121 | + $this->autoloadDetected = false; |
|
122 | + $this->daoNamespace = 'YourApplication\\Model\\Dao'; |
|
123 | + $this->beanNamespace = 'YourApplication\\Model\\Bean'; |
|
124 | + } |
|
125 | + } else { |
|
126 | + $this->autoloadDetected = true; |
|
127 | + } |
|
128 | + $this->defaultPath = true; |
|
129 | + $this->storePath = ''; |
|
130 | + |
|
131 | + $this->castDatesToDateTime = true; |
|
132 | + |
|
133 | + $this->content->addFile(dirname(__FILE__).'/../../../../views/installStep2.php', $this); |
|
134 | + $this->template->toHtml(); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * This action generates the TDBM instance, then the DAOs and Beans. |
|
139 | + * |
|
140 | + * @Action |
|
141 | + * |
|
142 | + * @param string $daonamespace |
|
143 | + * @param string $beannamespace |
|
144 | + * @param int $storeInUtc |
|
145 | + * @param string $selfedit |
|
146 | + * |
|
147 | + * @throws \Mouf\MoufException |
|
148 | + */ |
|
149 | + public function generate($daonamespace, $beannamespace, $storeInUtc = 0, $selfedit = 'false', $defaultPath = false, $storePath = '') |
|
150 | + { |
|
151 | + $this->selfedit = $selfedit; |
|
152 | + |
|
153 | + if ($selfedit == 'true') { |
|
154 | + $this->moufManager = MoufManager::getMoufManager(); |
|
155 | + } else { |
|
156 | + $this->moufManager = MoufManager::getMoufManagerHiddenInstance(); |
|
157 | + } |
|
158 | + |
|
159 | + if (!$this->moufManager->instanceExists('doctrineApcCache')) { |
|
160 | + $doctrineApcCache = $this->moufManager->createInstance('Doctrine\\Common\\Cache\\ApcCache')->setName('doctrineApcCache'); |
|
161 | + // TODO: set namespace |
|
162 | + } else { |
|
163 | + $doctrineApcCache = $this->moufManager->getInstanceDescriptor('doctrineApcCache'); |
|
164 | + } |
|
165 | + |
|
166 | + if (!$this->moufManager->instanceExists('tdbmService')) { |
|
167 | + $tdbmService = $this->moufManager->createInstance('Mouf\\Database\\TDBM\\TDBMService')->setName('tdbmService'); |
|
168 | + $tdbmService->getConstructorArgumentProperty('connection')->setValue($this->moufManager->getInstanceDescriptor('dbalConnection')); |
|
169 | + $tdbmService->getConstructorArgumentProperty('cache')->setValue($doctrineApcCache); |
|
170 | + } |
|
171 | + |
|
172 | + $this->moufManager->rewriteMouf(); |
|
173 | + |
|
174 | + TdbmController::generateDaos($this->moufManager, 'tdbmService', $daonamespace, $beannamespace, 'DaoFactory', 'daoFactory', $selfedit, $storeInUtc, $defaultPath, $storePath); |
|
175 | + |
|
176 | + InstallUtils::continueInstall($selfedit == 'true'); |
|
177 | + } |
|
178 | + |
|
179 | + protected $errorMsg; |
|
180 | + |
|
181 | + private function displayErrorMsg($msg) |
|
182 | + { |
|
183 | + $this->errorMsg = $msg; |
|
184 | + $this->content->addFile(dirname(__FILE__).'/../../../../views/installError.php', $this); |
|
185 | + $this->template->toHtml(); |
|
186 | + } |
|
187 | 187 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @Action |
87 | 87 | * |
88 | 88 | * @param string $name |
89 | - * @param bool $selfedit |
|
89 | + * @param string|boolean $selfedit |
|
90 | 90 | */ |
91 | 91 | public function generate($name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $storeInUtc = 0, $selfedit = 'false', $useCustomComposer = false, $composerFile = '') |
92 | 92 | { |
@@ -109,6 +109,8 @@ discard block |
||
109 | 109 | * @param string $daofactoryinstancename |
110 | 110 | * @param string $selfedit |
111 | 111 | * @param bool $storeInUtc |
112 | + * @param boolean $useCustomComposer |
|
113 | + * @param string $composerFile |
|
112 | 114 | * |
113 | 115 | * @throws \Mouf\MoufException |
114 | 116 | */ |
@@ -17,159 +17,159 @@ |
||
17 | 17 | */ |
18 | 18 | class TdbmController extends AbstractMoufInstanceController |
19 | 19 | { |
20 | - /** |
|
21 | - * @var HtmlBlock |
|
22 | - */ |
|
23 | - public $content; |
|
24 | - |
|
25 | - protected $daoNamespace; |
|
26 | - protected $beanNamespace; |
|
27 | - protected $daoFactoryName; |
|
28 | - protected $daoFactoryInstanceName; |
|
29 | - protected $autoloadDetected; |
|
30 | - protected $storeInUtc; |
|
31 | - protected $useCustomComposer; |
|
32 | - |
|
33 | - /** |
|
34 | - * Admin page used to display the DAO generation form. |
|
35 | - * |
|
36 | - * @Action |
|
37 | - * //@Admin |
|
38 | - */ |
|
39 | - public function defaultAction($name, $selfedit = 'false') |
|
40 | - { |
|
41 | - $this->initController($name, $selfedit); |
|
42 | - |
|
43 | - // Fill variables |
|
44 | - if ($this->moufManager->getVariable('tdbmDefaultSourceDirectory_'.$name) != null) { |
|
45 | - $this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace_'.$name); |
|
46 | - $this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace_'.$name); |
|
47 | - $this->daoFactoryName = $this->moufManager->getVariable('tdbmDefaultDaoFactoryName_'.$name); |
|
48 | - $this->daoFactoryInstanceName = $this->moufManager->getVariable('tdbmDefaultDaoFactoryInstanceName_'.$name); |
|
49 | - $this->storeInUtc = $this->moufManager->getVariable('tdbmDefaultStoreInUtc_'.$name); |
|
50 | - $this->useCustomComposer = $this->moufManager->getVariable('tdbmDefaultUseCustomComposer_'.$name); |
|
51 | - $this->composerFile = $this->moufManager->getVariable('tdbmDefaultComposerFile_'.$name); |
|
52 | - } else { |
|
53 | - $this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace'); |
|
54 | - $this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace'); |
|
55 | - $this->daoFactoryName = $this->moufManager->getVariable('tdbmDefaultDaoFactoryName'); |
|
56 | - $this->daoFactoryInstanceName = $this->moufManager->getVariable('tdbmDefaultDaoFactoryInstanceName'); |
|
57 | - $this->storeInUtc = $this->moufManager->getVariable('tdbmDefaultStoreInUtc'); |
|
58 | - $this->useCustomComposer = $this->moufManager->getVariable('tdbmDefaultUseCustomComposer'); |
|
59 | - $this->composerFile = $this->moufManager->getVariable('tdbmDefaultComposerFile'); |
|
60 | - } |
|
61 | - |
|
62 | - if ($this->daoNamespace == null && $this->beanNamespace == null) { |
|
63 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
64 | - |
|
65 | - $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
66 | - if ($autoloadNamespaces) { |
|
67 | - $this->autoloadDetected = true; |
|
68 | - $rootNamespace = $autoloadNamespaces[0]; |
|
69 | - $this->daoNamespace = $rootNamespace.'Dao'; |
|
70 | - $this->beanNamespace = $rootNamespace.'Dao\\Bean'; |
|
71 | - } else { |
|
72 | - $this->autoloadDetected = false; |
|
73 | - $this->daoNamespace = 'YourApplication\\Dao'; |
|
74 | - $this->beanNamespace = 'YourApplication\\Dao\\Bean'; |
|
75 | - } |
|
76 | - } else { |
|
77 | - $this->autoloadDetected = true; |
|
78 | - } |
|
79 | - |
|
80 | - $this->content->addFile(dirname(__FILE__).'/../../../../views/tdbmGenerate.php', $this); |
|
81 | - $this->template->toHtml(); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * This action generates the DAOs and Beans for the TDBM service passed in parameter. |
|
86 | - * |
|
87 | - * @Action |
|
88 | - * |
|
89 | - * @param string $name |
|
90 | - * @param bool $selfedit |
|
91 | - */ |
|
92 | - public function generate($name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $storeInUtc = 0, $selfedit = 'false', $useCustomComposer = false, $composerFile = '') |
|
93 | - { |
|
94 | - $this->initController($name, $selfedit); |
|
95 | - |
|
96 | - self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit, $storeInUtc, $useCustomComposer, $composerFile); |
|
97 | - |
|
98 | - // TODO: better: we should redirect to a screen that list the number of DAOs generated, etc... |
|
99 | - header('Location: '.ROOT_URL.'ajaxinstance/?name='.urlencode($name).'&selfedit='.$selfedit); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * This function generates the DAOs and Beans for the TDBM service passed in parameter. |
|
104 | - * |
|
105 | - * @param MoufManager $moufManager |
|
106 | - * @param string $name |
|
107 | - * @param string $daonamespace |
|
108 | - * @param string $beannamespace |
|
109 | - * @param string $daofactoryclassname |
|
110 | - * @param string $daofactoryinstancename |
|
111 | - * @param string $selfedit |
|
112 | - * @param bool $storeInUtc |
|
113 | - * |
|
114 | - * @throws \Mouf\MoufException |
|
115 | - */ |
|
116 | - public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit = 'false', $storeInUtc = null, $useCustomComposer = null, $composerFile = null) |
|
117 | - { |
|
118 | - $moufManager->setVariable('tdbmDefaultDaoNamespace_'.$name, $daonamespace); |
|
119 | - $moufManager->setVariable('tdbmDefaultBeanNamespace_'.$name, $beannamespace); |
|
120 | - $moufManager->setVariable('tdbmDefaultDaoFactoryName_'.$name, $daofactoryclassname); |
|
121 | - $moufManager->setVariable('tdbmDefaultDaoFactoryInstanceName_'.$name, $daofactoryinstancename); |
|
122 | - $moufManager->setVariable('tdbmDefaultStoreInUtc_'.$name, $storeInUtc); |
|
123 | - $moufManager->setVariable('tdbmDefaultUseCustomComposer_'.$name, $useCustomComposer); |
|
124 | - $moufManager->setVariable('tdbmDefaultComposerFile_'.$name, $composerFile); |
|
125 | - |
|
126 | - // In case of instance renaming, let's use the last used settings |
|
127 | - $moufManager->setVariable('tdbmDefaultDaoNamespace', $daonamespace); |
|
128 | - $moufManager->setVariable('tdbmDefaultBeanNamespace', $beannamespace); |
|
129 | - $moufManager->setVariable('tdbmDefaultDaoFactoryName', $daofactoryclassname); |
|
130 | - $moufManager->setVariable('tdbmDefaultDaoFactoryInstanceName', $daofactoryinstancename); |
|
131 | - $moufManager->setVariable('tdbmDefaultStoreInUtc', $storeInUtc); |
|
132 | - $moufManager->setVariable('tdbmDefaultUseCustomComposer', $useCustomComposer); |
|
133 | - $moufManager->setVariable('tdbmDefaultComposerFile', $composerFile); |
|
134 | - |
|
135 | - // Remove first and last slash in namespace. |
|
136 | - if (strpos($daonamespace, '\\') === 0) { |
|
137 | - $daonamespace = substr($daonamespace, 1); |
|
138 | - } |
|
139 | - if (strpos($daonamespace, '\\') === strlen($daonamespace) - 1) { |
|
140 | - $daonamespace = substr($daonamespace, 0, strlen($daonamespace) - 1); |
|
141 | - } |
|
142 | - if (strpos($beannamespace, '\\') === 0) { |
|
143 | - $beannamespace = substr($beannamespace, 1); |
|
144 | - } |
|
145 | - if (strpos($beannamespace, '\\') === strlen($beannamespace) - 1) { |
|
146 | - $beannamespace = substr($beannamespace, 0, strlen($beannamespace) - 1); |
|
147 | - } |
|
148 | - |
|
149 | - $tdbmService = new InstanceProxy($name); |
|
150 | - /* @var $tdbmService TDBMService */ |
|
151 | - $tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $storeInUtc, ($useCustomComposer ? $composerFile : null)); |
|
152 | - |
|
153 | - $moufManager->declareComponent($daofactoryinstancename, $daonamespace.'\\'.$daofactoryclassname, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS); |
|
154 | - |
|
155 | - $tableToBeanMap = []; |
|
156 | - |
|
157 | - //$tdbmServiceDescriptor = $moufManager->getInstanceDescriptor('tdbmService'); |
|
158 | - |
|
159 | - foreach ($tables as $table) { |
|
160 | - $daoName = TDBMDaoGenerator::getDaoNameFromTableName($table); |
|
161 | - |
|
162 | - $instanceName = TDBMDaoGenerator::toVariableName($daoName); |
|
163 | - if (!$moufManager->instanceExists($instanceName)) { |
|
164 | - $moufManager->declareComponent($instanceName, $daonamespace.'\\'.$daoName); |
|
165 | - } |
|
166 | - $moufManager->setParameterViaConstructor($instanceName, 0, $name, 'object'); |
|
167 | - $moufManager->bindComponentViaSetter($daofactoryinstancename, 'set'.$daoName, $instanceName); |
|
168 | - |
|
169 | - $tableToBeanMap[$table] = $beannamespace.'\\'.TDBMDaoGenerator::getBeanNameFromTableName($table); |
|
170 | - } |
|
171 | - $tdbmServiceDescriptor = $moufManager->getInstanceDescriptor($name); |
|
172 | - $tdbmServiceDescriptor->getSetterProperty('setTableToBeanMap')->setValue($tableToBeanMap); |
|
173 | - $moufManager->rewriteMouf(); |
|
174 | - } |
|
20 | + /** |
|
21 | + * @var HtmlBlock |
|
22 | + */ |
|
23 | + public $content; |
|
24 | + |
|
25 | + protected $daoNamespace; |
|
26 | + protected $beanNamespace; |
|
27 | + protected $daoFactoryName; |
|
28 | + protected $daoFactoryInstanceName; |
|
29 | + protected $autoloadDetected; |
|
30 | + protected $storeInUtc; |
|
31 | + protected $useCustomComposer; |
|
32 | + |
|
33 | + /** |
|
34 | + * Admin page used to display the DAO generation form. |
|
35 | + * |
|
36 | + * @Action |
|
37 | + * //@Admin |
|
38 | + */ |
|
39 | + public function defaultAction($name, $selfedit = 'false') |
|
40 | + { |
|
41 | + $this->initController($name, $selfedit); |
|
42 | + |
|
43 | + // Fill variables |
|
44 | + if ($this->moufManager->getVariable('tdbmDefaultSourceDirectory_'.$name) != null) { |
|
45 | + $this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace_'.$name); |
|
46 | + $this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace_'.$name); |
|
47 | + $this->daoFactoryName = $this->moufManager->getVariable('tdbmDefaultDaoFactoryName_'.$name); |
|
48 | + $this->daoFactoryInstanceName = $this->moufManager->getVariable('tdbmDefaultDaoFactoryInstanceName_'.$name); |
|
49 | + $this->storeInUtc = $this->moufManager->getVariable('tdbmDefaultStoreInUtc_'.$name); |
|
50 | + $this->useCustomComposer = $this->moufManager->getVariable('tdbmDefaultUseCustomComposer_'.$name); |
|
51 | + $this->composerFile = $this->moufManager->getVariable('tdbmDefaultComposerFile_'.$name); |
|
52 | + } else { |
|
53 | + $this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace'); |
|
54 | + $this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace'); |
|
55 | + $this->daoFactoryName = $this->moufManager->getVariable('tdbmDefaultDaoFactoryName'); |
|
56 | + $this->daoFactoryInstanceName = $this->moufManager->getVariable('tdbmDefaultDaoFactoryInstanceName'); |
|
57 | + $this->storeInUtc = $this->moufManager->getVariable('tdbmDefaultStoreInUtc'); |
|
58 | + $this->useCustomComposer = $this->moufManager->getVariable('tdbmDefaultUseCustomComposer'); |
|
59 | + $this->composerFile = $this->moufManager->getVariable('tdbmDefaultComposerFile'); |
|
60 | + } |
|
61 | + |
|
62 | + if ($this->daoNamespace == null && $this->beanNamespace == null) { |
|
63 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
64 | + |
|
65 | + $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
66 | + if ($autoloadNamespaces) { |
|
67 | + $this->autoloadDetected = true; |
|
68 | + $rootNamespace = $autoloadNamespaces[0]; |
|
69 | + $this->daoNamespace = $rootNamespace.'Dao'; |
|
70 | + $this->beanNamespace = $rootNamespace.'Dao\\Bean'; |
|
71 | + } else { |
|
72 | + $this->autoloadDetected = false; |
|
73 | + $this->daoNamespace = 'YourApplication\\Dao'; |
|
74 | + $this->beanNamespace = 'YourApplication\\Dao\\Bean'; |
|
75 | + } |
|
76 | + } else { |
|
77 | + $this->autoloadDetected = true; |
|
78 | + } |
|
79 | + |
|
80 | + $this->content->addFile(dirname(__FILE__).'/../../../../views/tdbmGenerate.php', $this); |
|
81 | + $this->template->toHtml(); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * This action generates the DAOs and Beans for the TDBM service passed in parameter. |
|
86 | + * |
|
87 | + * @Action |
|
88 | + * |
|
89 | + * @param string $name |
|
90 | + * @param bool $selfedit |
|
91 | + */ |
|
92 | + public function generate($name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $storeInUtc = 0, $selfedit = 'false', $useCustomComposer = false, $composerFile = '') |
|
93 | + { |
|
94 | + $this->initController($name, $selfedit); |
|
95 | + |
|
96 | + self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit, $storeInUtc, $useCustomComposer, $composerFile); |
|
97 | + |
|
98 | + // TODO: better: we should redirect to a screen that list the number of DAOs generated, etc... |
|
99 | + header('Location: '.ROOT_URL.'ajaxinstance/?name='.urlencode($name).'&selfedit='.$selfedit); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * This function generates the DAOs and Beans for the TDBM service passed in parameter. |
|
104 | + * |
|
105 | + * @param MoufManager $moufManager |
|
106 | + * @param string $name |
|
107 | + * @param string $daonamespace |
|
108 | + * @param string $beannamespace |
|
109 | + * @param string $daofactoryclassname |
|
110 | + * @param string $daofactoryinstancename |
|
111 | + * @param string $selfedit |
|
112 | + * @param bool $storeInUtc |
|
113 | + * |
|
114 | + * @throws \Mouf\MoufException |
|
115 | + */ |
|
116 | + public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit = 'false', $storeInUtc = null, $useCustomComposer = null, $composerFile = null) |
|
117 | + { |
|
118 | + $moufManager->setVariable('tdbmDefaultDaoNamespace_'.$name, $daonamespace); |
|
119 | + $moufManager->setVariable('tdbmDefaultBeanNamespace_'.$name, $beannamespace); |
|
120 | + $moufManager->setVariable('tdbmDefaultDaoFactoryName_'.$name, $daofactoryclassname); |
|
121 | + $moufManager->setVariable('tdbmDefaultDaoFactoryInstanceName_'.$name, $daofactoryinstancename); |
|
122 | + $moufManager->setVariable('tdbmDefaultStoreInUtc_'.$name, $storeInUtc); |
|
123 | + $moufManager->setVariable('tdbmDefaultUseCustomComposer_'.$name, $useCustomComposer); |
|
124 | + $moufManager->setVariable('tdbmDefaultComposerFile_'.$name, $composerFile); |
|
125 | + |
|
126 | + // In case of instance renaming, let's use the last used settings |
|
127 | + $moufManager->setVariable('tdbmDefaultDaoNamespace', $daonamespace); |
|
128 | + $moufManager->setVariable('tdbmDefaultBeanNamespace', $beannamespace); |
|
129 | + $moufManager->setVariable('tdbmDefaultDaoFactoryName', $daofactoryclassname); |
|
130 | + $moufManager->setVariable('tdbmDefaultDaoFactoryInstanceName', $daofactoryinstancename); |
|
131 | + $moufManager->setVariable('tdbmDefaultStoreInUtc', $storeInUtc); |
|
132 | + $moufManager->setVariable('tdbmDefaultUseCustomComposer', $useCustomComposer); |
|
133 | + $moufManager->setVariable('tdbmDefaultComposerFile', $composerFile); |
|
134 | + |
|
135 | + // Remove first and last slash in namespace. |
|
136 | + if (strpos($daonamespace, '\\') === 0) { |
|
137 | + $daonamespace = substr($daonamespace, 1); |
|
138 | + } |
|
139 | + if (strpos($daonamespace, '\\') === strlen($daonamespace) - 1) { |
|
140 | + $daonamespace = substr($daonamespace, 0, strlen($daonamespace) - 1); |
|
141 | + } |
|
142 | + if (strpos($beannamespace, '\\') === 0) { |
|
143 | + $beannamespace = substr($beannamespace, 1); |
|
144 | + } |
|
145 | + if (strpos($beannamespace, '\\') === strlen($beannamespace) - 1) { |
|
146 | + $beannamespace = substr($beannamespace, 0, strlen($beannamespace) - 1); |
|
147 | + } |
|
148 | + |
|
149 | + $tdbmService = new InstanceProxy($name); |
|
150 | + /* @var $tdbmService TDBMService */ |
|
151 | + $tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $storeInUtc, ($useCustomComposer ? $composerFile : null)); |
|
152 | + |
|
153 | + $moufManager->declareComponent($daofactoryinstancename, $daonamespace.'\\'.$daofactoryclassname, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS); |
|
154 | + |
|
155 | + $tableToBeanMap = []; |
|
156 | + |
|
157 | + //$tdbmServiceDescriptor = $moufManager->getInstanceDescriptor('tdbmService'); |
|
158 | + |
|
159 | + foreach ($tables as $table) { |
|
160 | + $daoName = TDBMDaoGenerator::getDaoNameFromTableName($table); |
|
161 | + |
|
162 | + $instanceName = TDBMDaoGenerator::toVariableName($daoName); |
|
163 | + if (!$moufManager->instanceExists($instanceName)) { |
|
164 | + $moufManager->declareComponent($instanceName, $daonamespace.'\\'.$daoName); |
|
165 | + } |
|
166 | + $moufManager->setParameterViaConstructor($instanceName, 0, $name, 'object'); |
|
167 | + $moufManager->bindComponentViaSetter($daofactoryinstancename, 'set'.$daoName, $instanceName); |
|
168 | + |
|
169 | + $tableToBeanMap[$table] = $beannamespace.'\\'.TDBMDaoGenerator::getBeanNameFromTableName($table); |
|
170 | + } |
|
171 | + $tdbmServiceDescriptor = $moufManager->getInstanceDescriptor($name); |
|
172 | + $tdbmServiceDescriptor->getSetterProperty('setTableToBeanMap')->setValue($tableToBeanMap); |
|
173 | + $moufManager->rewriteMouf(); |
|
174 | + } |
|
175 | 175 | } |