Passed
Push — 5.0 ( 921311...0e84bd )
by David
03:01
created
src/Mouf/Database/TDBM/Controllers/TdbmInstallController.php 1 patch
Indentation   +242 added lines, -242 removed lines patch added patch discarded remove patch
@@ -21,246 +21,246 @@
 block discarded – undo
21 21
  */
22 22
 class TdbmInstallController extends Controller
23 23
 {
24
-    /**
25
-     * @var HtmlBlock
26
-     */
27
-    public $content;
28
-
29
-    public $selfedit;
30
-
31
-    /**
32
-     * The active MoufManager to be edited/viewed.
33
-     *
34
-     * @var MoufManager
35
-     */
36
-    public $moufManager;
37
-
38
-    /**
39
-     * The template used by the main page for mouf.
40
-     *
41
-     * @Property
42
-     * @Compulsory
43
-     *
44
-     * @var TemplateInterface
45
-     */
46
-    public $template;
47
-
48
-    /**
49
-     * Displays the first install screen.
50
-     *
51
-     * @Action
52
-     * @Logged
53
-     *
54
-     * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
55
-     */
56
-    public function defaultAction($selfedit = 'false')
57
-    {
58
-        $this->selfedit = $selfedit;
59
-
60
-        if ($selfedit == 'true') {
61
-            $this->moufManager = MoufManager::getMoufManager();
62
-        } else {
63
-            $this->moufManager = MoufManager::getMoufManagerHiddenInstance();
64
-        }
65
-
66
-        $this->content->addFile(__DIR__.'/../../../../views/installStep1.php', $this);
67
-        $this->template->toHtml();
68
-    }
69
-
70
-    /**
71
-     * Skips the install process.
72
-     *
73
-     * @Action
74
-     * @Logged
75
-     *
76
-     * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
77
-     */
78
-    public function skip($selfedit = 'false')
79
-    {
80
-        InstallUtils::continueInstall($selfedit == 'true');
81
-    }
82
-
83
-    protected $daoNamespace;
84
-    protected $beanNamespace;
85
-    protected $autoloadDetected;
86
-    //protected $storeInUtc;
87
-    protected $useCustomComposer = false;
88
-    protected $composerFile;
89
-
90
-    /**
91
-     * Displays the second install screen.
92
-     *
93
-     * @Action
94
-     * @Logged
95
-     *
96
-     * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
97
-     */
98
-    public function configure($selfedit = 'false')
99
-    {
100
-        $this->selfedit = $selfedit;
101
-
102
-        if ($selfedit == 'true') {
103
-            $this->moufManager = MoufManager::getMoufManager();
104
-        } else {
105
-            $this->moufManager = MoufManager::getMoufManagerHiddenInstance();
106
-        }
107
-
108
-        // Let's start by performing basic checks about the instances we assume to exist.
109
-        if (!$this->moufManager->instanceExists('dbalConnection')) {
110
-            $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.");
111
-
112
-            return;
113
-        }
114
-
115
-        if ($this->moufManager->has('tdbmConfiguration')) {
116
-            $tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
117
-
118
-            $this->beanNamespace = $tdbmConfiguration->getConstructorArgumentProperty('beanNamespace')->getValue();
119
-            $this->daoNamespace = $tdbmConfiguration->getConstructorArgumentProperty('daoNamespace')->getValue();
120
-        } else {
121
-            // Old TDBM 4.2 fallback
122
-            $this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace_tdbmService');
123
-            $this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace_tdbmService');
124
-        }
125
-
126
-        if ($this->daoNamespace == null && $this->beanNamespace == null) {
127
-            $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json');
128
-
129
-            $autoloadNamespaces = $classNameMapper->getManagedNamespaces();
130
-            if ($autoloadNamespaces) {
131
-                $this->autoloadDetected = true;
132
-                $rootNamespace = $autoloadNamespaces[0];
133
-                $this->daoNamespace = $rootNamespace.'Dao';
134
-                $this->beanNamespace = $rootNamespace.'Model';
135
-            } else {
136
-                $this->autoloadDetected = false;
137
-                $this->daoNamespace = 'YourApplication\\Dao';
138
-                $this->beanNamespace = 'YourApplication\\Model';
139
-            }
140
-        } else {
141
-            $this->autoloadDetected = true;
142
-        }
143
-        $this->defaultPath = true;
144
-        $this->storePath = '';
145
-
146
-        $this->castDatesToDateTime = true;
147
-
148
-        $this->content->addFile(__DIR__.'/../../../../views/installStep2.php', $this);
149
-        $this->template->toHtml();
150
-    }
151
-
152
-    /**
153
-     * This action generates the TDBM instance, then the DAOs and Beans.
154
-     *
155
-     * @Action
156
-     *
157
-     * @param string $daonamespace
158
-     * @param string $beannamespace
159
-     * @param string $selfedit
160
-     *
161
-     * @throws \Mouf\MoufException
162
-     */
163
-    public function generate($daonamespace, $beannamespace, /*$storeInUtc = 0,*/ $selfedit = 'false', $defaultPath = false, $storePath = '')
164
-    {
165
-        $this->selfedit = $selfedit;
166
-
167
-        if ($selfedit == 'true') {
168
-            $this->moufManager = MoufManager::getMoufManager();
169
-        } else {
170
-            $this->moufManager = MoufManager::getMoufManagerHiddenInstance();
171
-        }
172
-
173
-        $doctrineCache = $this->moufManager->getInstanceDescriptor('defaultDoctrineCache');
174
-
175
-        $migratingFrom42 = false;
176
-        if ($this->moufManager->has('tdbmService') && !$this->moufManager->has('tdbmConfiguration')) {
177
-            $migratingFrom42 = true;
178
-        }
179
-
180
-        if ($this->moufManager->has('tdbmService') && $this->moufManager->getInstanceDescriptor('tdbmService')->getClassName() === 'Mouf\\Database\\TDBM\\TDBMService') {
181
-            $this->migrateNamespaceTo50($this->moufManager);
182
-        }
183
-
184
-        $namingStrategy = InstallUtils::getOrCreateInstance('namingStrategy', DefaultNamingStrategy::class, $this->moufManager);
185
-        if ($migratingFrom42) {
186
-            // Let's setup the naming strategy for compatibility
187
-            $namingStrategy->getSetterProperty('setBeanPrefix')->setValue('');
188
-            $namingStrategy->getSetterProperty('setBeanSuffix')->setValue('Bean');
189
-            $namingStrategy->getSetterProperty('setBaseBeanPrefix')->setValue('');
190
-            $namingStrategy->getSetterProperty('setBaseBeanSuffix')->setValue('BaseBean');
191
-            $namingStrategy->getSetterProperty('setDaoPrefix')->setValue('');
192
-            $namingStrategy->getSetterProperty('setDaoSuffix')->setValue('Dao');
193
-            $namingStrategy->getSetterProperty('setBaseDaoPrefix')->setValue('');
194
-            $namingStrategy->getSetterProperty('setBaseDaoSuffix')->setValue('BaseDao');
195
-        }
196
-
197
-        if (!$this->moufManager->instanceExists('tdbmConfiguration')) {
198
-            $moufListener = InstallUtils::getOrCreateInstance(MoufDiListener::class, MoufDiListener::class, $this->moufManager);
199
-
200
-            $tdbmConfiguration = $this->moufManager->createInstance(MoufConfiguration::class)->setName('tdbmConfiguration');
201
-            $tdbmConfiguration->getConstructorArgumentProperty('connection')->setValue($this->moufManager->getInstanceDescriptor('dbalConnection'));
202
-            $tdbmConfiguration->getConstructorArgumentProperty('cache')->setValue($doctrineCache);
203
-            $tdbmConfiguration->getConstructorArgumentProperty('namingStrategy')->setValue($namingStrategy);
204
-            $tdbmConfiguration->getProperty('daoFactoryInstanceName')->setValue('daoFactory');
205
-            $tdbmConfiguration->getConstructorArgumentProperty('generatorListeners')->setValue([$moufListener]);
206
-
207
-            // Let's also delete the tdbmService if migrating versions <= 4.2
208
-            if ($migratingFrom42) {
209
-                $this->moufManager->removeComponent('tdbmService');
210
-            }
211
-        } else {
212
-            $tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
213
-        }
214
-
215
-        if (!$this->moufManager->instanceExists('tdbmService')) {
216
-            $tdbmService = $this->moufManager->createInstance('TheCodingMachine\\TDBM\\TDBMService')->setName('tdbmService');
217
-            $tdbmService->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
218
-        }
219
-
220
-        // We declare our instance of the Symfony command as a Mouf instance
221
-        $generateCommand = InstallUtils::getOrCreateInstance('generateCommand', GenerateCommand::class, $this->moufManager);
222
-        $generateCommand->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
223
-
224
-        // We register that instance descriptor using "ConsoleUtils"
225
-        $consoleUtils = new ConsoleUtils($this->moufManager);
226
-        $consoleUtils->registerCommand($generateCommand);
227
-
228
-        $this->moufManager->rewriteMouf();
229
-
230
-        TdbmController::generateDaos($this->moufManager, 'tdbmService', $daonamespace, $beannamespace, 'daoFactory', $selfedit, /*$storeInUtc,*/ $defaultPath, $storePath);
231
-
232
-        InstallUtils::continueInstall($selfedit == 'true');
233
-    }
234
-
235
-    protected $errorMsg;
236
-
237
-    private function displayErrorMsg($msg)
238
-    {
239
-        $this->errorMsg = $msg;
240
-        $this->content->addFile(__DIR__.'/../../../../views/installError.php', $this);
241
-        $this->template->toHtml();
242
-    }
243
-
244
-    /**
245
-     * Migrate classes from old 4.x namespace (Mouf\Database\TDBM) to new 5.x namespace (TheCodingMachine\TDBM)
246
-     *
247
-     * @param MoufManager $moufManager
248
-     */
249
-    private function migrateNamespaceTo50(MoufManager $moufManager)
250
-    {
251
-        $instanceList = $moufManager->getInstancesList();
252
-
253
-        $migratedClasses = [
254
-            'Mouf\\Database\\TDBM\\Configuration' => 'TheCodingMachine\\TDBM\\Configuration',
255
-            'Mouf\\Database\\TDBM\\TDBMService' => 'TheCodingMachine\\TDBM\\TDBMService',
256
-            'Mouf\\Database\\TDBM\\Commands\\GenerateCommand' => 'TheCodingMachine\\TDBM\\Commands\\GenerateCommand',
257
-            'Mouf\\Database\\TDBM\\Utils\\DefaultNamingStrategy' => 'TheCodingMachine\\TDBM\\Utils\\DefaultNamingStrategy',
258
-        ];
259
-
260
-        foreach ($instanceList as $instanceName => $className) {
261
-            if (isset($migratedClasses[$className])) {
262
-                $moufManager->alterClass($instanceName, $migratedClasses[$className]);
263
-            }
264
-        }
265
-    }
24
+	/**
25
+	 * @var HtmlBlock
26
+	 */
27
+	public $content;
28
+
29
+	public $selfedit;
30
+
31
+	/**
32
+	 * The active MoufManager to be edited/viewed.
33
+	 *
34
+	 * @var MoufManager
35
+	 */
36
+	public $moufManager;
37
+
38
+	/**
39
+	 * The template used by the main page for mouf.
40
+	 *
41
+	 * @Property
42
+	 * @Compulsory
43
+	 *
44
+	 * @var TemplateInterface
45
+	 */
46
+	public $template;
47
+
48
+	/**
49
+	 * Displays the first install screen.
50
+	 *
51
+	 * @Action
52
+	 * @Logged
53
+	 *
54
+	 * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
55
+	 */
56
+	public function defaultAction($selfedit = 'false')
57
+	{
58
+		$this->selfedit = $selfedit;
59
+
60
+		if ($selfedit == 'true') {
61
+			$this->moufManager = MoufManager::getMoufManager();
62
+		} else {
63
+			$this->moufManager = MoufManager::getMoufManagerHiddenInstance();
64
+		}
65
+
66
+		$this->content->addFile(__DIR__.'/../../../../views/installStep1.php', $this);
67
+		$this->template->toHtml();
68
+	}
69
+
70
+	/**
71
+	 * Skips the install process.
72
+	 *
73
+	 * @Action
74
+	 * @Logged
75
+	 *
76
+	 * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
77
+	 */
78
+	public function skip($selfedit = 'false')
79
+	{
80
+		InstallUtils::continueInstall($selfedit == 'true');
81
+	}
82
+
83
+	protected $daoNamespace;
84
+	protected $beanNamespace;
85
+	protected $autoloadDetected;
86
+	//protected $storeInUtc;
87
+	protected $useCustomComposer = false;
88
+	protected $composerFile;
89
+
90
+	/**
91
+	 * Displays the second install screen.
92
+	 *
93
+	 * @Action
94
+	 * @Logged
95
+	 *
96
+	 * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
97
+	 */
98
+	public function configure($selfedit = 'false')
99
+	{
100
+		$this->selfedit = $selfedit;
101
+
102
+		if ($selfedit == 'true') {
103
+			$this->moufManager = MoufManager::getMoufManager();
104
+		} else {
105
+			$this->moufManager = MoufManager::getMoufManagerHiddenInstance();
106
+		}
107
+
108
+		// Let's start by performing basic checks about the instances we assume to exist.
109
+		if (!$this->moufManager->instanceExists('dbalConnection')) {
110
+			$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.");
111
+
112
+			return;
113
+		}
114
+
115
+		if ($this->moufManager->has('tdbmConfiguration')) {
116
+			$tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
117
+
118
+			$this->beanNamespace = $tdbmConfiguration->getConstructorArgumentProperty('beanNamespace')->getValue();
119
+			$this->daoNamespace = $tdbmConfiguration->getConstructorArgumentProperty('daoNamespace')->getValue();
120
+		} else {
121
+			// Old TDBM 4.2 fallback
122
+			$this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace_tdbmService');
123
+			$this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace_tdbmService');
124
+		}
125
+
126
+		if ($this->daoNamespace == null && $this->beanNamespace == null) {
127
+			$classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json');
128
+
129
+			$autoloadNamespaces = $classNameMapper->getManagedNamespaces();
130
+			if ($autoloadNamespaces) {
131
+				$this->autoloadDetected = true;
132
+				$rootNamespace = $autoloadNamespaces[0];
133
+				$this->daoNamespace = $rootNamespace.'Dao';
134
+				$this->beanNamespace = $rootNamespace.'Model';
135
+			} else {
136
+				$this->autoloadDetected = false;
137
+				$this->daoNamespace = 'YourApplication\\Dao';
138
+				$this->beanNamespace = 'YourApplication\\Model';
139
+			}
140
+		} else {
141
+			$this->autoloadDetected = true;
142
+		}
143
+		$this->defaultPath = true;
144
+		$this->storePath = '';
145
+
146
+		$this->castDatesToDateTime = true;
147
+
148
+		$this->content->addFile(__DIR__.'/../../../../views/installStep2.php', $this);
149
+		$this->template->toHtml();
150
+	}
151
+
152
+	/**
153
+	 * This action generates the TDBM instance, then the DAOs and Beans.
154
+	 *
155
+	 * @Action
156
+	 *
157
+	 * @param string $daonamespace
158
+	 * @param string $beannamespace
159
+	 * @param string $selfedit
160
+	 *
161
+	 * @throws \Mouf\MoufException
162
+	 */
163
+	public function generate($daonamespace, $beannamespace, /*$storeInUtc = 0,*/ $selfedit = 'false', $defaultPath = false, $storePath = '')
164
+	{
165
+		$this->selfedit = $selfedit;
166
+
167
+		if ($selfedit == 'true') {
168
+			$this->moufManager = MoufManager::getMoufManager();
169
+		} else {
170
+			$this->moufManager = MoufManager::getMoufManagerHiddenInstance();
171
+		}
172
+
173
+		$doctrineCache = $this->moufManager->getInstanceDescriptor('defaultDoctrineCache');
174
+
175
+		$migratingFrom42 = false;
176
+		if ($this->moufManager->has('tdbmService') && !$this->moufManager->has('tdbmConfiguration')) {
177
+			$migratingFrom42 = true;
178
+		}
179
+
180
+		if ($this->moufManager->has('tdbmService') && $this->moufManager->getInstanceDescriptor('tdbmService')->getClassName() === 'Mouf\\Database\\TDBM\\TDBMService') {
181
+			$this->migrateNamespaceTo50($this->moufManager);
182
+		}
183
+
184
+		$namingStrategy = InstallUtils::getOrCreateInstance('namingStrategy', DefaultNamingStrategy::class, $this->moufManager);
185
+		if ($migratingFrom42) {
186
+			// Let's setup the naming strategy for compatibility
187
+			$namingStrategy->getSetterProperty('setBeanPrefix')->setValue('');
188
+			$namingStrategy->getSetterProperty('setBeanSuffix')->setValue('Bean');
189
+			$namingStrategy->getSetterProperty('setBaseBeanPrefix')->setValue('');
190
+			$namingStrategy->getSetterProperty('setBaseBeanSuffix')->setValue('BaseBean');
191
+			$namingStrategy->getSetterProperty('setDaoPrefix')->setValue('');
192
+			$namingStrategy->getSetterProperty('setDaoSuffix')->setValue('Dao');
193
+			$namingStrategy->getSetterProperty('setBaseDaoPrefix')->setValue('');
194
+			$namingStrategy->getSetterProperty('setBaseDaoSuffix')->setValue('BaseDao');
195
+		}
196
+
197
+		if (!$this->moufManager->instanceExists('tdbmConfiguration')) {
198
+			$moufListener = InstallUtils::getOrCreateInstance(MoufDiListener::class, MoufDiListener::class, $this->moufManager);
199
+
200
+			$tdbmConfiguration = $this->moufManager->createInstance(MoufConfiguration::class)->setName('tdbmConfiguration');
201
+			$tdbmConfiguration->getConstructorArgumentProperty('connection')->setValue($this->moufManager->getInstanceDescriptor('dbalConnection'));
202
+			$tdbmConfiguration->getConstructorArgumentProperty('cache')->setValue($doctrineCache);
203
+			$tdbmConfiguration->getConstructorArgumentProperty('namingStrategy')->setValue($namingStrategy);
204
+			$tdbmConfiguration->getProperty('daoFactoryInstanceName')->setValue('daoFactory');
205
+			$tdbmConfiguration->getConstructorArgumentProperty('generatorListeners')->setValue([$moufListener]);
206
+
207
+			// Let's also delete the tdbmService if migrating versions <= 4.2
208
+			if ($migratingFrom42) {
209
+				$this->moufManager->removeComponent('tdbmService');
210
+			}
211
+		} else {
212
+			$tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
213
+		}
214
+
215
+		if (!$this->moufManager->instanceExists('tdbmService')) {
216
+			$tdbmService = $this->moufManager->createInstance('TheCodingMachine\\TDBM\\TDBMService')->setName('tdbmService');
217
+			$tdbmService->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
218
+		}
219
+
220
+		// We declare our instance of the Symfony command as a Mouf instance
221
+		$generateCommand = InstallUtils::getOrCreateInstance('generateCommand', GenerateCommand::class, $this->moufManager);
222
+		$generateCommand->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
223
+
224
+		// We register that instance descriptor using "ConsoleUtils"
225
+		$consoleUtils = new ConsoleUtils($this->moufManager);
226
+		$consoleUtils->registerCommand($generateCommand);
227
+
228
+		$this->moufManager->rewriteMouf();
229
+
230
+		TdbmController::generateDaos($this->moufManager, 'tdbmService', $daonamespace, $beannamespace, 'daoFactory', $selfedit, /*$storeInUtc,*/ $defaultPath, $storePath);
231
+
232
+		InstallUtils::continueInstall($selfedit == 'true');
233
+	}
234
+
235
+	protected $errorMsg;
236
+
237
+	private function displayErrorMsg($msg)
238
+	{
239
+		$this->errorMsg = $msg;
240
+		$this->content->addFile(__DIR__.'/../../../../views/installError.php', $this);
241
+		$this->template->toHtml();
242
+	}
243
+
244
+	/**
245
+	 * Migrate classes from old 4.x namespace (Mouf\Database\TDBM) to new 5.x namespace (TheCodingMachine\TDBM)
246
+	 *
247
+	 * @param MoufManager $moufManager
248
+	 */
249
+	private function migrateNamespaceTo50(MoufManager $moufManager)
250
+	{
251
+		$instanceList = $moufManager->getInstancesList();
252
+
253
+		$migratedClasses = [
254
+			'Mouf\\Database\\TDBM\\Configuration' => 'TheCodingMachine\\TDBM\\Configuration',
255
+			'Mouf\\Database\\TDBM\\TDBMService' => 'TheCodingMachine\\TDBM\\TDBMService',
256
+			'Mouf\\Database\\TDBM\\Commands\\GenerateCommand' => 'TheCodingMachine\\TDBM\\Commands\\GenerateCommand',
257
+			'Mouf\\Database\\TDBM\\Utils\\DefaultNamingStrategy' => 'TheCodingMachine\\TDBM\\Utils\\DefaultNamingStrategy',
258
+		];
259
+
260
+		foreach ($instanceList as $instanceName => $className) {
261
+			if (isset($migratedClasses[$className])) {
262
+				$moufManager->alterClass($instanceName, $migratedClasses[$className]);
263
+			}
264
+		}
265
+	}
266 266
 }
Please login to merge, or discard this patch.