Passed
Pull Request — 5.1 (#157)
by David
20:02 queued 13:38
created
src/Mouf/Database/TDBM/Controllers/TdbmInstallController.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -181,6 +181,9 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
Indentation   +254 added lines, -254 removed lines patch added patch discarded remove patch
@@ -25,258 +25,258 @@
 block discarded – undo
25 25
  */
26 26
 class TdbmInstallController extends Controller
27 27
 {
28
-    /**
29
-     * @var HtmlBlock
30
-     */
31
-    public $content;
32
-
33
-    public $selfedit;
34
-
35
-    /**
36
-     * The active MoufManager to be edited/viewed.
37
-     *
38
-     * @var MoufManager
39
-     */
40
-    public $moufManager;
41
-
42
-    /**
43
-     * The template used by the main page for mouf.
44
-     *
45
-     * @Property
46
-     * @Compulsory
47
-     *
48
-     * @var TemplateInterface
49
-     */
50
-    public $template;
51
-
52
-    /**
53
-     * Displays the first install screen.
54
-     *
55
-     * @Action
56
-     * @Logged
57
-     *
58
-     * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
59
-     */
60
-    public function defaultAction($selfedit = 'false')
61
-    {
62
-        $this->selfedit = $selfedit;
63
-
64
-        if ($selfedit == 'true') {
65
-            $this->moufManager = MoufManager::getMoufManager();
66
-        } else {
67
-            $this->moufManager = MoufManager::getMoufManagerHiddenInstance();
68
-        }
69
-
70
-        $this->content->addFile(__DIR__.'/../../../../views/installStep1.php', $this);
71
-        $this->template->toHtml();
72
-    }
73
-
74
-    /**
75
-     * Skips the install process.
76
-     *
77
-     * @Action
78
-     * @Logged
79
-     *
80
-     * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
81
-     */
82
-    public function skip($selfedit = 'false')
83
-    {
84
-        InstallUtils::continueInstall($selfedit == 'true');
85
-    }
86
-
87
-    protected $daoNamespace;
88
-    protected $beanNamespace;
89
-    protected $autoloadDetected;
90
-    //protected $storeInUtc;
91
-    protected $useCustomComposer = false;
92
-    protected $composerFile;
93
-
94
-    /**
95
-     * Displays the second install screen.
96
-     *
97
-     * @Action
98
-     * @Logged
99
-     *
100
-     * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
101
-     */
102
-    public function configure($selfedit = 'false')
103
-    {
104
-        $this->selfedit = $selfedit;
105
-
106
-        if ($selfedit == 'true') {
107
-            $this->moufManager = MoufManager::getMoufManager();
108
-        } else {
109
-            $this->moufManager = MoufManager::getMoufManagerHiddenInstance();
110
-        }
111
-
112
-        // Let's start by performing basic checks about the instances we assume to exist.
113
-        if (!$this->moufManager->instanceExists('dbalConnection')) {
114
-            $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.");
115
-
116
-            return;
117
-        }
118
-
119
-        if ($this->moufManager->has('tdbmConfiguration')) {
120
-            $tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
121
-
122
-            $this->beanNamespace = $tdbmConfiguration->getConstructorArgumentProperty('beanNamespace')->getValue();
123
-            $this->daoNamespace = $tdbmConfiguration->getConstructorArgumentProperty('daoNamespace')->getValue();
124
-        } else {
125
-            // Old TDBM 4.2 fallback
126
-            $this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace_tdbmService');
127
-            $this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace_tdbmService');
128
-        }
129
-
130
-        if ($this->daoNamespace == null && $this->beanNamespace == null) {
131
-            $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json');
132
-
133
-            $autoloadNamespaces = $classNameMapper->getManagedNamespaces();
134
-            if ($autoloadNamespaces) {
135
-                $this->autoloadDetected = true;
136
-                $rootNamespace = $autoloadNamespaces[0];
137
-                $this->daoNamespace = $rootNamespace.'Dao';
138
-                $this->beanNamespace = $rootNamespace.'Model';
139
-            } else {
140
-                $this->autoloadDetected = false;
141
-                $this->daoNamespace = 'YourApplication\\Dao';
142
-                $this->beanNamespace = 'YourApplication\\Model';
143
-            }
144
-        } else {
145
-            $this->autoloadDetected = true;
146
-        }
147
-        $this->defaultPath = true;
148
-        $this->storePath = '';
149
-
150
-        $this->castDatesToDateTime = true;
151
-
152
-        $this->content->addFile(__DIR__.'/../../../../views/installStep2.php', $this);
153
-        $this->template->toHtml();
154
-    }
155
-
156
-    /**
157
-     * This action generates the TDBM instance, then the DAOs and Beans.
158
-     *
159
-     * @Action
160
-     *
161
-     * @param string $daonamespace
162
-     * @param string $beannamespace
163
-     * @param string $selfedit
164
-     *
165
-     * @throws \Mouf\MoufException
166
-     */
167
-    public function generate($daonamespace, $beannamespace, /*$storeInUtc = 0,*/ $selfedit = 'false', $defaultPath = false, $storePath = '')
168
-    {
169
-        $this->selfedit = $selfedit;
170
-
171
-        if ($selfedit == 'true') {
172
-            $this->moufManager = MoufManager::getMoufManager();
173
-        } else {
174
-            $this->moufManager = MoufManager::getMoufManagerHiddenInstance();
175
-        }
176
-
177
-        $doctrineCache = $this->moufManager->getInstanceDescriptor('defaultDoctrineCache');
178
-
179
-        $migratingFrom42 = false;
180
-        if ($this->moufManager->has('tdbmService') && !$this->moufManager->has('tdbmConfiguration')) {
181
-            $migratingFrom42 = true;
182
-        }
183
-
184
-        if ($this->moufManager->has('tdbmService') && $this->moufManager->getInstanceDescriptor('tdbmService')->getClassName() === 'Mouf\\Database\\TDBM\\TDBMService') {
185
-            $this->migrateNamespaceTo50($this->moufManager);
186
-        }
187
-
188
-        $annotationParser = InstallUtils::getOrCreateInstance(AnnotationParser::class, AnnotationParser::class, $this->moufManager);
189
-        $annotationParser->getConstructorArgumentProperty('annotations')->setValue([
190
-            'UUID' => UUID::class,
191
-            'Autoincrement' => Autoincrement::class,
192
-            'Bean' => Bean::class
193
-        ]);
194
-
195
-        $namingStrategy = InstallUtils::getOrCreateInstance('namingStrategy', DefaultNamingStrategy::class, $this->moufManager);
196
-        if ($migratingFrom42) {
197
-            // Let's setup the naming strategy for compatibility
198
-            $namingStrategy->getSetterProperty('setBeanPrefix')->setValue('');
199
-            $namingStrategy->getSetterProperty('setBeanSuffix')->setValue('Bean');
200
-            $namingStrategy->getSetterProperty('setBaseBeanPrefix')->setValue('');
201
-            $namingStrategy->getSetterProperty('setBaseBeanSuffix')->setValue('BaseBean');
202
-            $namingStrategy->getSetterProperty('setDaoPrefix')->setValue('');
203
-            $namingStrategy->getSetterProperty('setDaoSuffix')->setValue('Dao');
204
-            $namingStrategy->getSetterProperty('setBaseDaoPrefix')->setValue('');
205
-            $namingStrategy->getSetterProperty('setBaseDaoSuffix')->setValue('BaseDao');
206
-        }
207
-        if ($namingStrategy->getClassName() === DefaultNamingStrategy::class) {
208
-            $namingStrategy->getConstructorArgumentProperty('annotationParser')->setValue($this->moufManager->getInstanceDescriptor(AnnotationParser::class));
209
-            $namingStrategy->getConstructorArgumentProperty('schemaManager')->setOrigin('php')->setValue('return $container->get(\'dbalConnection\')->getSchemaManager();');
210
-        }
211
-
212
-
213
-        if (!$this->moufManager->instanceExists('tdbmConfiguration')) {
214
-            $moufListener = InstallUtils::getOrCreateInstance(MoufDiListener::class, MoufDiListener::class, $this->moufManager);
215
-
216
-            $tdbmConfiguration = $this->moufManager->createInstance(MoufConfiguration::class)->setName('tdbmConfiguration');
217
-            $tdbmConfiguration->getConstructorArgumentProperty('connection')->setValue($this->moufManager->getInstanceDescriptor('dbalConnection'));
218
-            $tdbmConfiguration->getConstructorArgumentProperty('cache')->setValue($doctrineCache);
219
-            $tdbmConfiguration->getConstructorArgumentProperty('namingStrategy')->setValue($namingStrategy);
220
-            $tdbmConfiguration->getProperty('daoFactoryInstanceName')->setValue('daoFactory');
221
-            $tdbmConfiguration->getConstructorArgumentProperty('generatorListeners')->setValue([$moufListener]);
222
-
223
-            // Let's also delete the tdbmService if migrating versions <= 4.2
224
-            if ($migratingFrom42) {
225
-                $this->moufManager->removeComponent('tdbmService');
226
-            }
227
-        } else {
228
-            $tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
229
-        }
230
-
231
-        if (!$this->moufManager->instanceExists('tdbmService')) {
232
-            $tdbmService = $this->moufManager->createInstance('TheCodingMachine\\TDBM\\TDBMService')->setName('tdbmService');
233
-            $tdbmService->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
234
-        }
235
-
236
-        // We declare our instance of the Symfony command as a Mouf instance
237
-        $generateCommand = InstallUtils::getOrCreateInstance('generateCommand', GenerateCommand::class, $this->moufManager);
238
-        $generateCommand->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
239
-
240
-        // We register that instance descriptor using "ConsoleUtils"
241
-        $consoleUtils = new ConsoleUtils($this->moufManager);
242
-        $consoleUtils->registerCommand($generateCommand);
243
-
244
-        $this->moufManager->rewriteMouf();
245
-
246
-        TdbmController::generateDaos($this->moufManager, 'tdbmService', $daonamespace, $beannamespace, 'daoFactory', $selfedit, /*$storeInUtc,*/ $defaultPath, $storePath);
247
-
248
-        InstallUtils::continueInstall($selfedit == 'true');
249
-    }
250
-
251
-    protected $errorMsg;
252
-
253
-    private function displayErrorMsg($msg)
254
-    {
255
-        $this->errorMsg = $msg;
256
-        $this->content->addFile(__DIR__.'/../../../../views/installError.php', $this);
257
-        $this->template->toHtml();
258
-    }
259
-
260
-    /**
261
-     * Migrate classes from old 4.x namespace (Mouf\Database\TDBM) to new 5.x namespace (TheCodingMachine\TDBM)
262
-     *
263
-     * @param MoufManager $moufManager
264
-     */
265
-    private function migrateNamespaceTo50(MoufManager $moufManager)
266
-    {
267
-        $instanceList = $moufManager->getInstancesList();
268
-
269
-        $migratedClasses = [
270
-            'Mouf\\Database\\TDBM\\Configuration' => 'TheCodingMachine\\TDBM\\Configuration',
271
-            'Mouf\\Database\\TDBM\\TDBMService' => 'TheCodingMachine\\TDBM\\TDBMService',
272
-            'Mouf\\Database\\TDBM\\Commands\\GenerateCommand' => 'TheCodingMachine\\TDBM\\Commands\\GenerateCommand',
273
-            'Mouf\\Database\\TDBM\\Utils\\DefaultNamingStrategy' => 'TheCodingMachine\\TDBM\\Utils\\DefaultNamingStrategy',
274
-        ];
275
-
276
-        foreach ($instanceList as $instanceName => $className) {
277
-            if (isset($migratedClasses[$className])) {
278
-                $moufManager->alterClass($instanceName, $migratedClasses[$className]);
279
-            }
280
-        }
281
-    }
28
+	/**
29
+	 * @var HtmlBlock
30
+	 */
31
+	public $content;
32
+
33
+	public $selfedit;
34
+
35
+	/**
36
+	 * The active MoufManager to be edited/viewed.
37
+	 *
38
+	 * @var MoufManager
39
+	 */
40
+	public $moufManager;
41
+
42
+	/**
43
+	 * The template used by the main page for mouf.
44
+	 *
45
+	 * @Property
46
+	 * @Compulsory
47
+	 *
48
+	 * @var TemplateInterface
49
+	 */
50
+	public $template;
51
+
52
+	/**
53
+	 * Displays the first install screen.
54
+	 *
55
+	 * @Action
56
+	 * @Logged
57
+	 *
58
+	 * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
59
+	 */
60
+	public function defaultAction($selfedit = 'false')
61
+	{
62
+		$this->selfedit = $selfedit;
63
+
64
+		if ($selfedit == 'true') {
65
+			$this->moufManager = MoufManager::getMoufManager();
66
+		} else {
67
+			$this->moufManager = MoufManager::getMoufManagerHiddenInstance();
68
+		}
69
+
70
+		$this->content->addFile(__DIR__.'/../../../../views/installStep1.php', $this);
71
+		$this->template->toHtml();
72
+	}
73
+
74
+	/**
75
+	 * Skips the install process.
76
+	 *
77
+	 * @Action
78
+	 * @Logged
79
+	 *
80
+	 * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
81
+	 */
82
+	public function skip($selfedit = 'false')
83
+	{
84
+		InstallUtils::continueInstall($selfedit == 'true');
85
+	}
86
+
87
+	protected $daoNamespace;
88
+	protected $beanNamespace;
89
+	protected $autoloadDetected;
90
+	//protected $storeInUtc;
91
+	protected $useCustomComposer = false;
92
+	protected $composerFile;
93
+
94
+	/**
95
+	 * Displays the second install screen.
96
+	 *
97
+	 * @Action
98
+	 * @Logged
99
+	 *
100
+	 * @param string $selfedit If true, the name of the component must be a component from the Mouf framework itself (internal use only)
101
+	 */
102
+	public function configure($selfedit = 'false')
103
+	{
104
+		$this->selfedit = $selfedit;
105
+
106
+		if ($selfedit == 'true') {
107
+			$this->moufManager = MoufManager::getMoufManager();
108
+		} else {
109
+			$this->moufManager = MoufManager::getMoufManagerHiddenInstance();
110
+		}
111
+
112
+		// Let's start by performing basic checks about the instances we assume to exist.
113
+		if (!$this->moufManager->instanceExists('dbalConnection')) {
114
+			$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.");
115
+
116
+			return;
117
+		}
118
+
119
+		if ($this->moufManager->has('tdbmConfiguration')) {
120
+			$tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
121
+
122
+			$this->beanNamespace = $tdbmConfiguration->getConstructorArgumentProperty('beanNamespace')->getValue();
123
+			$this->daoNamespace = $tdbmConfiguration->getConstructorArgumentProperty('daoNamespace')->getValue();
124
+		} else {
125
+			// Old TDBM 4.2 fallback
126
+			$this->daoNamespace = $this->moufManager->getVariable('tdbmDefaultDaoNamespace_tdbmService');
127
+			$this->beanNamespace = $this->moufManager->getVariable('tdbmDefaultBeanNamespace_tdbmService');
128
+		}
129
+
130
+		if ($this->daoNamespace == null && $this->beanNamespace == null) {
131
+			$classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json');
132
+
133
+			$autoloadNamespaces = $classNameMapper->getManagedNamespaces();
134
+			if ($autoloadNamespaces) {
135
+				$this->autoloadDetected = true;
136
+				$rootNamespace = $autoloadNamespaces[0];
137
+				$this->daoNamespace = $rootNamespace.'Dao';
138
+				$this->beanNamespace = $rootNamespace.'Model';
139
+			} else {
140
+				$this->autoloadDetected = false;
141
+				$this->daoNamespace = 'YourApplication\\Dao';
142
+				$this->beanNamespace = 'YourApplication\\Model';
143
+			}
144
+		} else {
145
+			$this->autoloadDetected = true;
146
+		}
147
+		$this->defaultPath = true;
148
+		$this->storePath = '';
149
+
150
+		$this->castDatesToDateTime = true;
151
+
152
+		$this->content->addFile(__DIR__.'/../../../../views/installStep2.php', $this);
153
+		$this->template->toHtml();
154
+	}
155
+
156
+	/**
157
+	 * This action generates the TDBM instance, then the DAOs and Beans.
158
+	 *
159
+	 * @Action
160
+	 *
161
+	 * @param string $daonamespace
162
+	 * @param string $beannamespace
163
+	 * @param string $selfedit
164
+	 *
165
+	 * @throws \Mouf\MoufException
166
+	 */
167
+	public function generate($daonamespace, $beannamespace, /*$storeInUtc = 0,*/ $selfedit = 'false', $defaultPath = false, $storePath = '')
168
+	{
169
+		$this->selfedit = $selfedit;
170
+
171
+		if ($selfedit == 'true') {
172
+			$this->moufManager = MoufManager::getMoufManager();
173
+		} else {
174
+			$this->moufManager = MoufManager::getMoufManagerHiddenInstance();
175
+		}
176
+
177
+		$doctrineCache = $this->moufManager->getInstanceDescriptor('defaultDoctrineCache');
178
+
179
+		$migratingFrom42 = false;
180
+		if ($this->moufManager->has('tdbmService') && !$this->moufManager->has('tdbmConfiguration')) {
181
+			$migratingFrom42 = true;
182
+		}
183
+
184
+		if ($this->moufManager->has('tdbmService') && $this->moufManager->getInstanceDescriptor('tdbmService')->getClassName() === 'Mouf\\Database\\TDBM\\TDBMService') {
185
+			$this->migrateNamespaceTo50($this->moufManager);
186
+		}
187
+
188
+		$annotationParser = InstallUtils::getOrCreateInstance(AnnotationParser::class, AnnotationParser::class, $this->moufManager);
189
+		$annotationParser->getConstructorArgumentProperty('annotations')->setValue([
190
+			'UUID' => UUID::class,
191
+			'Autoincrement' => Autoincrement::class,
192
+			'Bean' => Bean::class
193
+		]);
194
+
195
+		$namingStrategy = InstallUtils::getOrCreateInstance('namingStrategy', DefaultNamingStrategy::class, $this->moufManager);
196
+		if ($migratingFrom42) {
197
+			// Let's setup the naming strategy for compatibility
198
+			$namingStrategy->getSetterProperty('setBeanPrefix')->setValue('');
199
+			$namingStrategy->getSetterProperty('setBeanSuffix')->setValue('Bean');
200
+			$namingStrategy->getSetterProperty('setBaseBeanPrefix')->setValue('');
201
+			$namingStrategy->getSetterProperty('setBaseBeanSuffix')->setValue('BaseBean');
202
+			$namingStrategy->getSetterProperty('setDaoPrefix')->setValue('');
203
+			$namingStrategy->getSetterProperty('setDaoSuffix')->setValue('Dao');
204
+			$namingStrategy->getSetterProperty('setBaseDaoPrefix')->setValue('');
205
+			$namingStrategy->getSetterProperty('setBaseDaoSuffix')->setValue('BaseDao');
206
+		}
207
+		if ($namingStrategy->getClassName() === DefaultNamingStrategy::class) {
208
+			$namingStrategy->getConstructorArgumentProperty('annotationParser')->setValue($this->moufManager->getInstanceDescriptor(AnnotationParser::class));
209
+			$namingStrategy->getConstructorArgumentProperty('schemaManager')->setOrigin('php')->setValue('return $container->get(\'dbalConnection\')->getSchemaManager();');
210
+		}
211
+
212
+
213
+		if (!$this->moufManager->instanceExists('tdbmConfiguration')) {
214
+			$moufListener = InstallUtils::getOrCreateInstance(MoufDiListener::class, MoufDiListener::class, $this->moufManager);
215
+
216
+			$tdbmConfiguration = $this->moufManager->createInstance(MoufConfiguration::class)->setName('tdbmConfiguration');
217
+			$tdbmConfiguration->getConstructorArgumentProperty('connection')->setValue($this->moufManager->getInstanceDescriptor('dbalConnection'));
218
+			$tdbmConfiguration->getConstructorArgumentProperty('cache')->setValue($doctrineCache);
219
+			$tdbmConfiguration->getConstructorArgumentProperty('namingStrategy')->setValue($namingStrategy);
220
+			$tdbmConfiguration->getProperty('daoFactoryInstanceName')->setValue('daoFactory');
221
+			$tdbmConfiguration->getConstructorArgumentProperty('generatorListeners')->setValue([$moufListener]);
222
+
223
+			// Let's also delete the tdbmService if migrating versions <= 4.2
224
+			if ($migratingFrom42) {
225
+				$this->moufManager->removeComponent('tdbmService');
226
+			}
227
+		} else {
228
+			$tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
229
+		}
230
+
231
+		if (!$this->moufManager->instanceExists('tdbmService')) {
232
+			$tdbmService = $this->moufManager->createInstance('TheCodingMachine\\TDBM\\TDBMService')->setName('tdbmService');
233
+			$tdbmService->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
234
+		}
235
+
236
+		// We declare our instance of the Symfony command as a Mouf instance
237
+		$generateCommand = InstallUtils::getOrCreateInstance('generateCommand', GenerateCommand::class, $this->moufManager);
238
+		$generateCommand->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
239
+
240
+		// We register that instance descriptor using "ConsoleUtils"
241
+		$consoleUtils = new ConsoleUtils($this->moufManager);
242
+		$consoleUtils->registerCommand($generateCommand);
243
+
244
+		$this->moufManager->rewriteMouf();
245
+
246
+		TdbmController::generateDaos($this->moufManager, 'tdbmService', $daonamespace, $beannamespace, 'daoFactory', $selfedit, /*$storeInUtc,*/ $defaultPath, $storePath);
247
+
248
+		InstallUtils::continueInstall($selfedit == 'true');
249
+	}
250
+
251
+	protected $errorMsg;
252
+
253
+	private function displayErrorMsg($msg)
254
+	{
255
+		$this->errorMsg = $msg;
256
+		$this->content->addFile(__DIR__.'/../../../../views/installError.php', $this);
257
+		$this->template->toHtml();
258
+	}
259
+
260
+	/**
261
+	 * Migrate classes from old 4.x namespace (Mouf\Database\TDBM) to new 5.x namespace (TheCodingMachine\TDBM)
262
+	 *
263
+	 * @param MoufManager $moufManager
264
+	 */
265
+	private function migrateNamespaceTo50(MoufManager $moufManager)
266
+	{
267
+		$instanceList = $moufManager->getInstancesList();
268
+
269
+		$migratedClasses = [
270
+			'Mouf\\Database\\TDBM\\Configuration' => 'TheCodingMachine\\TDBM\\Configuration',
271
+			'Mouf\\Database\\TDBM\\TDBMService' => 'TheCodingMachine\\TDBM\\TDBMService',
272
+			'Mouf\\Database\\TDBM\\Commands\\GenerateCommand' => 'TheCodingMachine\\TDBM\\Commands\\GenerateCommand',
273
+			'Mouf\\Database\\TDBM\\Utils\\DefaultNamingStrategy' => 'TheCodingMachine\\TDBM\\Utils\\DefaultNamingStrategy',
274
+		];
275
+
276
+		foreach ($instanceList as $instanceName => $className) {
277
+			if (isset($migratedClasses[$className])) {
278
+				$moufManager->alterClass($instanceName, $migratedClasses[$className]);
279
+			}
280
+		}
281
+	}
282 282
 }
Please login to merge, or discard this patch.
src/views/tdbmGenerate.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 <input type="hidden" id="selfedit" name="selfedit" value="<?php echo plainstring_to_htmlprotected($this->selfedit) ?>" />
9 9
 
10 10
 <?php if (!$this->autoloadDetected) {
11
-    ?>
11
+	?>
12 12
 <div class="alert">Warning! TDBM could not detect the autoload section of your composer.json file.
13 13
 Unless you are developing your own autoload system, you should configure <strong>composer.json</strong> to <a href="http://getcomposer.org/doc/01-basic-usage.md#autoloading" target="_blank">define a source directory and a root namespace using PSR-0</a>.</div>
14 14
 <?php
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/MoufConfiguration.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -17,21 +17,21 @@
 block discarded – undo
17 17
  */
18 18
 class MoufConfiguration extends Configuration
19 19
 {
20
-    private $daoFactoryInstanceName = 'daoFactory';
20
+	private $daoFactoryInstanceName = 'daoFactory';
21 21
 
22
-    /**
23
-     * @return string
24
-     */
25
-    public function getDaoFactoryInstanceName() : string
26
-    {
27
-        return $this->daoFactoryInstanceName;
28
-    }
22
+	/**
23
+	 * @return string
24
+	 */
25
+	public function getDaoFactoryInstanceName() : string
26
+	{
27
+		return $this->daoFactoryInstanceName;
28
+	}
29 29
 
30
-    /**
31
-     * @param string $daoFactoryInstanceName
32
-     */
33
-    public function setDaoFactoryInstanceName(string $daoFactoryInstanceName)
34
-    {
35
-        $this->daoFactoryInstanceName = $daoFactoryInstanceName;
36
-    }
30
+	/**
31
+	 * @param string $daoFactoryInstanceName
32
+	 */
33
+	public function setDaoFactoryInstanceName(string $daoFactoryInstanceName)
34
+	{
35
+		$this->daoFactoryInstanceName = $daoFactoryInstanceName;
36
+	}
37 37
 }
Please login to merge, or discard this patch.
src/views/installStep2.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 <input type="hidden" id="selfedit" name="selfedit" value="<?php echo plainstring_to_htmlprotected($this->selfedit) ?>" />
9 9
 
10 10
 <?php if (!$this->autoloadDetected) {
11
-    ?>
11
+	?>
12 12
 <div class="alert">Warning! TDBM could not detect the autoload section of your composer.json file.
13 13
 Unless you are developing your own autoload system, you should configure <strong>composer.json</strong> to <a href="http://getcomposer.org/doc/01-basic-usage.md#autoloading" target="_blank">define a source directory and a root namespace using PSR-0</a>.</div>
14 14
 <?php
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Utils/MoufDiListener.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -11,58 +11,58 @@
 block discarded – undo
11 11
 class MoufDiListener implements GeneratorListenerInterface
12 12
 {
13 13
 
14
-    /**
15
-     * @param ConfigurationInterface $configuration
16
-     * @param BeanDescriptorInterface[] $beanDescriptors
17
-     */
18
-    public function onGenerate(ConfigurationInterface $configuration, array $beanDescriptors): void
19
-    {
20
-        // Let's generate the needed instance in Mouf.
21
-        $moufManager = MoufManager::getMoufManager();
14
+	/**
15
+	 * @param ConfigurationInterface $configuration
16
+	 * @param BeanDescriptorInterface[] $beanDescriptors
17
+	 */
18
+	public function onGenerate(ConfigurationInterface $configuration, array $beanDescriptors): void
19
+	{
20
+		// Let's generate the needed instance in Mouf.
21
+		$moufManager = MoufManager::getMoufManager();
22 22
 
23
-        $daoFactoryInstanceName = null;
24
-        if ($configuration instanceof MoufConfiguration) {
25
-            $daoFactoryInstanceName = $configuration->getDaoFactoryInstanceName();
26
-            $daoFactoryClassName = $configuration->getDaoNamespace().'\\Generated\\'.$configuration->getNamingStrategy()->getDaoFactoryClassName();
27
-            $moufManager->declareComponent($daoFactoryInstanceName, $daoFactoryClassName, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS);
28
-        }
23
+		$daoFactoryInstanceName = null;
24
+		if ($configuration instanceof MoufConfiguration) {
25
+			$daoFactoryInstanceName = $configuration->getDaoFactoryInstanceName();
26
+			$daoFactoryClassName = $configuration->getDaoNamespace().'\\Generated\\'.$configuration->getNamingStrategy()->getDaoFactoryClassName();
27
+			$moufManager->declareComponent($daoFactoryInstanceName, $daoFactoryClassName, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS);
28
+		}
29 29
 
30
-        $tdbmServiceInstanceName = $this->getTdbmInstanceName($configuration);
30
+		$tdbmServiceInstanceName = $this->getTdbmInstanceName($configuration);
31 31
 
32
-        foreach ($beanDescriptors as $beanDescriptor) {
33
-            $daoName = $beanDescriptor->getDaoClassName();
32
+		foreach ($beanDescriptors as $beanDescriptor) {
33
+			$daoName = $beanDescriptor->getDaoClassName();
34 34
 
35
-            $instanceName = TDBMDaoGenerator::toVariableName($daoName);
36
-            if (!$moufManager->instanceExists($instanceName)) {
37
-                $moufManager->declareComponent($instanceName, $configuration->getDaoNamespace().'\\'.$daoName);
38
-            }
39
-            $moufManager->setParameterViaConstructor($instanceName, 0, $tdbmServiceInstanceName, 'object');
40
-            if ($daoFactoryInstanceName !== null) {
41
-                $moufManager->bindComponentViaSetter($daoFactoryInstanceName, 'set'.$daoName, $instanceName);
42
-            }
43
-        }
35
+			$instanceName = TDBMDaoGenerator::toVariableName($daoName);
36
+			if (!$moufManager->instanceExists($instanceName)) {
37
+				$moufManager->declareComponent($instanceName, $configuration->getDaoNamespace().'\\'.$daoName);
38
+			}
39
+			$moufManager->setParameterViaConstructor($instanceName, 0, $tdbmServiceInstanceName, 'object');
40
+			if ($daoFactoryInstanceName !== null) {
41
+				$moufManager->bindComponentViaSetter($daoFactoryInstanceName, 'set'.$daoName, $instanceName);
42
+			}
43
+		}
44 44
 
45
-        $moufManager->rewriteMouf();
46
-    }
45
+		$moufManager->rewriteMouf();
46
+	}
47 47
 
48
-    private function getTdbmInstanceName(ConfigurationInterface $configuration) : string
49
-    {
50
-        $moufManager = MoufManager::getMoufManager();
48
+	private function getTdbmInstanceName(ConfigurationInterface $configuration) : string
49
+	{
50
+		$moufManager = MoufManager::getMoufManager();
51 51
 
52
-        $configurationInstanceName = $moufManager->findInstanceName($configuration);
53
-        if (!$configurationInstanceName) {
54
-            throw new \TDBMException('Could not find TDBM instance for configuration object.');
55
-        }
52
+		$configurationInstanceName = $moufManager->findInstanceName($configuration);
53
+		if (!$configurationInstanceName) {
54
+			throw new \TDBMException('Could not find TDBM instance for configuration object.');
55
+		}
56 56
 
57
-        // Let's find the configuration
58
-        $tdbmServicesNames = $moufManager->findInstances(TDBMService::class);
57
+		// Let's find the configuration
58
+		$tdbmServicesNames = $moufManager->findInstances(TDBMService::class);
59 59
 
60
-        foreach ($tdbmServicesNames as $name) {
61
-            if ($moufManager->getInstanceDescriptor($name)->getConstructorArgumentProperty('configuration')->getValue()->getName() === $configurationInstanceName) {
62
-                return $name;
63
-            }
64
-        }
60
+		foreach ($tdbmServicesNames as $name) {
61
+			if ($moufManager->getInstanceDescriptor($name)->getConstructorArgumentProperty('configuration')->getValue()->getName() === $configurationInstanceName) {
62
+				return $name;
63
+			}
64
+		}
65 65
 
66
-        throw new \TDBMException('Could not find TDBMService instance.');
67
-    }
66
+		throw new \TDBMException('Could not find TDBMService instance.');
67
+	}
68 68
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Controllers/TdbmController.php 3 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      * @Action
83 83
      *
84 84
      * @param string $name
85
-     * @param bool   $selfedit
85
+     * @param string|boolean   $selfedit
86 86
      */
87 87
     public function generate($name, $daonamespace, $beannamespace, $daofactoryinstancename, /*$storeInUtc = 0,*/ $selfedit = 'false', $useCustomComposer = false, $composerFile = '')
88 88
     {
@@ -102,6 +102,8 @@  discard block
 block discarded – undo
102 102
      * @param string      $daonamespace
103 103
      * @param string      $beannamespace
104 104
      * @param string      $selfedit
105
+     * @param boolean $useCustomComposer
106
+     * @param string $composerFile
105 107
      *
106 108
      * @throws \Mouf\MoufException
107 109
      */
Please login to merge, or discard this patch.
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -19,134 +19,134 @@
 block discarded – undo
19 19
  */
20 20
 class TdbmController extends AbstractMoufInstanceController
21 21
 {
22
-    /**
23
-     * @var HtmlBlock
24
-     */
25
-    public $content;
26
-
27
-    protected $daoNamespace;
28
-    protected $beanNamespace;
29
-    protected $daoFactoryInstanceName;
30
-    protected $autoloadDetected;
31
-    ///protected $storeInUtc;
32
-    protected $useCustomComposer;
33
-    protected $composerFile;
34
-
35
-    /**
36
-     * Admin page used to display the DAO generation form.
37
-     *
38
-     * @Action
39
-     */
40
-    public function defaultAction($name, $selfedit = 'false')
41
-    {
42
-        $this->initController($name, $selfedit);
43
-
44
-        // Fill variables
45
-        $this->daoNamespace = self::getFromConfiguration($this->moufManager, $name, 'daoNamespace');
46
-        $this->beanNamespace = self::getFromConfiguration($this->moufManager, $name, 'beanNamespace');
47
-        $this->daoFactoryInstanceName = self::getFromConfiguration($this->moufManager, $name, 'daoFactoryInstanceName');
48
-        //$this->storeInUtc = self::getFromConfiguration($this->moufManager, $name, 'storeInUtc');
49
-        $pathFinder = self::getFromConfiguration($this->moufManager, $name, 'pathFinder');
50
-        if ($pathFinder !== null) {
51
-            $this->composerFile = $pathFinder->getConstructorArgumentProperty('composerFile')->getValue();
52
-        } else {
53
-            $this->composerFile = null;
54
-        }
55
-        $this->useCustomComposer = $this->composerFile ? true : false;
56
-
57
-        if ($this->daoNamespace == null && $this->beanNamespace == null) {
58
-            $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json');
59
-
60
-            $autoloadNamespaces = $classNameMapper->getManagedNamespaces();
61
-            if ($autoloadNamespaces) {
62
-                $this->autoloadDetected = true;
63
-                $rootNamespace = $autoloadNamespaces[0];
64
-                $this->daoNamespace = $rootNamespace.'Dao';
65
-                $this->beanNamespace = $rootNamespace.'Dao\\Bean';
66
-            } else {
67
-                $this->autoloadDetected = false;
68
-                $this->daoNamespace = 'YourApplication\\Dao';
69
-                $this->beanNamespace = 'YourApplication\\Dao\\Bean';
70
-            }
71
-        } else {
72
-            $this->autoloadDetected = true;
73
-        }
74
-
75
-        $this->content->addFile(__DIR__.'/../../../../views/tdbmGenerate.php', $this);
76
-        $this->template->toHtml();
77
-    }
78
-
79
-    /**
80
-     * This action generates the DAOs and Beans for the TDBM service passed in parameter.
81
-     *
82
-     * @Action
83
-     *
84
-     * @param string $name
85
-     * @param bool   $selfedit
86
-     */
87
-    public function generate($name, $daonamespace, $beannamespace, $daofactoryinstancename, /*$storeInUtc = 0,*/ $selfedit = 'false', $useCustomComposer = false, $composerFile = '')
88
-    {
89
-        $this->initController($name, $selfedit);
90
-
91
-        self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit, /*$storeInUtc,*/ $useCustomComposer, $composerFile);
92
-
93
-        // TODO: better: we should redirect to a screen that list the number of DAOs generated, etc...
94
-        header('Location: '.ROOT_URL.'ajaxinstance/?name='.urlencode($name).'&selfedit='.$selfedit);
95
-    }
96
-
97
-    /**
98
-     * This function generates the DAOs and Beans for the TDBM service passed in parameter.
99
-     *
100
-     * @param MoufManager $moufManager
101
-     * @param string      $name
102
-     * @param string      $daonamespace
103
-     * @param string      $beannamespace
104
-     * @param string      $selfedit
105
-     *
106
-     * @throws \Mouf\MoufException
107
-     */
108
-    public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit = 'false', /*$storeInUtc = null,*/ $useCustomComposer = null, $composerFile = null)
109
-    {
110
-        self::setInConfiguration($moufManager, $name, 'daoNamespace', $daonamespace);
111
-        self::setInConfiguration($moufManager, $name, 'beanNamespace', $beannamespace);
112
-        self::setInConfiguration($moufManager, $name, 'daoFactoryInstanceName', $daofactoryinstancename);
113
-        //self::setInConfiguration($moufManager, $name, 'storeInUtc', $storeInUtc);
114
-        if ($useCustomComposer) {
115
-            $pathFinder = $moufManager->createInstance(PathFinder::class);
116
-            $pathFinder->getConstructorArgumentProperty('composerFile')->setValue($composerFile);
117
-            self::setInConfiguration($moufManager, $name, 'pathFinder', $pathFinder);
118
-        } else {
119
-            self::setInConfiguration($moufManager, $name, 'pathFinder', null);
120
-        }
121
-        // Let's rewrite before calling the DAO generator
122
-        $moufManager->rewriteMouf();
123
-
124
-
125
-        $tdbmService = new InstanceProxy($name);
126
-        /* @var $tdbmService TDBMService */
127
-        $tdbmService->generateAllDaosAndBeans();
128
-    }
129
-
130
-    private static function getConfigurationDescriptor(MoufManager $moufManager, string $tdbmInstanceName)
131
-    {
132
-        return $moufManager->getInstanceDescriptor($tdbmInstanceName)->getConstructorArgumentProperty('configuration')->getValue();
133
-    }
134
-
135
-    private static function getFromConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property)
136
-    {
137
-        $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName);
138
-        if ($configuration === null) {
139
-            throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.');
140
-        }
141
-        return $configuration->getProperty($property)->getValue();
142
-    }
143
-
144
-    private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ?string $value)
145
-    {
146
-        $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName);
147
-        if ($configuration === null) {
148
-            throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.');
149
-        }
150
-        $configuration->getProperty($property)->setValue($value);
151
-    }
22
+	/**
23
+	 * @var HtmlBlock
24
+	 */
25
+	public $content;
26
+
27
+	protected $daoNamespace;
28
+	protected $beanNamespace;
29
+	protected $daoFactoryInstanceName;
30
+	protected $autoloadDetected;
31
+	///protected $storeInUtc;
32
+	protected $useCustomComposer;
33
+	protected $composerFile;
34
+
35
+	/**
36
+	 * Admin page used to display the DAO generation form.
37
+	 *
38
+	 * @Action
39
+	 */
40
+	public function defaultAction($name, $selfedit = 'false')
41
+	{
42
+		$this->initController($name, $selfedit);
43
+
44
+		// Fill variables
45
+		$this->daoNamespace = self::getFromConfiguration($this->moufManager, $name, 'daoNamespace');
46
+		$this->beanNamespace = self::getFromConfiguration($this->moufManager, $name, 'beanNamespace');
47
+		$this->daoFactoryInstanceName = self::getFromConfiguration($this->moufManager, $name, 'daoFactoryInstanceName');
48
+		//$this->storeInUtc = self::getFromConfiguration($this->moufManager, $name, 'storeInUtc');
49
+		$pathFinder = self::getFromConfiguration($this->moufManager, $name, 'pathFinder');
50
+		if ($pathFinder !== null) {
51
+			$this->composerFile = $pathFinder->getConstructorArgumentProperty('composerFile')->getValue();
52
+		} else {
53
+			$this->composerFile = null;
54
+		}
55
+		$this->useCustomComposer = $this->composerFile ? true : false;
56
+
57
+		if ($this->daoNamespace == null && $this->beanNamespace == null) {
58
+			$classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json');
59
+
60
+			$autoloadNamespaces = $classNameMapper->getManagedNamespaces();
61
+			if ($autoloadNamespaces) {
62
+				$this->autoloadDetected = true;
63
+				$rootNamespace = $autoloadNamespaces[0];
64
+				$this->daoNamespace = $rootNamespace.'Dao';
65
+				$this->beanNamespace = $rootNamespace.'Dao\\Bean';
66
+			} else {
67
+				$this->autoloadDetected = false;
68
+				$this->daoNamespace = 'YourApplication\\Dao';
69
+				$this->beanNamespace = 'YourApplication\\Dao\\Bean';
70
+			}
71
+		} else {
72
+			$this->autoloadDetected = true;
73
+		}
74
+
75
+		$this->content->addFile(__DIR__.'/../../../../views/tdbmGenerate.php', $this);
76
+		$this->template->toHtml();
77
+	}
78
+
79
+	/**
80
+	 * This action generates the DAOs and Beans for the TDBM service passed in parameter.
81
+	 *
82
+	 * @Action
83
+	 *
84
+	 * @param string $name
85
+	 * @param bool   $selfedit
86
+	 */
87
+	public function generate($name, $daonamespace, $beannamespace, $daofactoryinstancename, /*$storeInUtc = 0,*/ $selfedit = 'false', $useCustomComposer = false, $composerFile = '')
88
+	{
89
+		$this->initController($name, $selfedit);
90
+
91
+		self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit, /*$storeInUtc,*/ $useCustomComposer, $composerFile);
92
+
93
+		// TODO: better: we should redirect to a screen that list the number of DAOs generated, etc...
94
+		header('Location: '.ROOT_URL.'ajaxinstance/?name='.urlencode($name).'&selfedit='.$selfedit);
95
+	}
96
+
97
+	/**
98
+	 * This function generates the DAOs and Beans for the TDBM service passed in parameter.
99
+	 *
100
+	 * @param MoufManager $moufManager
101
+	 * @param string      $name
102
+	 * @param string      $daonamespace
103
+	 * @param string      $beannamespace
104
+	 * @param string      $selfedit
105
+	 *
106
+	 * @throws \Mouf\MoufException
107
+	 */
108
+	public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit = 'false', /*$storeInUtc = null,*/ $useCustomComposer = null, $composerFile = null)
109
+	{
110
+		self::setInConfiguration($moufManager, $name, 'daoNamespace', $daonamespace);
111
+		self::setInConfiguration($moufManager, $name, 'beanNamespace', $beannamespace);
112
+		self::setInConfiguration($moufManager, $name, 'daoFactoryInstanceName', $daofactoryinstancename);
113
+		//self::setInConfiguration($moufManager, $name, 'storeInUtc', $storeInUtc);
114
+		if ($useCustomComposer) {
115
+			$pathFinder = $moufManager->createInstance(PathFinder::class);
116
+			$pathFinder->getConstructorArgumentProperty('composerFile')->setValue($composerFile);
117
+			self::setInConfiguration($moufManager, $name, 'pathFinder', $pathFinder);
118
+		} else {
119
+			self::setInConfiguration($moufManager, $name, 'pathFinder', null);
120
+		}
121
+		// Let's rewrite before calling the DAO generator
122
+		$moufManager->rewriteMouf();
123
+
124
+
125
+		$tdbmService = new InstanceProxy($name);
126
+		/* @var $tdbmService TDBMService */
127
+		$tdbmService->generateAllDaosAndBeans();
128
+	}
129
+
130
+	private static function getConfigurationDescriptor(MoufManager $moufManager, string $tdbmInstanceName)
131
+	{
132
+		return $moufManager->getInstanceDescriptor($tdbmInstanceName)->getConstructorArgumentProperty('configuration')->getValue();
133
+	}
134
+
135
+	private static function getFromConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property)
136
+	{
137
+		$configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName);
138
+		if ($configuration === null) {
139
+			throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.');
140
+		}
141
+		return $configuration->getProperty($property)->getValue();
142
+	}
143
+
144
+	private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ?string $value)
145
+	{
146
+		$configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName);
147
+		if ($configuration === null) {
148
+			throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.');
149
+		}
150
+		$configuration->getProperty($property)->setValue($value);
151
+	}
152 152
 }
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,6 @@
 block discarded – undo
6 6
 use Mouf\Controllers\AbstractMoufInstanceController;
7 7
 use TheCodingMachine\TDBM\TDBMService;
8 8
 use TheCodingMachine\TDBM\Utils\PathFinder\PathFinder;
9
-use TheCodingMachine\TDBM\Utils\TDBMDaoGenerator;
10 9
 use Mouf\Html\HtmlElement\HtmlBlock;
11 10
 use Mouf\MoufManager;
12 11
 use Mouf\InstanceProxy;
Please login to merge, or discard this patch.