Passed
Pull Request — 4.2 (#140)
by David
05:21
created
src/Mouf/Database/TDBM/Utils/DefaultNamingStrategy.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -7,168 +7,168 @@
 block discarded – undo
7 7
 
8 8
 class DefaultNamingStrategy implements NamingStrategyInterface
9 9
 {
10
-    private $beanPrefix = '';
11
-    private $beanSuffix = '';
12
-    private $baseBeanPrefix = 'Abstract';
13
-    private $baseBeanSuffix = '';
14
-    private $daoPrefix = '';
15
-    private $daoSuffix = 'Dao';
16
-    private $baseDaoPrefix = 'Abstract';
17
-    private $baseDaoSuffix = 'Dao';
18
-
19
-    /**
20
-     * Sets the string prefix to any bean class name.
21
-     *
22
-     * @param string $beanPrefix
23
-     */
24
-    public function setBeanPrefix(string $beanPrefix)
25
-    {
26
-        $this->beanPrefix = $beanPrefix;
27
-    }
28
-
29
-    /**
30
-     * Sets the string suffix to any bean class name.
31
-     *
32
-     * @param string $beanSuffix
33
-     */
34
-    public function setBeanSuffix(string $beanSuffix)
35
-    {
36
-        $this->beanSuffix = $beanSuffix;
37
-    }
38
-
39
-    /**
40
-     * Sets the string prefix to any base bean class name.
41
-     *
42
-     * @param string $baseBeanPrefix
43
-     */
44
-    public function setBaseBeanPrefix(string $baseBeanPrefix)
45
-    {
46
-        $this->baseBeanPrefix = $baseBeanPrefix;
47
-    }
48
-
49
-    /**
50
-     * Sets the string suffix to any base bean class name.
51
-     *
52
-     * @param string $baseBeanSuffix
53
-     */
54
-    public function setBaseBeanSuffix(string $baseBeanSuffix)
55
-    {
56
-        $this->baseBeanSuffix = $baseBeanSuffix;
57
-    }
58
-
59
-    /**
60
-     * Sets the string prefix to any DAO class name.
61
-     *
62
-     * @param string $daoPrefix
63
-     */
64
-    public function setDaoPrefix(string $daoPrefix)
65
-    {
66
-        $this->daoPrefix = $daoPrefix;
67
-    }
68
-
69
-    /**
70
-     * Sets the string suffix to any DAO class name.
71
-     *
72
-     * @param string $daoSuffix
73
-     */
74
-    public function setDaoSuffix(string $daoSuffix)
75
-    {
76
-        $this->daoSuffix = $daoSuffix;
77
-    }
78
-
79
-    /**
80
-     * Sets the string prefix to any base DAO class name.
81
-     *
82
-     * @param string $baseDaoPrefix
83
-     */
84
-    public function setBaseDaoPrefix(string $baseDaoPrefix)
85
-    {
86
-        $this->baseDaoPrefix = $baseDaoPrefix;
87
-    }
88
-
89
-    /**
90
-     * Sets the string suffix to any base DAO class name.
91
-     *
92
-     * @param string $baseDaoSuffix
93
-     */
94
-    public function setBaseDaoSuffix(string $baseDaoSuffix)
95
-    {
96
-        $this->baseDaoSuffix = $baseDaoSuffix;
97
-    }
98
-
99
-
100
-    /**
101
-     * Returns the bean class name from the table name (excluding the namespace).
102
-     *
103
-     * @param string $tableName
104
-     * @return string
105
-     */
106
-    public function getBeanClassName(string $tableName): string
107
-    {
108
-        return $this->beanPrefix.self::toSingularCamelCase($tableName).$this->beanSuffix;
109
-    }
110
-
111
-    /**
112
-     * Returns the base bean class name from the table name (excluding the namespace).
113
-     *
114
-     * @param string $tableName
115
-     * @return string
116
-     */
117
-    public function getBaseBeanClassName(string $tableName): string
118
-    {
119
-        return $this->baseBeanPrefix.self::toSingularCamelCase($tableName).$this->baseBeanSuffix;
120
-    }
121
-
122
-    /**
123
-     * Returns the name of the DAO class from the table name (excluding the namespace).
124
-     *
125
-     * @param string $tableName
126
-     * @return string
127
-     */
128
-    public function getDaoClassName(string $tableName): string
129
-    {
130
-        return $this->daoPrefix.self::toSingularCamelCase($tableName).$this->daoSuffix;
131
-    }
132
-
133
-    /**
134
-     * Returns the name of the base DAO class from the table name (excluding the namespace).
135
-     *
136
-     * @param string $tableName
137
-     * @return string
138
-     */
139
-    public function getBaseDaoClassName(string $tableName): string
140
-    {
141
-        return $this->baseDaoPrefix.self::toSingularCamelCase($tableName).$this->baseDaoSuffix;
142
-    }
143
-
144
-    /**
145
-     * Tries to put string to the singular form (if it is plural) and camel case form.
146
-     * We assume the table names are in english.
147
-     *
148
-     * @param $str string
149
-     *
150
-     * @return string
151
-     */
152
-    private static function toSingularCamelCase(string $str): string
153
-    {
154
-        $tokens = preg_split("/[_ ]+/", $str);
155
-        $tokens = array_map([Inflector::class, 'singularize'], $tokens);
156
-
157
-        $str = '';
158
-        foreach ($tokens as $token) {
159
-            $str .= ucfirst(Inflector::singularize($token));
160
-        }
161
-
162
-        return $str;
163
-    }
164
-
165
-    /**
166
-     * Returns the class name for the DAO factory.
167
-     *
168
-     * @return string
169
-     */
170
-    public function getDaoFactoryClassName(): string
171
-    {
172
-        return 'DaoFactory';
173
-    }
10
+	private $beanPrefix = '';
11
+	private $beanSuffix = '';
12
+	private $baseBeanPrefix = 'Abstract';
13
+	private $baseBeanSuffix = '';
14
+	private $daoPrefix = '';
15
+	private $daoSuffix = 'Dao';
16
+	private $baseDaoPrefix = 'Abstract';
17
+	private $baseDaoSuffix = 'Dao';
18
+
19
+	/**
20
+	 * Sets the string prefix to any bean class name.
21
+	 *
22
+	 * @param string $beanPrefix
23
+	 */
24
+	public function setBeanPrefix(string $beanPrefix)
25
+	{
26
+		$this->beanPrefix = $beanPrefix;
27
+	}
28
+
29
+	/**
30
+	 * Sets the string suffix to any bean class name.
31
+	 *
32
+	 * @param string $beanSuffix
33
+	 */
34
+	public function setBeanSuffix(string $beanSuffix)
35
+	{
36
+		$this->beanSuffix = $beanSuffix;
37
+	}
38
+
39
+	/**
40
+	 * Sets the string prefix to any base bean class name.
41
+	 *
42
+	 * @param string $baseBeanPrefix
43
+	 */
44
+	public function setBaseBeanPrefix(string $baseBeanPrefix)
45
+	{
46
+		$this->baseBeanPrefix = $baseBeanPrefix;
47
+	}
48
+
49
+	/**
50
+	 * Sets the string suffix to any base bean class name.
51
+	 *
52
+	 * @param string $baseBeanSuffix
53
+	 */
54
+	public function setBaseBeanSuffix(string $baseBeanSuffix)
55
+	{
56
+		$this->baseBeanSuffix = $baseBeanSuffix;
57
+	}
58
+
59
+	/**
60
+	 * Sets the string prefix to any DAO class name.
61
+	 *
62
+	 * @param string $daoPrefix
63
+	 */
64
+	public function setDaoPrefix(string $daoPrefix)
65
+	{
66
+		$this->daoPrefix = $daoPrefix;
67
+	}
68
+
69
+	/**
70
+	 * Sets the string suffix to any DAO class name.
71
+	 *
72
+	 * @param string $daoSuffix
73
+	 */
74
+	public function setDaoSuffix(string $daoSuffix)
75
+	{
76
+		$this->daoSuffix = $daoSuffix;
77
+	}
78
+
79
+	/**
80
+	 * Sets the string prefix to any base DAO class name.
81
+	 *
82
+	 * @param string $baseDaoPrefix
83
+	 */
84
+	public function setBaseDaoPrefix(string $baseDaoPrefix)
85
+	{
86
+		$this->baseDaoPrefix = $baseDaoPrefix;
87
+	}
88
+
89
+	/**
90
+	 * Sets the string suffix to any base DAO class name.
91
+	 *
92
+	 * @param string $baseDaoSuffix
93
+	 */
94
+	public function setBaseDaoSuffix(string $baseDaoSuffix)
95
+	{
96
+		$this->baseDaoSuffix = $baseDaoSuffix;
97
+	}
98
+
99
+
100
+	/**
101
+	 * Returns the bean class name from the table name (excluding the namespace).
102
+	 *
103
+	 * @param string $tableName
104
+	 * @return string
105
+	 */
106
+	public function getBeanClassName(string $tableName): string
107
+	{
108
+		return $this->beanPrefix.self::toSingularCamelCase($tableName).$this->beanSuffix;
109
+	}
110
+
111
+	/**
112
+	 * Returns the base bean class name from the table name (excluding the namespace).
113
+	 *
114
+	 * @param string $tableName
115
+	 * @return string
116
+	 */
117
+	public function getBaseBeanClassName(string $tableName): string
118
+	{
119
+		return $this->baseBeanPrefix.self::toSingularCamelCase($tableName).$this->baseBeanSuffix;
120
+	}
121
+
122
+	/**
123
+	 * Returns the name of the DAO class from the table name (excluding the namespace).
124
+	 *
125
+	 * @param string $tableName
126
+	 * @return string
127
+	 */
128
+	public function getDaoClassName(string $tableName): string
129
+	{
130
+		return $this->daoPrefix.self::toSingularCamelCase($tableName).$this->daoSuffix;
131
+	}
132
+
133
+	/**
134
+	 * Returns the name of the base DAO class from the table name (excluding the namespace).
135
+	 *
136
+	 * @param string $tableName
137
+	 * @return string
138
+	 */
139
+	public function getBaseDaoClassName(string $tableName): string
140
+	{
141
+		return $this->baseDaoPrefix.self::toSingularCamelCase($tableName).$this->baseDaoSuffix;
142
+	}
143
+
144
+	/**
145
+	 * Tries to put string to the singular form (if it is plural) and camel case form.
146
+	 * We assume the table names are in english.
147
+	 *
148
+	 * @param $str string
149
+	 *
150
+	 * @return string
151
+	 */
152
+	private static function toSingularCamelCase(string $str): string
153
+	{
154
+		$tokens = preg_split("/[_ ]+/", $str);
155
+		$tokens = array_map([Inflector::class, 'singularize'], $tokens);
156
+
157
+		$str = '';
158
+		foreach ($tokens as $token) {
159
+			$str .= ucfirst(Inflector::singularize($token));
160
+		}
161
+
162
+		return $str;
163
+	}
164
+
165
+	/**
166
+	 * Returns the class name for the DAO factory.
167
+	 *
168
+	 * @return string
169
+	 */
170
+	public function getDaoFactoryClassName(): string
171
+	{
172
+		return 'DaoFactory';
173
+	}
174 174
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Commands/GenerateCommand.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -13,48 +13,48 @@
 block discarded – undo
13 13
 class GenerateCommand extends Command
14 14
 {
15 15
 
16
-    /**
17
-     * @var TDBMService
18
-     */
19
-    private $configuration;
16
+	/**
17
+	 * @var TDBMService
18
+	 */
19
+	private $configuration;
20 20
 
21
-    public function __construct(ConfigurationInterface $configuration)
22
-    {
23
-        parent::__construct();
24
-        $this->configuration = $configuration;
25
-    }
21
+	public function __construct(ConfigurationInterface $configuration)
22
+	{
23
+		parent::__construct();
24
+		$this->configuration = $configuration;
25
+	}
26 26
 
27
-    protected function configure()
28
-    {
29
-        $this->setName('tdbm:generate')
30
-            ->setDescription('Generates DAOs and beans.')
31
-            ->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.')
32
-        ;
33
-    }
27
+	protected function configure()
28
+	{
29
+		$this->setName('tdbm:generate')
30
+			->setDescription('Generates DAOs and beans.')
31
+			->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.')
32
+		;
33
+	}
34 34
 
35
-    protected function execute(InputInterface $input, OutputInterface $output)
36
-    {
37
-        // TODO: externalize composer.json file for autoloading (no more parameters for generateAllDaosAndBeans)
35
+	protected function execute(InputInterface $input, OutputInterface $output)
36
+	{
37
+		// TODO: externalize composer.json file for autoloading (no more parameters for generateAllDaosAndBeans)
38 38
 
39
-        $alteredConf = new AlteredConfiguration($this->configuration);
39
+		$alteredConf = new AlteredConfiguration($this->configuration);
40 40
 
41 41
 
42
-        $loggers = [ new ConsoleLogger($output) ];
42
+		$loggers = [ new ConsoleLogger($output) ];
43 43
 
44
-        $logger = $alteredConf->getLogger();
45
-        if ($logger) {
46
-            $loggers[] = $logger;
47
-        }
44
+		$logger = $alteredConf->getLogger();
45
+		if ($logger) {
46
+			$loggers[] = $logger;
47
+		}
48 48
 
49
-        $multiLogger = new MultiLogger($loggers);
49
+		$multiLogger = new MultiLogger($loggers);
50 50
 
51
-        $alteredConf->setLogger($multiLogger);
51
+		$alteredConf->setLogger($multiLogger);
52 52
 
53
-        $multiLogger->notice('Starting regenerating DAOs and beans');
53
+		$multiLogger->notice('Starting regenerating DAOs and beans');
54 54
 
55
-        $tdbmService = new TDBMService($this->configuration);
56
-        $tdbmService->generateAllDaosAndBeans();
55
+		$tdbmService = new TDBMService($this->configuration);
56
+		$tdbmService->generateAllDaosAndBeans();
57 57
 
58
-        $multiLogger->notice('Finished regenerating DAOs and beans');
59
-    }
58
+		$multiLogger->notice('Finished regenerating DAOs and beans');
59
+	}
60 60
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Controllers/TdbmInstallController.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -21,219 +21,219 @@
 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(dirname(__FILE__).'/../../../../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
-        $namingStrategy = InstallUtils::getOrCreateInstance('namingStrategy', DefaultNamingStrategy::class, $this->moufManager);
181
-        if ($migratingFrom42) {
182
-            // Let's setup the naming strategy for compatibility
183
-            $namingStrategy->getSetterProperty('setBeanPrefix')->setValue('');
184
-            $namingStrategy->getSetterProperty('setBeanSuffix')->setValue('Bean');
185
-            $namingStrategy->getSetterProperty('setBaseBeanPrefix')->setValue('');
186
-            $namingStrategy->getSetterProperty('setBaseBeanSuffix')->setValue('BaseBean');
187
-            $namingStrategy->getSetterProperty('setDaoPrefix')->setValue('');
188
-            $namingStrategy->getSetterProperty('setDaoSuffix')->setValue('Dao');
189
-            $namingStrategy->getSetterProperty('setBaseDaoPrefix')->setValue('');
190
-            $namingStrategy->getSetterProperty('setBaseDaoSuffix')->setValue('BaseDao');
191
-        }
192
-
193
-        if (!$this->moufManager->instanceExists('tdbmConfiguration')) {
194
-            $moufListener = InstallUtils::getOrCreateInstance(MoufDiListener::class, MoufDiListener::class, $this->moufManager);
195
-
196
-            $tdbmConfiguration = $this->moufManager->createInstance(MoufConfiguration::class)->setName('tdbmConfiguration');
197
-            $tdbmConfiguration->getConstructorArgumentProperty('connection')->setValue($this->moufManager->getInstanceDescriptor('dbalConnection'));
198
-            $tdbmConfiguration->getConstructorArgumentProperty('cache')->setValue($doctrineCache);
199
-            $tdbmConfiguration->getConstructorArgumentProperty('namingStrategy')->setValue($namingStrategy);
200
-            $tdbmConfiguration->getProperty('daoFactoryInstanceName')->setValue('daoFactory');
201
-            $tdbmConfiguration->getConstructorArgumentProperty('generatorListeners')->setValue([$moufListener]);
202
-
203
-            // Let's also delete the tdbmService if migrating versions <= 4.2
204
-            if ($migratingFrom42) {
205
-                $this->moufManager->removeComponent('tdbmService');
206
-            }
207
-        } else {
208
-            $tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
209
-        }
210
-
211
-        if (!$this->moufManager->instanceExists('tdbmService')) {
212
-            $tdbmService = $this->moufManager->createInstance('Mouf\\Database\\TDBM\\TDBMService')->setName('tdbmService');
213
-            $tdbmService->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
214
-        }
215
-
216
-        // We declare our instance of the Symfony command as a Mouf instance
217
-        $generateCommand = InstallUtils::getOrCreateInstance('generateCommand', GenerateCommand::class, $this->moufManager);
218
-        $generateCommand->getConstructorArgumentProperty('tdbmConfiguration')->setValue($tdbmConfiguration);
219
-
220
-        // We register that instance descriptor using "ConsoleUtils"
221
-        $consoleUtils = new ConsoleUtils($this->moufManager);
222
-        $consoleUtils->registerCommand($generateCommand);
223
-
224
-        $this->moufManager->rewriteMouf();
225
-
226
-        TdbmController::generateDaos($this->moufManager, 'tdbmService', $daonamespace, $beannamespace, 'daoFactory', $selfedit, /*$storeInUtc,*/ $defaultPath, $storePath);
227
-
228
-        InstallUtils::continueInstall($selfedit == 'true');
229
-    }
230
-
231
-    protected $errorMsg;
232
-
233
-    private function displayErrorMsg($msg)
234
-    {
235
-        $this->errorMsg = $msg;
236
-        $this->content->addFile(__DIR__.'/../../../../views/installError.php', $this);
237
-        $this->template->toHtml();
238
-    }
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(dirname(__FILE__).'/../../../../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
+		$namingStrategy = InstallUtils::getOrCreateInstance('namingStrategy', DefaultNamingStrategy::class, $this->moufManager);
181
+		if ($migratingFrom42) {
182
+			// Let's setup the naming strategy for compatibility
183
+			$namingStrategy->getSetterProperty('setBeanPrefix')->setValue('');
184
+			$namingStrategy->getSetterProperty('setBeanSuffix')->setValue('Bean');
185
+			$namingStrategy->getSetterProperty('setBaseBeanPrefix')->setValue('');
186
+			$namingStrategy->getSetterProperty('setBaseBeanSuffix')->setValue('BaseBean');
187
+			$namingStrategy->getSetterProperty('setDaoPrefix')->setValue('');
188
+			$namingStrategy->getSetterProperty('setDaoSuffix')->setValue('Dao');
189
+			$namingStrategy->getSetterProperty('setBaseDaoPrefix')->setValue('');
190
+			$namingStrategy->getSetterProperty('setBaseDaoSuffix')->setValue('BaseDao');
191
+		}
192
+
193
+		if (!$this->moufManager->instanceExists('tdbmConfiguration')) {
194
+			$moufListener = InstallUtils::getOrCreateInstance(MoufDiListener::class, MoufDiListener::class, $this->moufManager);
195
+
196
+			$tdbmConfiguration = $this->moufManager->createInstance(MoufConfiguration::class)->setName('tdbmConfiguration');
197
+			$tdbmConfiguration->getConstructorArgumentProperty('connection')->setValue($this->moufManager->getInstanceDescriptor('dbalConnection'));
198
+			$tdbmConfiguration->getConstructorArgumentProperty('cache')->setValue($doctrineCache);
199
+			$tdbmConfiguration->getConstructorArgumentProperty('namingStrategy')->setValue($namingStrategy);
200
+			$tdbmConfiguration->getProperty('daoFactoryInstanceName')->setValue('daoFactory');
201
+			$tdbmConfiguration->getConstructorArgumentProperty('generatorListeners')->setValue([$moufListener]);
202
+
203
+			// Let's also delete the tdbmService if migrating versions <= 4.2
204
+			if ($migratingFrom42) {
205
+				$this->moufManager->removeComponent('tdbmService');
206
+			}
207
+		} else {
208
+			$tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration');
209
+		}
210
+
211
+		if (!$this->moufManager->instanceExists('tdbmService')) {
212
+			$tdbmService = $this->moufManager->createInstance('Mouf\\Database\\TDBM\\TDBMService')->setName('tdbmService');
213
+			$tdbmService->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration);
214
+		}
215
+
216
+		// We declare our instance of the Symfony command as a Mouf instance
217
+		$generateCommand = InstallUtils::getOrCreateInstance('generateCommand', GenerateCommand::class, $this->moufManager);
218
+		$generateCommand->getConstructorArgumentProperty('tdbmConfiguration')->setValue($tdbmConfiguration);
219
+
220
+		// We register that instance descriptor using "ConsoleUtils"
221
+		$consoleUtils = new ConsoleUtils($this->moufManager);
222
+		$consoleUtils->registerCommand($generateCommand);
223
+
224
+		$this->moufManager->rewriteMouf();
225
+
226
+		TdbmController::generateDaos($this->moufManager, 'tdbmService', $daonamespace, $beannamespace, 'daoFactory', $selfedit, /*$storeInUtc,*/ $defaultPath, $storePath);
227
+
228
+		InstallUtils::continueInstall($selfedit == 'true');
229
+	}
230
+
231
+	protected $errorMsg;
232
+
233
+	private function displayErrorMsg($msg)
234
+	{
235
+		$this->errorMsg = $msg;
236
+		$this->content->addFile(__DIR__.'/../../../../views/installError.php', $this);
237
+		$this->template->toHtml();
238
+	}
239 239
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Configuration.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -15,166 +15,166 @@
 block discarded – undo
15 15
 class Configuration implements ConfigurationInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @var string
20
-     */
21
-    private $beanNamespace;
22
-    /**
23
-     * @var string
24
-     */
25
-    private $daoNamespace;
26
-    /**
27
-     * @var Connection
28
-     */
29
-    private $connection;
30
-    /**
31
-     * @var Cache
32
-     */
33
-    private $cache;
34
-    /**
35
-     * @var SchemaAnalyzer
36
-     */
37
-    private $schemaAnalyzer;
38
-    /**
39
-     * @var LoggerInterface
40
-     */
41
-    private $logger;
42
-    /**
43
-     * @var GeneratorListenerInterface
44
-     */
45
-    private $generatorEventDispatcher;
46
-    /**
47
-     * @var NamingStrategyInterface
48
-     */
49
-    private $namingStrategy;
50
-    /**
51
-     * The Composer file used to detect the path where files should be written.
52
-     *
53
-     * @var string
54
-     */
55
-    private $composerFile;
56
-
57
-    /**
58
-     * @param string $beanNamespace The namespace hosting the beans
59
-     * @param string $daoNamespace The namespace hosting the DAOs
60
-     * @param Connection $connection The connection to the database
61
-     * @param Cache|null $cache The Doctrine cache to store database metadata
62
-     * @param SchemaAnalyzer|null $schemaAnalyzer The schema analyzer that will be used to find shortest paths... Will be automatically created if not passed
63
-     * @param LoggerInterface|null $logger The logger
64
-     * @param GeneratorListenerInterface[] $generatorListeners A list of listeners that will be triggered when beans/daos are generated
65
-     */
66
-    public function __construct(string $beanNamespace, string $daoNamespace, Connection $connection, NamingStrategyInterface $namingStrategy, Cache $cache = null, SchemaAnalyzer $schemaAnalyzer = null, LoggerInterface $logger = null, array $generatorListeners = [])
67
-    {
68
-        $this->beanNamespace = rtrim($beanNamespace, '\\');
69
-        $this->daoNamespace = rtrim($daoNamespace, '\\');
70
-        $this->connection = $connection;
71
-        $this->namingStrategy = $namingStrategy;
72
-        if ($cache !== null) {
73
-            $this->cache = $cache;
74
-        } else {
75
-            $this->cache = new VoidCache();
76
-        }
77
-        if ($schemaAnalyzer !== null) {
78
-            $this->schemaAnalyzer = $schemaAnalyzer;
79
-        } else {
80
-            $this->schemaAnalyzer = new SchemaAnalyzer($this->connection->getSchemaManager(), $this->cache, $this->getConnectionUniqueId());
81
-        }
82
-        $this->logger = $logger;
83
-        $this->generatorEventDispatcher = new GeneratorEventDispatcher($generatorListeners);
84
-        $this->composerFile = 'composer.json';
85
-    }
86
-
87
-    /**
88
-     * @return string
89
-     */
90
-    public function getBeanNamespace(): string
91
-    {
92
-        return $this->beanNamespace;
93
-    }
94
-
95
-    /**
96
-     * @return string
97
-     */
98
-    public function getDaoNamespace(): string
99
-    {
100
-        return $this->daoNamespace;
101
-    }
102
-
103
-    /**
104
-     * @return Connection
105
-     */
106
-    public function getConnection(): Connection
107
-    {
108
-        return $this->connection;
109
-    }
110
-
111
-    /**
112
-     * @return NamingStrategyInterface
113
-     */
114
-    public function getNamingStrategy(): NamingStrategyInterface
115
-    {
116
-        return $this->namingStrategy;
117
-    }
118
-
119
-    /**
120
-     * @return Cache
121
-     */
122
-    public function getCache(): Cache
123
-    {
124
-        return $this->cache;
125
-    }
126
-
127
-    /**
128
-     * @return SchemaAnalyzer
129
-     */
130
-    public function getSchemaAnalyzer(): SchemaAnalyzer
131
-    {
132
-        return $this->schemaAnalyzer;
133
-    }
134
-
135
-    /**
136
-     * @return LoggerInterface
137
-     */
138
-    public function getLogger(): ?LoggerInterface
139
-    {
140
-        return $this->logger;
141
-    }
142
-
143
-    /**
144
-     * @return GeneratorListenerInterface
145
-     */
146
-    public function getGeneratorEventDispatcher(): GeneratorListenerInterface
147
-    {
148
-        return $this->generatorEventDispatcher;
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * Creates a unique cache key for the current connection.
155
-     *
156
-     * @return string
157
-     */
158
-    private function getConnectionUniqueId(): string
159
-    {
160
-        return hash('md4', $this->connection->getHost().'-'.$this->connection->getPort().'-'.$this->connection->getDatabase().'-'.$this->connection->getDriver()->getName());
161
-    }
162
-
163
-    /**
164
-     * @return null|string
165
-     */
166
-    public function getComposerFile() : string
167
-    {
168
-        return $this->composerFile;
169
-    }
170
-
171
-    /**
172
-     * Sets the Composer file used to detect the path where files should be written.
173
-     *
174
-     * @param null|string $composerFile
175
-     */
176
-    public function setComposerFile(string $composerFile)
177
-    {
178
-        $this->composerFile = $composerFile;
179
-    }
18
+	/**
19
+	 * @var string
20
+	 */
21
+	private $beanNamespace;
22
+	/**
23
+	 * @var string
24
+	 */
25
+	private $daoNamespace;
26
+	/**
27
+	 * @var Connection
28
+	 */
29
+	private $connection;
30
+	/**
31
+	 * @var Cache
32
+	 */
33
+	private $cache;
34
+	/**
35
+	 * @var SchemaAnalyzer
36
+	 */
37
+	private $schemaAnalyzer;
38
+	/**
39
+	 * @var LoggerInterface
40
+	 */
41
+	private $logger;
42
+	/**
43
+	 * @var GeneratorListenerInterface
44
+	 */
45
+	private $generatorEventDispatcher;
46
+	/**
47
+	 * @var NamingStrategyInterface
48
+	 */
49
+	private $namingStrategy;
50
+	/**
51
+	 * The Composer file used to detect the path where files should be written.
52
+	 *
53
+	 * @var string
54
+	 */
55
+	private $composerFile;
56
+
57
+	/**
58
+	 * @param string $beanNamespace The namespace hosting the beans
59
+	 * @param string $daoNamespace The namespace hosting the DAOs
60
+	 * @param Connection $connection The connection to the database
61
+	 * @param Cache|null $cache The Doctrine cache to store database metadata
62
+	 * @param SchemaAnalyzer|null $schemaAnalyzer The schema analyzer that will be used to find shortest paths... Will be automatically created if not passed
63
+	 * @param LoggerInterface|null $logger The logger
64
+	 * @param GeneratorListenerInterface[] $generatorListeners A list of listeners that will be triggered when beans/daos are generated
65
+	 */
66
+	public function __construct(string $beanNamespace, string $daoNamespace, Connection $connection, NamingStrategyInterface $namingStrategy, Cache $cache = null, SchemaAnalyzer $schemaAnalyzer = null, LoggerInterface $logger = null, array $generatorListeners = [])
67
+	{
68
+		$this->beanNamespace = rtrim($beanNamespace, '\\');
69
+		$this->daoNamespace = rtrim($daoNamespace, '\\');
70
+		$this->connection = $connection;
71
+		$this->namingStrategy = $namingStrategy;
72
+		if ($cache !== null) {
73
+			$this->cache = $cache;
74
+		} else {
75
+			$this->cache = new VoidCache();
76
+		}
77
+		if ($schemaAnalyzer !== null) {
78
+			$this->schemaAnalyzer = $schemaAnalyzer;
79
+		} else {
80
+			$this->schemaAnalyzer = new SchemaAnalyzer($this->connection->getSchemaManager(), $this->cache, $this->getConnectionUniqueId());
81
+		}
82
+		$this->logger = $logger;
83
+		$this->generatorEventDispatcher = new GeneratorEventDispatcher($generatorListeners);
84
+		$this->composerFile = 'composer.json';
85
+	}
86
+
87
+	/**
88
+	 * @return string
89
+	 */
90
+	public function getBeanNamespace(): string
91
+	{
92
+		return $this->beanNamespace;
93
+	}
94
+
95
+	/**
96
+	 * @return string
97
+	 */
98
+	public function getDaoNamespace(): string
99
+	{
100
+		return $this->daoNamespace;
101
+	}
102
+
103
+	/**
104
+	 * @return Connection
105
+	 */
106
+	public function getConnection(): Connection
107
+	{
108
+		return $this->connection;
109
+	}
110
+
111
+	/**
112
+	 * @return NamingStrategyInterface
113
+	 */
114
+	public function getNamingStrategy(): NamingStrategyInterface
115
+	{
116
+		return $this->namingStrategy;
117
+	}
118
+
119
+	/**
120
+	 * @return Cache
121
+	 */
122
+	public function getCache(): Cache
123
+	{
124
+		return $this->cache;
125
+	}
126
+
127
+	/**
128
+	 * @return SchemaAnalyzer
129
+	 */
130
+	public function getSchemaAnalyzer(): SchemaAnalyzer
131
+	{
132
+		return $this->schemaAnalyzer;
133
+	}
134
+
135
+	/**
136
+	 * @return LoggerInterface
137
+	 */
138
+	public function getLogger(): ?LoggerInterface
139
+	{
140
+		return $this->logger;
141
+	}
142
+
143
+	/**
144
+	 * @return GeneratorListenerInterface
145
+	 */
146
+	public function getGeneratorEventDispatcher(): GeneratorListenerInterface
147
+	{
148
+		return $this->generatorEventDispatcher;
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * Creates a unique cache key for the current connection.
155
+	 *
156
+	 * @return string
157
+	 */
158
+	private function getConnectionUniqueId(): string
159
+	{
160
+		return hash('md4', $this->connection->getHost().'-'.$this->connection->getPort().'-'.$this->connection->getDatabase().'-'.$this->connection->getDriver()->getName());
161
+	}
162
+
163
+	/**
164
+	 * @return null|string
165
+	 */
166
+	public function getComposerFile() : string
167
+	{
168
+		return $this->composerFile;
169
+	}
170
+
171
+	/**
172
+	 * Sets the Composer file used to detect the path where files should be written.
173
+	 *
174
+	 * @param null|string $composerFile
175
+	 */
176
+	public function setComposerFile(string $composerFile)
177
+	{
178
+		$this->composerFile = $composerFile;
179
+	}
180 180
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Commands/AlteredConfiguration.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -19,103 +19,103 @@
 block discarded – undo
19 19
  */
20 20
 class AlteredConfiguration implements ConfigurationInterface
21 21
 {
22
-    /**
23
-     * @var ConfigurationInterface
24
-     */
25
-    private $configuration;
26
-
27
-    /**
28
-     * @var LoggerInterface
29
-     */
30
-    private $logger;
31
-
32
-    public function __construct(ConfigurationInterface $configuration)
33
-    {
34
-        $this->configuration = $configuration;
35
-        $this->logger = $configuration->getLogger();
36
-    }
37
-
38
-
39
-    /**
40
-     * @return string
41
-     */
42
-    public function getBeanNamespace(): string
43
-    {
44
-        return $this->configuration->getBeanNamespace();
45
-    }
46
-
47
-    /**
48
-     * @return string
49
-     */
50
-    public function getDaoNamespace(): string
51
-    {
52
-        return $this->configuration->getDaoNamespace();
53
-    }
54
-
55
-    /**
56
-     * @return Connection
57
-     */
58
-    public function getConnection(): Connection
59
-    {
60
-        return $this->configuration->getConnection();
61
-    }
62
-
63
-    /**
64
-     * @return Cache
65
-     */
66
-    public function getCache(): Cache
67
-    {
68
-        return $this->configuration->getCache();
69
-    }
70
-
71
-    /**
72
-     * @return NamingStrategyInterface
73
-     */
74
-    public function getNamingStrategy(): NamingStrategyInterface
75
-    {
76
-        return $this->configuration->getNamingStrategy();
77
-    }
78
-
79
-    /**
80
-     * @return SchemaAnalyzer
81
-     */
82
-    public function getSchemaAnalyzer(): SchemaAnalyzer
83
-    {
84
-        return $this->configuration->getSchemaAnalyzer();
85
-    }
86
-
87
-    /**
88
-     * @return LoggerInterface
89
-     */
90
-    public function getLogger(): ?LoggerInterface
91
-    {
92
-        return $this->configuration->getLogger();
93
-    }
94
-
95
-    /**
96
-     * @return GeneratorListenerInterface
97
-     */
98
-    public function getGeneratorEventDispatcher(): GeneratorListenerInterface
99
-    {
100
-        return $this->configuration->getGeneratorEventDispatcher();
101
-    }
102
-
103
-    /**
104
-     * @param LoggerInterface $logger
105
-     */
106
-    public function setLogger(LoggerInterface $logger)
107
-    {
108
-        $this->logger = $logger;
109
-    }
110
-
111
-    /**
112
-     * Get the Composer file used to detect the path where files should be written.
113
-     * Path is relative to the root directory (this function will typically return 'composer.json' unless you want to write the beans and DAOs in a package).
114
-     *
115
-     * @return null|string
116
-     */
117
-    public function getComposerFile(): string
118
-    {
119
-        return $this->configuration->getComposerFile();
120
-    }
22
+	/**
23
+	 * @var ConfigurationInterface
24
+	 */
25
+	private $configuration;
26
+
27
+	/**
28
+	 * @var LoggerInterface
29
+	 */
30
+	private $logger;
31
+
32
+	public function __construct(ConfigurationInterface $configuration)
33
+	{
34
+		$this->configuration = $configuration;
35
+		$this->logger = $configuration->getLogger();
36
+	}
37
+
38
+
39
+	/**
40
+	 * @return string
41
+	 */
42
+	public function getBeanNamespace(): string
43
+	{
44
+		return $this->configuration->getBeanNamespace();
45
+	}
46
+
47
+	/**
48
+	 * @return string
49
+	 */
50
+	public function getDaoNamespace(): string
51
+	{
52
+		return $this->configuration->getDaoNamespace();
53
+	}
54
+
55
+	/**
56
+	 * @return Connection
57
+	 */
58
+	public function getConnection(): Connection
59
+	{
60
+		return $this->configuration->getConnection();
61
+	}
62
+
63
+	/**
64
+	 * @return Cache
65
+	 */
66
+	public function getCache(): Cache
67
+	{
68
+		return $this->configuration->getCache();
69
+	}
70
+
71
+	/**
72
+	 * @return NamingStrategyInterface
73
+	 */
74
+	public function getNamingStrategy(): NamingStrategyInterface
75
+	{
76
+		return $this->configuration->getNamingStrategy();
77
+	}
78
+
79
+	/**
80
+	 * @return SchemaAnalyzer
81
+	 */
82
+	public function getSchemaAnalyzer(): SchemaAnalyzer
83
+	{
84
+		return $this->configuration->getSchemaAnalyzer();
85
+	}
86
+
87
+	/**
88
+	 * @return LoggerInterface
89
+	 */
90
+	public function getLogger(): ?LoggerInterface
91
+	{
92
+		return $this->configuration->getLogger();
93
+	}
94
+
95
+	/**
96
+	 * @return GeneratorListenerInterface
97
+	 */
98
+	public function getGeneratorEventDispatcher(): GeneratorListenerInterface
99
+	{
100
+		return $this->configuration->getGeneratorEventDispatcher();
101
+	}
102
+
103
+	/**
104
+	 * @param LoggerInterface $logger
105
+	 */
106
+	public function setLogger(LoggerInterface $logger)
107
+	{
108
+		$this->logger = $logger;
109
+	}
110
+
111
+	/**
112
+	 * Get the Composer file used to detect the path where files should be written.
113
+	 * Path is relative to the root directory (this function will typically return 'composer.json' unless you want to write the beans and DAOs in a package).
114
+	 *
115
+	 * @return null|string
116
+	 */
117
+	public function getComposerFile(): string
118
+	{
119
+		return $this->configuration->getComposerFile();
120
+	}
121 121
 }
122 122
\ No newline at end of file
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/ConfigurationInterface.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -11,51 +11,51 @@
 block discarded – undo
11 11
 
12 12
 interface ConfigurationInterface
13 13
 {
14
-    /**
15
-     * @return string
16
-     */
17
-    public function getBeanNamespace(): string;
18
-
19
-    /**
20
-     * @return string
21
-     */
22
-    public function getDaoNamespace(): string;
23
-
24
-    /**
25
-     * @return Connection
26
-     */
27
-    public function getConnection(): Connection;
28
-
29
-    /**
30
-     * @return Cache
31
-     */
32
-    public function getCache(): Cache;
33
-
34
-    /**
35
-     * @return NamingStrategyInterface
36
-     */
37
-    public function getNamingStrategy(): NamingStrategyInterface;
38
-
39
-    /**
40
-     * @return SchemaAnalyzer
41
-     */
42
-    public function getSchemaAnalyzer(): SchemaAnalyzer;
43
-
44
-    /**
45
-     * @return LoggerInterface
46
-     */
47
-    public function getLogger(): ?LoggerInterface;
48
-
49
-    /**
50
-     * @return GeneratorListenerInterface
51
-     */
52
-    public function getGeneratorEventDispatcher(): GeneratorListenerInterface;
53
-
54
-    /**
55
-     * Get the Composer file used to detect the path where files should be written.
56
-     * Path is relative to the root directory (this function will typically return 'composer.json' unless you want to write the beans and DAOs in a package).
57
-     *
58
-     * @return null|string
59
-     */
60
-    public function getComposerFile() : string;
14
+	/**
15
+	 * @return string
16
+	 */
17
+	public function getBeanNamespace(): string;
18
+
19
+	/**
20
+	 * @return string
21
+	 */
22
+	public function getDaoNamespace(): string;
23
+
24
+	/**
25
+	 * @return Connection
26
+	 */
27
+	public function getConnection(): Connection;
28
+
29
+	/**
30
+	 * @return Cache
31
+	 */
32
+	public function getCache(): Cache;
33
+
34
+	/**
35
+	 * @return NamingStrategyInterface
36
+	 */
37
+	public function getNamingStrategy(): NamingStrategyInterface;
38
+
39
+	/**
40
+	 * @return SchemaAnalyzer
41
+	 */
42
+	public function getSchemaAnalyzer(): SchemaAnalyzer;
43
+
44
+	/**
45
+	 * @return LoggerInterface
46
+	 */
47
+	public function getLogger(): ?LoggerInterface;
48
+
49
+	/**
50
+	 * @return GeneratorListenerInterface
51
+	 */
52
+	public function getGeneratorEventDispatcher(): GeneratorListenerInterface;
53
+
54
+	/**
55
+	 * Get the Composer file used to detect the path where files should be written.
56
+	 * Path is relative to the root directory (this function will typically return 'composer.json' unless you want to write the beans and DAOs in a package).
57
+	 *
58
+	 * @return null|string
59
+	 */
60
+	public function getComposerFile() : string;
61 61
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Utils/TDBMDaoGenerator.php 1 patch
Indentation   +416 added lines, -416 removed lines patch added patch discarded remove patch
@@ -19,157 +19,157 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class TDBMDaoGenerator
21 21
 {
22
-    /**
23
-     * @var Schema
24
-     */
25
-    private $schema;
26
-
27
-    /**
28
-     * The root directory of the project.
29
-     *
30
-     * @var string
31
-     */
32
-    private $rootPath;
33
-
34
-    /**
35
-     * Name of composer file.
36
-     *
37
-     * @var string
38
-     */
39
-    private $composerFile;
40
-
41
-    /**
42
-     * @var TDBMSchemaAnalyzer
43
-     */
44
-    private $tdbmSchemaAnalyzer;
45
-
46
-    /**
47
-     * @var EventDispatcherInterface
48
-     */
49
-    private $eventDispatcher;
50
-
51
-    /**
52
-     * @var NamingStrategyInterface
53
-     */
54
-    private $namingStrategy;
55
-    /**
56
-     * @var ConfigurationInterface
57
-     */
58
-    private $configuration;
59
-
60
-    /**
61
-     * Constructor.
62
-     *
63
-     * @param ConfigurationInterface $configuration
64
-     * @param Schema $schema
65
-     * @param TDBMSchemaAnalyzer $tdbmSchemaAnalyzer
66
-     */
67
-    public function __construct(ConfigurationInterface $configuration, Schema $schema, TDBMSchemaAnalyzer $tdbmSchemaAnalyzer)
68
-    {
69
-        $this->configuration = $configuration;
70
-        $this->schema = $schema;
71
-        $this->tdbmSchemaAnalyzer = $tdbmSchemaAnalyzer;
72
-        $this->rootPath = __DIR__.'/../../../../../../../../';
73
-        $this->composerFile = $configuration->getComposerFile();
74
-        $this->namingStrategy = $configuration->getNamingStrategy();
75
-        $this->eventDispatcher = $configuration->getGeneratorEventDispatcher();
76
-    }
77
-
78
-    /**
79
-     * Generates all the daos and beans.
80
-     *
81
-     * @throws TDBMException
82
-     */
83
-    public function generateAllDaosAndBeans(): void
84
-    {
85
-        $classNameMapper = ClassNameMapper::createFromComposerFile($this->rootPath.$this->composerFile);
86
-        // TODO: check that no class name ends with "Base". Otherwise, there will be name clash.
87
-
88
-        $tableList = $this->schema->getTables();
89
-
90
-        // Remove all beans and daos from junction tables
91
-        $junctionTables = $this->configuration->getSchemaAnalyzer()->detectJunctionTables(true);
92
-        $junctionTableNames = array_map(function (Table $table) {
93
-            return $table->getName();
94
-        }, $junctionTables);
95
-
96
-        $tableList = array_filter($tableList, function (Table $table) use ($junctionTableNames) {
97
-            return !in_array($table->getName(), $junctionTableNames);
98
-        });
99
-
100
-        $beanDescriptors = [];
101
-
102
-        foreach ($tableList as $table) {
103
-            $beanDescriptors[] = $this->generateDaoAndBean($table, $classNameMapper);
104
-        }
105
-
106
-
107
-        $this->generateFactory($tableList, $classNameMapper);
108
-
109
-        // Let's call the list of listeners
110
-        $this->eventDispatcher->onGenerate($this->configuration, $beanDescriptors);
111
-    }
112
-
113
-    /**
114
-     * Generates in one method call the daos and the beans for one table.
115
-     *
116
-     * @param Table $table
117
-     * @param ClassNameMapper $classNameMapper
118
-     *
119
-     * @return BeanDescriptor
120
-     * @throws TDBMException
121
-     */
122
-    private function generateDaoAndBean(Table $table, ClassNameMapper $classNameMapper) : BeanDescriptor
123
-    {
124
-        // TODO: $storeInUtc is NOT USED.
125
-        $tableName = $table->getName();
126
-        $daoName = $this->namingStrategy->getDaoClassName($tableName);
127
-        $beanName = $this->namingStrategy->getBeanClassName($tableName);
128
-        $baseBeanName = $this->namingStrategy->getBaseBeanClassName($tableName);
129
-        $baseDaoName = $this->namingStrategy->getBaseDaoClassName($tableName);
130
-
131
-        $beanDescriptor = new BeanDescriptor($table, $this->configuration->getSchemaAnalyzer(), $this->schema, $this->tdbmSchemaAnalyzer, $this->namingStrategy);
132
-        $this->generateBean($beanDescriptor, $beanName, $baseBeanName, $table, $classNameMapper);
133
-        $this->generateDao($beanDescriptor, $daoName, $baseDaoName, $beanName, $table, $classNameMapper);
134
-        return $beanDescriptor;
135
-    }
136
-
137
-    /**
138
-     * Writes the PHP bean file with all getters and setters from the table passed in parameter.
139
-     *
140
-     * @param BeanDescriptor  $beanDescriptor
141
-     * @param string          $className       The name of the class
142
-     * @param string          $baseClassName   The name of the base class which will be extended (name only, no directory)
143
-     * @param Table           $table           The table
144
-     * @param ClassNameMapper $classNameMapper
145
-     *
146
-     * @throws TDBMException
147
-     */
148
-    public function generateBean(BeanDescriptor $beanDescriptor, $className, $baseClassName, Table $table, ClassNameMapper $classNameMapper)
149
-    {
150
-        $beannamespace = $this->configuration->getBeanNamespace();
151
-        $str = $beanDescriptor->generatePhpCode($beannamespace);
152
-
153
-        $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($beannamespace.'\\Generated\\'.$baseClassName);
154
-        if (empty($possibleBaseFileNames)) {
155
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace.'\\'.$baseClassName.'" is not autoloadable.');
156
-        }
157
-        $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0];
158
-
159
-        $this->ensureDirectoryExist($possibleBaseFileName);
160
-        file_put_contents($possibleBaseFileName, $str);
161
-        @chmod($possibleBaseFileName, 0664);
162
-
163
-        $possibleFileNames = $classNameMapper->getPossibleFileNames($beannamespace.'\\'.$className);
164
-        if (empty($possibleFileNames)) {
165
-            // @codeCoverageIgnoreStart
166
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace.'\\'.$className.'" is not autoloadable.');
167
-            // @codeCoverageIgnoreEnd
168
-        }
169
-        $possibleFileName = $this->rootPath.$possibleFileNames[0];
170
-        if (!file_exists($possibleFileName)) {
171
-            $tableName = $table->getName();
172
-            $str = "<?php
22
+	/**
23
+	 * @var Schema
24
+	 */
25
+	private $schema;
26
+
27
+	/**
28
+	 * The root directory of the project.
29
+	 *
30
+	 * @var string
31
+	 */
32
+	private $rootPath;
33
+
34
+	/**
35
+	 * Name of composer file.
36
+	 *
37
+	 * @var string
38
+	 */
39
+	private $composerFile;
40
+
41
+	/**
42
+	 * @var TDBMSchemaAnalyzer
43
+	 */
44
+	private $tdbmSchemaAnalyzer;
45
+
46
+	/**
47
+	 * @var EventDispatcherInterface
48
+	 */
49
+	private $eventDispatcher;
50
+
51
+	/**
52
+	 * @var NamingStrategyInterface
53
+	 */
54
+	private $namingStrategy;
55
+	/**
56
+	 * @var ConfigurationInterface
57
+	 */
58
+	private $configuration;
59
+
60
+	/**
61
+	 * Constructor.
62
+	 *
63
+	 * @param ConfigurationInterface $configuration
64
+	 * @param Schema $schema
65
+	 * @param TDBMSchemaAnalyzer $tdbmSchemaAnalyzer
66
+	 */
67
+	public function __construct(ConfigurationInterface $configuration, Schema $schema, TDBMSchemaAnalyzer $tdbmSchemaAnalyzer)
68
+	{
69
+		$this->configuration = $configuration;
70
+		$this->schema = $schema;
71
+		$this->tdbmSchemaAnalyzer = $tdbmSchemaAnalyzer;
72
+		$this->rootPath = __DIR__.'/../../../../../../../../';
73
+		$this->composerFile = $configuration->getComposerFile();
74
+		$this->namingStrategy = $configuration->getNamingStrategy();
75
+		$this->eventDispatcher = $configuration->getGeneratorEventDispatcher();
76
+	}
77
+
78
+	/**
79
+	 * Generates all the daos and beans.
80
+	 *
81
+	 * @throws TDBMException
82
+	 */
83
+	public function generateAllDaosAndBeans(): void
84
+	{
85
+		$classNameMapper = ClassNameMapper::createFromComposerFile($this->rootPath.$this->composerFile);
86
+		// TODO: check that no class name ends with "Base". Otherwise, there will be name clash.
87
+
88
+		$tableList = $this->schema->getTables();
89
+
90
+		// Remove all beans and daos from junction tables
91
+		$junctionTables = $this->configuration->getSchemaAnalyzer()->detectJunctionTables(true);
92
+		$junctionTableNames = array_map(function (Table $table) {
93
+			return $table->getName();
94
+		}, $junctionTables);
95
+
96
+		$tableList = array_filter($tableList, function (Table $table) use ($junctionTableNames) {
97
+			return !in_array($table->getName(), $junctionTableNames);
98
+		});
99
+
100
+		$beanDescriptors = [];
101
+
102
+		foreach ($tableList as $table) {
103
+			$beanDescriptors[] = $this->generateDaoAndBean($table, $classNameMapper);
104
+		}
105
+
106
+
107
+		$this->generateFactory($tableList, $classNameMapper);
108
+
109
+		// Let's call the list of listeners
110
+		$this->eventDispatcher->onGenerate($this->configuration, $beanDescriptors);
111
+	}
112
+
113
+	/**
114
+	 * Generates in one method call the daos and the beans for one table.
115
+	 *
116
+	 * @param Table $table
117
+	 * @param ClassNameMapper $classNameMapper
118
+	 *
119
+	 * @return BeanDescriptor
120
+	 * @throws TDBMException
121
+	 */
122
+	private function generateDaoAndBean(Table $table, ClassNameMapper $classNameMapper) : BeanDescriptor
123
+	{
124
+		// TODO: $storeInUtc is NOT USED.
125
+		$tableName = $table->getName();
126
+		$daoName = $this->namingStrategy->getDaoClassName($tableName);
127
+		$beanName = $this->namingStrategy->getBeanClassName($tableName);
128
+		$baseBeanName = $this->namingStrategy->getBaseBeanClassName($tableName);
129
+		$baseDaoName = $this->namingStrategy->getBaseDaoClassName($tableName);
130
+
131
+		$beanDescriptor = new BeanDescriptor($table, $this->configuration->getSchemaAnalyzer(), $this->schema, $this->tdbmSchemaAnalyzer, $this->namingStrategy);
132
+		$this->generateBean($beanDescriptor, $beanName, $baseBeanName, $table, $classNameMapper);
133
+		$this->generateDao($beanDescriptor, $daoName, $baseDaoName, $beanName, $table, $classNameMapper);
134
+		return $beanDescriptor;
135
+	}
136
+
137
+	/**
138
+	 * Writes the PHP bean file with all getters and setters from the table passed in parameter.
139
+	 *
140
+	 * @param BeanDescriptor  $beanDescriptor
141
+	 * @param string          $className       The name of the class
142
+	 * @param string          $baseClassName   The name of the base class which will be extended (name only, no directory)
143
+	 * @param Table           $table           The table
144
+	 * @param ClassNameMapper $classNameMapper
145
+	 *
146
+	 * @throws TDBMException
147
+	 */
148
+	public function generateBean(BeanDescriptor $beanDescriptor, $className, $baseClassName, Table $table, ClassNameMapper $classNameMapper)
149
+	{
150
+		$beannamespace = $this->configuration->getBeanNamespace();
151
+		$str = $beanDescriptor->generatePhpCode($beannamespace);
152
+
153
+		$possibleBaseFileNames = $classNameMapper->getPossibleFileNames($beannamespace.'\\Generated\\'.$baseClassName);
154
+		if (empty($possibleBaseFileNames)) {
155
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace.'\\'.$baseClassName.'" is not autoloadable.');
156
+		}
157
+		$possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0];
158
+
159
+		$this->ensureDirectoryExist($possibleBaseFileName);
160
+		file_put_contents($possibleBaseFileName, $str);
161
+		@chmod($possibleBaseFileName, 0664);
162
+
163
+		$possibleFileNames = $classNameMapper->getPossibleFileNames($beannamespace.'\\'.$className);
164
+		if (empty($possibleFileNames)) {
165
+			// @codeCoverageIgnoreStart
166
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace.'\\'.$className.'" is not autoloadable.');
167
+			// @codeCoverageIgnoreEnd
168
+		}
169
+		$possibleFileName = $this->rootPath.$possibleFileNames[0];
170
+		if (!file_exists($possibleFileName)) {
171
+			$tableName = $table->getName();
172
+			$str = "<?php
173 173
 /*
174 174
  * This file has been automatically generated by TDBM.
175 175
  * You can edit this file as it will not be overwritten.
@@ -186,76 +186,76 @@  discard block
 block discarded – undo
186 186
 {
187 187
 }
188 188
 ";
189
-            $this->ensureDirectoryExist($possibleFileName);
190
-            file_put_contents($possibleFileName, $str);
191
-            @chmod($possibleFileName, 0664);
192
-        }
193
-    }
194
-
195
-    /**
196
-     * Tries to find a @defaultSort annotation in one of the columns.
197
-     *
198
-     * @param Table $table
199
-     *
200
-     * @return array First item: column name, Second item: column order (asc/desc)
201
-     */
202
-    private function getDefaultSortColumnFromAnnotation(Table $table)
203
-    {
204
-        $defaultSort = null;
205
-        $defaultSortDirection = null;
206
-        foreach ($table->getColumns() as $column) {
207
-            $comments = $column->getComment();
208
-            $matches = [];
209
-            if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) {
210
-                $defaultSort = $column->getName();
211
-                if (count($matches) === 3) {
212
-                    $defaultSortDirection = $matches[2];
213
-                } else {
214
-                    $defaultSortDirection = 'ASC';
215
-                }
216
-            }
217
-        }
218
-
219
-        return [$defaultSort, $defaultSortDirection];
220
-    }
221
-
222
-    /**
223
-     * Writes the PHP bean DAO with simple functions to create/get/save objects.
224
-     *
225
-     * @param BeanDescriptor  $beanDescriptor
226
-     * @param string          $className       The name of the class
227
-     * @param string          $baseClassName
228
-     * @param string          $beanClassName
229
-     * @param Table           $table
230
-     * @param ClassNameMapper $classNameMapper
231
-     *
232
-     * @throws TDBMException
233
-     */
234
-    private function generateDao(BeanDescriptor $beanDescriptor, string $className, string $baseClassName, string $beanClassName, Table $table, ClassNameMapper $classNameMapper)
235
-    {
236
-        $daonamespace = $this->configuration->getDaoNamespace();
237
-        $beannamespace = $this->configuration->getBeanNamespace();
238
-        $tableName = $table->getName();
239
-        $primaryKeyColumns = $table->getPrimaryKeyColumns();
240
-
241
-        list($defaultSort, $defaultSortDirection) = $this->getDefaultSortColumnFromAnnotation($table);
242
-
243
-        // FIXME: lowercase tables with _ in the name should work!
244
-        $tableCamel = self::toSingular(self::toCamelCase($tableName));
245
-
246
-        $beanClassWithoutNameSpace = $beanClassName;
247
-        $beanClassName = $beannamespace.'\\'.$beanClassName;
248
-
249
-        list($usedBeans, $findByDaoCode) = $beanDescriptor->generateFindByDaoCode($beannamespace, $beanClassWithoutNameSpace);
250
-
251
-        $usedBeans[] = $beanClassName;
252
-        // Let's suppress duplicates in used beans (if any)
253
-        $usedBeans = array_flip(array_flip($usedBeans));
254
-        $useStatements = array_map(function ($usedBean) {
255
-            return "use $usedBean;\n";
256
-        }, $usedBeans);
257
-
258
-        $str = "<?php
189
+			$this->ensureDirectoryExist($possibleFileName);
190
+			file_put_contents($possibleFileName, $str);
191
+			@chmod($possibleFileName, 0664);
192
+		}
193
+	}
194
+
195
+	/**
196
+	 * Tries to find a @defaultSort annotation in one of the columns.
197
+	 *
198
+	 * @param Table $table
199
+	 *
200
+	 * @return array First item: column name, Second item: column order (asc/desc)
201
+	 */
202
+	private function getDefaultSortColumnFromAnnotation(Table $table)
203
+	{
204
+		$defaultSort = null;
205
+		$defaultSortDirection = null;
206
+		foreach ($table->getColumns() as $column) {
207
+			$comments = $column->getComment();
208
+			$matches = [];
209
+			if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) {
210
+				$defaultSort = $column->getName();
211
+				if (count($matches) === 3) {
212
+					$defaultSortDirection = $matches[2];
213
+				} else {
214
+					$defaultSortDirection = 'ASC';
215
+				}
216
+			}
217
+		}
218
+
219
+		return [$defaultSort, $defaultSortDirection];
220
+	}
221
+
222
+	/**
223
+	 * Writes the PHP bean DAO with simple functions to create/get/save objects.
224
+	 *
225
+	 * @param BeanDescriptor  $beanDescriptor
226
+	 * @param string          $className       The name of the class
227
+	 * @param string          $baseClassName
228
+	 * @param string          $beanClassName
229
+	 * @param Table           $table
230
+	 * @param ClassNameMapper $classNameMapper
231
+	 *
232
+	 * @throws TDBMException
233
+	 */
234
+	private function generateDao(BeanDescriptor $beanDescriptor, string $className, string $baseClassName, string $beanClassName, Table $table, ClassNameMapper $classNameMapper)
235
+	{
236
+		$daonamespace = $this->configuration->getDaoNamespace();
237
+		$beannamespace = $this->configuration->getBeanNamespace();
238
+		$tableName = $table->getName();
239
+		$primaryKeyColumns = $table->getPrimaryKeyColumns();
240
+
241
+		list($defaultSort, $defaultSortDirection) = $this->getDefaultSortColumnFromAnnotation($table);
242
+
243
+		// FIXME: lowercase tables with _ in the name should work!
244
+		$tableCamel = self::toSingular(self::toCamelCase($tableName));
245
+
246
+		$beanClassWithoutNameSpace = $beanClassName;
247
+		$beanClassName = $beannamespace.'\\'.$beanClassName;
248
+
249
+		list($usedBeans, $findByDaoCode) = $beanDescriptor->generateFindByDaoCode($beannamespace, $beanClassWithoutNameSpace);
250
+
251
+		$usedBeans[] = $beanClassName;
252
+		// Let's suppress duplicates in used beans (if any)
253
+		$usedBeans = array_flip(array_flip($usedBeans));
254
+		$useStatements = array_map(function ($usedBean) {
255
+			return "use $usedBean;\n";
256
+		}, $usedBeans);
257
+
258
+		$str = "<?php
259 259
 
260 260
 /*
261 261
  * This file has been automatically generated by TDBM.
@@ -331,10 +331,10 @@  discard block
 block discarded – undo
331 331
     }
332 332
     ";
333 333
 
334
-        if (count($primaryKeyColumns) === 1) {
335
-            $primaryKeyColumn = $primaryKeyColumns[0];
336
-            $primaryKeyPhpType = self::dbalTypeToPhpType($table->getColumn($primaryKeyColumn)->getType());
337
-            $str .= "
334
+		if (count($primaryKeyColumns) === 1) {
335
+			$primaryKeyColumn = $primaryKeyColumns[0];
336
+			$primaryKeyPhpType = self::dbalTypeToPhpType($table->getColumn($primaryKeyColumn)->getType());
337
+			$str .= "
338 338
     /**
339 339
      * Get $beanClassWithoutNameSpace specified by its ID (its primary key)
340 340
      * If the primary key does not exist, an exception is thrown.
@@ -349,8 +349,8 @@  discard block
 block discarded – undo
349 349
         return \$this->tdbmService->findObjectByPk('$tableName', ['$primaryKeyColumn' => \$id], [], \$lazyLoading);
350 350
     }
351 351
     ";
352
-        }
353
-        $str .= "
352
+		}
353
+		$str .= "
354 354
     /**
355 355
      * Deletes the $beanClassWithoutNameSpace passed in parameter.
356 356
      *
@@ -450,33 +450,33 @@  discard block
 block discarded – undo
450 450
     }
451 451
 ";
452 452
 
453
-        $str .= $findByDaoCode;
454
-        $str .= '}
453
+		$str .= $findByDaoCode;
454
+		$str .= '}
455 455
 ';
456 456
 
457
-        $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($daonamespace.'\\Generated\\'.$baseClassName);
458
-        if (empty($possibleBaseFileNames)) {
459
-            // @codeCoverageIgnoreStart
460
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daonamespace.'\\Generated\\'.$baseClassName.'" is not autoloadable.');
461
-            // @codeCoverageIgnoreEnd
462
-        }
463
-        $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0];
464
-
465
-        $this->ensureDirectoryExist($possibleBaseFileName);
466
-        file_put_contents($possibleBaseFileName, $str);
467
-        @chmod($possibleBaseFileName, 0664);
468
-
469
-        $possibleFileNames = $classNameMapper->getPossibleFileNames($daonamespace.'\\'.$className);
470
-        if (empty($possibleFileNames)) {
471
-            // @codeCoverageIgnoreStart
472
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daonamespace.'\\'.$className.'" is not autoloadable.');
473
-            // @codeCoverageIgnoreEnd
474
-        }
475
-        $possibleFileName = $this->rootPath.$possibleFileNames[0];
476
-
477
-        // Now, let's generate the "editable" class
478
-        if (!file_exists($possibleFileName)) {
479
-            $str = "<?php
457
+		$possibleBaseFileNames = $classNameMapper->getPossibleFileNames($daonamespace.'\\Generated\\'.$baseClassName);
458
+		if (empty($possibleBaseFileNames)) {
459
+			// @codeCoverageIgnoreStart
460
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daonamespace.'\\Generated\\'.$baseClassName.'" is not autoloadable.');
461
+			// @codeCoverageIgnoreEnd
462
+		}
463
+		$possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0];
464
+
465
+		$this->ensureDirectoryExist($possibleBaseFileName);
466
+		file_put_contents($possibleBaseFileName, $str);
467
+		@chmod($possibleBaseFileName, 0664);
468
+
469
+		$possibleFileNames = $classNameMapper->getPossibleFileNames($daonamespace.'\\'.$className);
470
+		if (empty($possibleFileNames)) {
471
+			// @codeCoverageIgnoreStart
472
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daonamespace.'\\'.$className.'" is not autoloadable.');
473
+			// @codeCoverageIgnoreEnd
474
+		}
475
+		$possibleFileName = $this->rootPath.$possibleFileNames[0];
476
+
477
+		// Now, let's generate the "editable" class
478
+		if (!file_exists($possibleFileName)) {
479
+			$str = "<?php
480 480
 
481 481
 /*
482 482
  * This file has been automatically generated by TDBM.
@@ -494,27 +494,27 @@  discard block
 block discarded – undo
494 494
 {
495 495
 }
496 496
 ";
497
-            $this->ensureDirectoryExist($possibleFileName);
498
-            file_put_contents($possibleFileName, $str);
499
-            @chmod($possibleFileName, 0664);
500
-        }
501
-    }
502
-
503
-    /**
504
-     * Generates the factory bean.
505
-     *
506
-     * @param Table[] $tableList
507
-     * @param ClassNameMapper $classNameMapper
508
-     * @throws TDBMException
509
-     */
510
-    private function generateFactory(array $tableList, ClassNameMapper $classNameMapper) : void
511
-    {
512
-        $daoNamespace = $this->configuration->getDaoNamespace();
513
-        $daoFactoryClassName = $this->namingStrategy->getDaoFactoryClassName();
514
-
515
-        // For each table, let's write a property.
516
-
517
-        $str = "<?php
497
+			$this->ensureDirectoryExist($possibleFileName);
498
+			file_put_contents($possibleFileName, $str);
499
+			@chmod($possibleFileName, 0664);
500
+		}
501
+	}
502
+
503
+	/**
504
+	 * Generates the factory bean.
505
+	 *
506
+	 * @param Table[] $tableList
507
+	 * @param ClassNameMapper $classNameMapper
508
+	 * @throws TDBMException
509
+	 */
510
+	private function generateFactory(array $tableList, ClassNameMapper $classNameMapper) : void
511
+	{
512
+		$daoNamespace = $this->configuration->getDaoNamespace();
513
+		$daoFactoryClassName = $this->namingStrategy->getDaoFactoryClassName();
514
+
515
+		// For each table, let's write a property.
516
+
517
+		$str = "<?php
518 518
 
519 519
 /*
520 520
  * This file has been automatically generated by TDBM.
@@ -524,13 +524,13 @@  discard block
 block discarded – undo
524 524
 namespace {$daoNamespace}\\Generated;
525 525
 
526 526
 ";
527
-        foreach ($tableList as $table) {
528
-            $tableName = $table->getName();
529
-            $daoClassName = $this->namingStrategy->getDaoClassName($tableName);
530
-            $str .= "use {$daoNamespace}\\".$daoClassName.";\n";
531
-        }
527
+		foreach ($tableList as $table) {
528
+			$tableName = $table->getName();
529
+			$daoClassName = $this->namingStrategy->getDaoClassName($tableName);
530
+			$str .= "use {$daoNamespace}\\".$daoClassName.";\n";
531
+		}
532 532
 
533
-        $str .= "
533
+		$str .= "
534 534
 /**
535 535
  * The $daoFactoryClassName provides an easy access to all DAOs generated by TDBM.
536 536
  *
@@ -539,12 +539,12 @@  discard block
 block discarded – undo
539 539
 {
540 540
 ";
541 541
 
542
-        foreach ($tableList as $table) {
543
-            $tableName = $table->getName();
544
-            $daoClassName = $this->namingStrategy->getDaoClassName($tableName);
545
-            $daoInstanceName = self::toVariableName($daoClassName);
542
+		foreach ($tableList as $table) {
543
+			$tableName = $table->getName();
544
+			$daoClassName = $this->namingStrategy->getDaoClassName($tableName);
545
+			$daoInstanceName = self::toVariableName($daoClassName);
546 546
 
547
-            $str .= '    /**
547
+			$str .= '    /**
548 548
      * @var '.$daoClassName.'
549 549
      */
550 550
     private $'.$daoInstanceName.';
@@ -568,140 +568,140 @@  discard block
 block discarded – undo
568 568
     {
569 569
         $this->'.$daoInstanceName.' = $'.$daoInstanceName.';
570 570
     }';
571
-        }
571
+		}
572 572
 
