Passed
Push — 5.0 ( d6b4f8...921311 )
by David
17:04 queued 13:14
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   +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('Mouf\\Database\\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('Mouf\\Database\\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.
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/Mouf/Database/TDBM/Controllers/TdbmController.php 4 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@
 block discarded – undo
135 135
         return $configuration->getProperty($property)->getValue();
136 136
     }
137 137
 
138
-    private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ?string $value)
138
+    private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ? string $value)
139 139
     {
140 140
         $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName);
141 141
         if ($configuration === null) {
Please login to merge, or discard this patch.
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.
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.