573
-        $str .= '
573
+		$str .= '
574 574
 }
575 575
 ';
576 576
 
577
-        $possibleFileNames = $classNameMapper->getPossibleFileNames($daoNamespace.'\\Generated\\'.$daoFactoryClassName);
578
-        if (empty($possibleFileNames)) {
579
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daoNamespace.'\\'.$daoFactoryClassName.'" is not autoloadable.');
580
-        }
581
-        $possibleFileName = $this->rootPath.$possibleFileNames[0];
582
-
583
-        $this->ensureDirectoryExist($possibleFileName);
584
-        file_put_contents($possibleFileName, $str);
585
-        @chmod($possibleFileName, 0664);
586
-    }
587
-
588
-    /**
589
-     * Transforms a string to camelCase (except the first letter will be uppercase too).
590
-     * Underscores and spaces are removed and the first letter after the underscore is uppercased.
591
-     *
592
-     * @param $str string
593
-     *
594
-     * @return string
595
-     */
596
-    public static function toCamelCase($str)
597
-    {
598
-        $str = strtoupper(substr($str, 0, 1)).substr($str, 1);
599
-        while (true) {
600
-            if (strpos($str, '_') === false && strpos($str, ' ') === false) {
601
-                break;
602
-            }
603
-
604
-            $pos = strpos($str, '_');
605
-            if ($pos === false) {
606
-                $pos = strpos($str, ' ');
607
-            }
608
-            $before = substr($str, 0, $pos);
609
-            $after = substr($str, $pos + 1);
610
-            $str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1);
611
-        }
612
-
613
-        return $str;
614
-    }
615
-
616
-    /**
617
-     * Tries to put string to the singular form (if it is plural).
618
-     * We assume the table names are in english.
619
-     *
620
-     * @param $str string
621
-     *
622
-     * @return string
623
-     */
624
-    public static function toSingular($str)
625
-    {
626
-        return Inflector::singularize($str);
627
-    }
628
-
629
-    /**
630
-     * Put the first letter of the string in lower case.
631
-     * Very useful to transform a class name into a variable name.
632
-     *
633
-     * @param $str string
634
-     *
635
-     * @return string
636
-     */
637
-    public static function toVariableName($str)
638
-    {
639
-        return strtolower(substr($str, 0, 1)).substr($str, 1);
640
-    }
641
-
642
-    /**
643
-     * Ensures the file passed in parameter can be written in its directory.
644
-     *
645
-     * @param string $fileName
646
-     *
647
-     * @throws TDBMException
648
-     */
649
-    private function ensureDirectoryExist($fileName)
650
-    {
651
-        $dirName = dirname($fileName);
652
-        if (!file_exists($dirName)) {
653
-            $old = umask(0);
654
-            $result = mkdir($dirName, 0775, true);
655
-            umask($old);
656
-            if ($result === false) {
657
-                throw new TDBMException("Unable to create directory: '".$dirName."'.");
658
-            }
659
-        }
660
-    }
661
-
662
-    /**
663
-     * Absolute path to composer json file.
664
-     *
665
-     * @param string $composerFile
666
-     */
667
-    public function setComposerFile($composerFile)
668
-    {
669
-        $this->rootPath = dirname($composerFile).'/';
670
-        $this->composerFile = basename($composerFile);
671
-    }
672
-
673
-    /**
674
-     * Transforms a DBAL type into a PHP type (for PHPDoc purpose).
675
-     *
676
-     * @param Type $type The DBAL type
677
-     *
678
-     * @return string The PHP type
679
-     */
680
-    public static function dbalTypeToPhpType(Type $type)
681
-    {
682
-        $map = [
683
-            Type::TARRAY => 'array',
684
-            Type::SIMPLE_ARRAY => 'array',
685
-            'json' => 'array',  // 'json' is supported from Doctrine DBAL 2.6 only.
686
-            Type::JSON_ARRAY => 'array',
687
-            Type::BIGINT => 'string',
688
-            Type::BOOLEAN => 'bool',
689
-            Type::DATETIME => '\DateTimeInterface',
690
-            Type::DATETIMETZ => '\DateTimeInterface',
691
-            Type::DATE => '\DateTimeInterface',
692
-            Type::TIME => '\DateTimeInterface',
693
-            Type::DECIMAL => 'float',
694
-            Type::INTEGER => 'int',
695
-            Type::OBJECT => 'string',
696
-            Type::SMALLINT => 'int',
697
-            Type::STRING => 'string',
698
-            Type::TEXT => 'string',
699
-            Type::BINARY => 'string',
700
-            Type::BLOB => 'string',
701
-            Type::FLOAT => 'float',
702
-            Type::GUID => 'string',
703
-        ];
704
-
705
-        return isset($map[$type->getName()]) ? $map[$type->getName()] : $type->getName();
706
-    }
577
+		$possibleFileNames = $classNameMapper->getPossibleFileNames($daoNamespace.'\\Generated\\'.$daoFactoryClassName);
578
+		if (empty($possibleFileNames)) {
579
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daoNamespace.'\\'.$daoFactoryClassName.'" is not autoloadable.');
580
+		}
581
+		$possibleFileName = $this->rootPath.$possibleFileNames[0];
582
+
583
+		$this->ensureDirectoryExist($possibleFileName);
584
+		file_put_contents($possibleFileName, $str);
585
+		@chmod($possibleFileName, 0664);
586
+	}
587
+
588
+	/**
589
+	 * Transforms a string to camelCase (except the first letter will be uppercase too).
590
+	 * Underscores and spaces are removed and the first letter after the underscore is uppercased.
591
+	 *
592
+	 * @param $str string
593
+	 *
594
+	 * @return string
595
+	 */
596
+	public static function toCamelCase($str)
597
+	{
598
+		$str = strtoupper(substr($str, 0, 1)).substr($str, 1);
599
+		while (true) {
600
+			if (strpos($str, '_') === false && strpos($str, ' ') === false) {
601
+				break;
602
+			}
603
+
604
+			$pos = strpos($str, '_');
605
+			if ($pos === false) {
606
+				$pos = strpos($str, ' ');
607
+			}
608
+			$before = substr($str, 0, $pos);
609
+			$after = substr($str, $pos + 1);
610
+			$str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1);
611
+		}
612
+
613
+		return $str;
614
+	}
615
+
616
+	/**
617
+	 * Tries to put string to the singular form (if it is plural).
618
+	 * We assume the table names are in english.
619
+	 *
620
+	 * @param $str string
621
+	 *
622
+	 * @return string
623
+	 */
624
+	public static function toSingular($str)
625
+	{
626
+		return Inflector::singularize($str);
627
+	}
628
+
629
+	/**
630
+	 * Put the first letter of the string in lower case.
631
+	 * Very useful to transform a class name into a variable name.
632
+	 *
633
+	 * @param $str string
634
+	 *
635
+	 * @return string
636
+	 */
637
+	public static function toVariableName($str)
638
+	{
639
+		return strtolower(substr($str, 0, 1)).substr($str, 1);
640
+	}
641
+
642
+	/**
643
+	 * Ensures the file passed in parameter can be written in its directory.
644
+	 *
645
+	 * @param string $fileName
646
+	 *
647
+	 * @throws TDBMException
648
+	 */
649
+	private function ensureDirectoryExist($fileName)
650
+	{
651
+		$dirName = dirname($fileName);
652
+		if (!file_exists($dirName)) {
653
+			$old = umask(0);
654
+			$result = mkdir($dirName, 0775, true);
655
+			umask($old);
656
+			if ($result === false) {
657
+				throw new TDBMException("Unable to create directory: '".$dirName."'.");
658
+			}
659
+		}
660
+	}
661
+
662
+	/**
663
+	 * Absolute path to composer json file.
664
+	 *
665
+	 * @param string $composerFile
666
+	 */
667
+	public function setComposerFile($composerFile)
668
+	{
669
+		$this->rootPath = dirname($composerFile).'/';
670
+		$this->composerFile = basename($composerFile);
671
+	}
672
+
673
+	/**
674
+	 * Transforms a DBAL type into a PHP type (for PHPDoc purpose).
675
+	 *
676
+	 * @param Type $type The DBAL type
677
+	 *
678
+	 * @return string The PHP type
679
+	 */
680
+	public static function dbalTypeToPhpType(Type $type)
681
+	{
682
+		$map = [
683
+			Type::TARRAY => 'array',
684
+			Type::SIMPLE_ARRAY => 'array',
685
+			'json' => 'array',  // 'json' is supported from Doctrine DBAL 2.6 only.
686
+			Type::JSON_ARRAY => 'array',
687
+			Type::BIGINT => 'string',
688
+			Type::BOOLEAN => 'bool',
689
+			Type::DATETIME => '\DateTimeInterface',
690
+			Type::DATETIMETZ => '\DateTimeInterface',
691
+			Type::DATE => '\DateTimeInterface',
692
+			Type::TIME => '\DateTimeInterface',
693
+			Type::DECIMAL => 'float',
694
+			Type::INTEGER => 'int',
695
+			Type::OBJECT => 'string',
696
+			Type::SMALLINT => 'int',
697
+			Type::STRING => 'string',
698
+			Type::TEXT => 'string',
699
+			Type::BINARY => 'string',
700
+			Type::BLOB => 'string',
701
+			Type::FLOAT => 'float',
702
+			Type::GUID => 'string',
703
+		];
704
+
705
+		return isset($map[$type->getName()]) ? $map[$type->getName()] : $type->getName();
706
+	}
707 707
 }
Please login to merge, or discard this patch.