Test Failed
Pull Request — 4.2 (#140)
by David
05:30 queued 14s
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   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -17,171 +17,171 @@
 block discarded – undo
17 17
 class Configuration implements ConfigurationInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    private $beanNamespace;
24
-    /**
25
-     * @var string
26
-     */
27
-    private $daoNamespace;
28
-    /**
29
-     * @var Connection
30
-     */
31
-    private $connection;
32
-    /**
33
-     * @var Cache
34
-     */
35
-    private $cache;
36
-    /**
37
-     * @var SchemaAnalyzer
38
-     */
39
-    private $schemaAnalyzer;
40
-    /**
41
-     * @var LoggerInterface
42
-     */
43
-    private $logger;
44
-    /**
45
-     * @var GeneratorListenerInterface
46
-     */
47
-    private $generatorEventDispatcher;
48
-    /**
49
-     * @var NamingStrategyInterface
50
-     */
51
-    private $namingStrategy;
52
-    /**
53
-     * @var PathFinderInterface
54
-     */
55
-    private $pathFinder;
56
-    /**
57
-     * The Composer file used to detect the path where files should be written.
58
-     *
59
-     * @var string
60
-     */
61
-    private $composerFile;
62
-
63
-    /**
64
-     * @param string $beanNamespace The namespace hosting the beans
65
-     * @param string $daoNamespace The namespace hosting the DAOs
66
-     * @param Connection $connection The connection to the database
67
-     * @param Cache|null $cache The Doctrine cache to store database metadata
68
-     * @param SchemaAnalyzer|null $schemaAnalyzer The schema analyzer that will be used to find shortest paths... Will be automatically created if not passed
69
-     * @param LoggerInterface|null $logger The logger
70
-     * @param GeneratorListenerInterface[] $generatorListeners A list of listeners that will be triggered when beans/daos are generated
71
-     */
72
-    public function __construct(string $beanNamespace, string $daoNamespace, Connection $connection, NamingStrategyInterface $namingStrategy, Cache $cache = null, SchemaAnalyzer $schemaAnalyzer = null, LoggerInterface $logger = null, array $generatorListeners = [])
73
-    {
74
-        $this->beanNamespace = rtrim($beanNamespace, '\\');
75
-        $this->daoNamespace = rtrim($daoNamespace, '\\');
76
-        $this->connection = $connection;
77
-        $this->namingStrategy = $namingStrategy;
78
-        if ($cache !== null) {
79
-            $this->cache = $cache;
80
-        } else {
81
-            $this->cache = new VoidCache();
82
-        }
83
-        if ($schemaAnalyzer !== null) {
84
-            $this->schemaAnalyzer = $schemaAnalyzer;
85
-        } else {
86
-            $this->schemaAnalyzer = new SchemaAnalyzer($this->connection->getSchemaManager(), $this->cache, $this->getConnectionUniqueId());
87
-        }
88
-        $this->logger = $logger;
89
-        $this->generatorEventDispatcher = new GeneratorEventDispatcher($generatorListeners);
90
-        $this->pathFinder = new PathFinder();
91
-    }
92
-
93
-    /**
94
-     * @return string
95
-     */
96
-    public function getBeanNamespace(): string
97
-    {
98
-        return $this->beanNamespace;
99
-    }
100
-
101
-    /**
102
-     * @return string
103
-     */
104
-    public function getDaoNamespace(): string
105
-    {
106
-        return $this->daoNamespace;
107
-    }
108
-
109
-    /**
110
-     * @return Connection
111
-     */
112
-    public function getConnection(): Connection
113
-    {
114
-        return $this->connection;
115
-    }
116
-
117
-    /**
118
-     * @return NamingStrategyInterface
119
-     */
120
-    public function getNamingStrategy(): NamingStrategyInterface
121
-    {
122
-        return $this->namingStrategy;
123
-    }
124
-
125
-    /**
126
-     * @return Cache
127
-     */
128
-    public function getCache(): Cache
129
-    {
130
-        return $this->cache;
131
-    }
132
-
133
-    /**
134
-     * @return SchemaAnalyzer
135
-     */
136
-    public function getSchemaAnalyzer(): SchemaAnalyzer
137
-    {
138
-        return $this->schemaAnalyzer;
139
-    }
140
-
141
-    /**
142
-     * @return LoggerInterface
143
-     */
144
-    public function getLogger(): ?LoggerInterface
145
-    {
146
-        return $this->logger;
147
-    }
148
-
149
-    /**
150
-     * @return GeneratorListenerInterface
151
-     */
152
-    public function getGeneratorEventDispatcher(): GeneratorListenerInterface
153
-    {
154
-        return $this->generatorEventDispatcher;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * Creates a unique cache key for the current connection.
161
-     *
162
-     * @return string
163
-     */
164
-    private function getConnectionUniqueId(): string
165
-    {
166
-        return hash('md4', $this->connection->getHost().'-'.$this->connection->getPort().'-'.$this->connection->getDatabase().'-'.$this->connection->getDriver()->getName());
167
-    }
168
-
169
-    /**
170
-     * Returns a class able to find the place of a PHP file based on the class name.
171
-     * Useful to find the path where DAOs and beans should be written to.
172
-     *
173
-     * @return PathFinderInterface
174
-     */
175
-    public function getPathFinder(): PathFinderInterface
176
-    {
177
-        return $this->pathFinder;
178
-    }
179
-
180
-    /**
181
-     * @param PathFinderInterface $pathFinder
182
-     */
183
-    public function setPathFinder(PathFinderInterface $pathFinder)
184
-    {
185
-        $this->pathFinder = $pathFinder;
186
-    }
20
+	/**
21
+	 * @var string
22
+	 */
23
+	private $beanNamespace;
24
+	/**
25
+	 * @var string
26
+	 */
27
+	private $daoNamespace;
28
+	/**
29
+	 * @var Connection
30
+	 */
31
+	private $connection;
32
+	/**
33
+	 * @var Cache
34
+	 */
35
+	private $cache;
36
+	/**
37
+	 * @var SchemaAnalyzer
38
+	 */
39
+	private $schemaAnalyzer;
40
+	/**
41
+	 * @var LoggerInterface
42
+	 */
43
+	private $logger;
44
+	/**
45
+	 * @var GeneratorListenerInterface
46
+	 */
47
+	private $generatorEventDispatcher;
48
+	/**
49
+	 * @var NamingStrategyInterface
50
+	 */
51
+	private $namingStrategy;
52
+	/**
53
+	 * @var PathFinderInterface
54
+	 */
55
+	private $pathFinder;
56
+	/**
57
+	 * The Composer file used to detect the path where files should be written.
58
+	 *
59
+	 * @var string
60
+	 */
61
+	private $composerFile;
62
+
63
+	/**
64
+	 * @param string $beanNamespace The namespace hosting the beans
65
+	 * @param string $daoNamespace The namespace hosting the DAOs
66
+	 * @param Connection $connection The connection to the database
67
+	 * @param Cache|null $cache The Doctrine cache to store database metadata
68
+	 * @param SchemaAnalyzer|null $schemaAnalyzer The schema analyzer that will be used to find shortest paths... Will be automatically created if not passed
69
+	 * @param LoggerInterface|null $logger The logger
70
+	 * @param GeneratorListenerInterface[] $generatorListeners A list of listeners that will be triggered when beans/daos are generated
71
+	 */
72
+	public function __construct(string $beanNamespace, string $daoNamespace, Connection $connection, NamingStrategyInterface $namingStrategy, Cache $cache = null, SchemaAnalyzer $schemaAnalyzer = null, LoggerInterface $logger = null, array $generatorListeners = [])
73
+	{
74
+		$this->beanNamespace = rtrim($beanNamespace, '\\');
75
+		$this->daoNamespace = rtrim($daoNamespace, '\\');
76
+		$this->connection = $connection;
77
+		$this->namingStrategy = $namingStrategy;
78
+		if ($cache !== null) {
79
+			$this->cache = $cache;
80
+		} else {
81
+			$this->cache = new VoidCache();
82
+		}
83
+		if ($schemaAnalyzer !== null) {
84
+			$this->schemaAnalyzer = $schemaAnalyzer;
85
+		} else {
86
+			$this->schemaAnalyzer = new SchemaAnalyzer($this->connection->getSchemaManager(), $this->cache, $this->getConnectionUniqueId());
87
+		}
88
+		$this->logger = $logger;
89
+		$this->generatorEventDispatcher = new GeneratorEventDispatcher($generatorListeners);
90
+		$this->pathFinder = new PathFinder();
91
+	}
92
+
93
+	/**
94
+	 * @return string
95
+	 */
96
+	public function getBeanNamespace(): string
97
+	{
98
+		return $this->beanNamespace;
99
+	}
100
+
101
+	/**
102
+	 * @return string
103
+	 */
104
+	public function getDaoNamespace(): string
105
+	{
106
+		return $this->daoNamespace;
107
+	}
108
+
109
+	/**
110
+	 * @return Connection
111
+	 */
112
+	public function getConnection(): Connection
113
+	{
114
+		return $this->connection;
115
+	}
116
+
117
+	/**
118
+	 * @return NamingStrategyInterface
119
+	 */
120
+	public function getNamingStrategy(): NamingStrategyInterface
121
+	{
122
+		return $this->namingStrategy;
123
+	}
124
+
125
+	/**
126
+	 * @return Cache
127
+	 */
128
+	public function getCache(): Cache
129
+	{
130
+		return $this->cache;
131
+	}
132
+
133
+	/**
134
+	 * @return SchemaAnalyzer
135
+	 */
136
+	public function getSchemaAnalyzer(): SchemaAnalyzer
137
+	{
138
+		return $this->schemaAnalyzer;
139
+	}
140
+
141
+	/**
142
+	 * @return LoggerInterface
143
+	 */
144
+	public function getLogger(): ?LoggerInterface
145
+	{
146
+		return $this->logger;
147
+	}
148
+
149
+	/**
150
+	 * @return GeneratorListenerInterface
151
+	 */
152
+	public function getGeneratorEventDispatcher(): GeneratorListenerInterface
153
+	{
154
+		return $this->generatorEventDispatcher;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * Creates a unique cache key for the current connection.
161
+	 *
162
+	 * @return string
163
+	 */
164
+	private function getConnectionUniqueId(): string
165
+	{
166
+		return hash('md4', $this->connection->getHost().'-'.$this->connection->getPort().'-'.$this->connection->getDatabase().'-'.$this->connection->getDriver()->getName());
167
+	}
168
+
169
+	/**
170
+	 * Returns a class able to find the place of a PHP file based on the class name.
171
+	 * Useful to find the path where DAOs and beans should be written to.
172
+	 *
173
+	 * @return PathFinderInterface
174
+	 */
175
+	public function getPathFinder(): PathFinderInterface
176
+	{
177
+		return $this->pathFinder;
178
+	}
179
+
180
+	/**
181
+	 * @param PathFinderInterface $pathFinder
182
+	 */
183
+	public function setPathFinder(PathFinderInterface $pathFinder)
184
+	{
185
+		$this->pathFinder = $pathFinder;
186
+	}
187 187
 }
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
@@ -20,103 +20,103 @@
 block discarded – undo
20 20
  */
21 21
 class AlteredConfiguration implements ConfigurationInterface
22 22
 {
23
-    /**
24
-     * @var ConfigurationInterface
25
-     */
26
-    private $configuration;
27
-
28
-    /**
29
-     * @var LoggerInterface
30
-     */
31
-    private $logger;
32
-
33
-    public function __construct(ConfigurationInterface $configuration)
34
-    {
35
-        $this->configuration = $configuration;
36
-        $this->logger = $configuration->getLogger();
37
-    }
38
-
39
-
40
-    /**
41
-     * @return string
42
-     */
43
-    public function getBeanNamespace(): string
44
-    {
45
-        return $this->configuration->getBeanNamespace();
46
-    }
47
-
48
-    /**
49
-     * @return string
50
-     */
51
-    public function getDaoNamespace(): string
52
-    {
53
-        return $this->configuration->getDaoNamespace();
54
-    }
55
-
56
-    /**
57
-     * @return Connection
58
-     */
59
-    public function getConnection(): Connection
60
-    {
61
-        return $this->configuration->getConnection();
62
-    }
63
-
64
-    /**
65
-     * @return Cache
66
-     */
67
-    public function getCache(): Cache
68
-    {
69
-        return $this->configuration->getCache();
70
-    }
71
-
72
-    /**
73
-     * @return NamingStrategyInterface
74
-     */
75
-    public function getNamingStrategy(): NamingStrategyInterface
76
-    {
77
-        return $this->configuration->getNamingStrategy();
78
-    }
79
-
80
-    /**
81
-     * @return SchemaAnalyzer
82
-     */
83
-    public function getSchemaAnalyzer(): SchemaAnalyzer
84
-    {
85
-        return $this->configuration->getSchemaAnalyzer();
86
-    }
87
-
88
-    /**
89
-     * @return LoggerInterface
90
-     */
91
-    public function getLogger(): ?LoggerInterface
92
-    {
93
-        return $this->configuration->getLogger();
94
-    }
95
-
96
-    /**
97
-     * @return GeneratorListenerInterface
98
-     */
99
-    public function getGeneratorEventDispatcher(): GeneratorListenerInterface
100
-    {
101
-        return $this->configuration->getGeneratorEventDispatcher();
102
-    }
103
-
104
-    /**
105
-     * @param LoggerInterface $logger
106
-     */
107
-    public function setLogger(LoggerInterface $logger)
108
-    {
109
-        $this->logger = $logger;
110
-    }
111
-
112
-    /**
113
-     * Returns a class able to find the place of a PHP file based on the class name.
114
-     * Useful to find the path where DAOs and beans should be written to.
115
-     *
116
-     * @return PathFinderInterface
117
-     */
118
-    public function getPathFinder(): PathFinderInterface
119
-    {
120
-        return $this->getPathFinder();
121
-    }
23
+	/**
24
+	 * @var ConfigurationInterface
25
+	 */
26
+	private $configuration;
27
+
28
+	/**
29
+	 * @var LoggerInterface
30
+	 */
31
+	private $logger;
32
+
33
+	public function __construct(ConfigurationInterface $configuration)
34
+	{
35
+		$this->configuration = $configuration;
36
+		$this->logger = $configuration->getLogger();
37
+	}
38
+
39
+
40
+	/**
41
+	 * @return string
42
+	 */
43
+	public function getBeanNamespace(): string
44
+	{
45
+		return $this->configuration->getBeanNamespace();
46
+	}
47
+
48
+	/**
49
+	 * @return string
50
+	 */
51
+	public function getDaoNamespace(): string
52
+	{
53
+		return $this->configuration->getDaoNamespace();
54
+	}
55
+
56
+	/**
57
+	 * @return Connection
58
+	 */
59
+	public function getConnection(): Connection
60
+	{
61
+		return $this->configuration->getConnection();
62
+	}
63
+
64
+	/**
65
+	 * @return Cache
66
+	 */
67
+	public function getCache(): Cache
68
+	{
69
+		return $this->configuration->getCache();
70
+	}
71
+
72
+	/**
73
+	 * @return NamingStrategyInterface
74
+	 */
75
+	public function getNamingStrategy(): NamingStrategyInterface
76
+	{
77
+		return $this->configuration->getNamingStrategy();
78
+	}
79
+
80
+	/**
81
+	 * @return SchemaAnalyzer
82
+	 */
83
+	public function getSchemaAnalyzer(): SchemaAnalyzer
84
+	{
85
+		return $this->configuration->getSchemaAnalyzer();
86
+	}
87
+
88
+	/**
89
+	 * @return LoggerInterface
90
+	 */
91
+	public function getLogger(): ?LoggerInterface
92
+	{
93
+		return $this->configuration->getLogger();
94
+	}
95
+
96
+	/**
97
+	 * @return GeneratorListenerInterface
98
+	 */
99
+	public function getGeneratorEventDispatcher(): GeneratorListenerInterface
100
+	{
101
+		return $this->configuration->getGeneratorEventDispatcher();
102
+	}
103
+
104
+	/**
105
+	 * @param LoggerInterface $logger
106
+	 */
107
+	public function setLogger(LoggerInterface $logger)
108
+	{
109
+		$this->logger = $logger;
110
+	}
111
+
112
+	/**
113
+	 * Returns a class able to find the place of a PHP file based on the class name.
114
+	 * Useful to find the path where DAOs and beans should be written to.
115
+	 *
116
+	 * @return PathFinderInterface
117
+	 */
118
+	public function getPathFinder(): PathFinderInterface
119
+	{
120
+		return $this->getPathFinder();
121
+	}
122 122
 }
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
@@ -13,51 +13,51 @@
 block discarded – undo
13 13
 
14 14
 interface ConfigurationInterface
15 15
 {
16
-    /**
17
-     * @return string
18
-     */
19
-    public function getBeanNamespace(): string;
20
-
21
-    /**
22
-     * @return string
23
-     */
24
-    public function getDaoNamespace(): string;
25
-
26
-    /**
27
-     * @return Connection
28
-     */
29
-    public function getConnection(): Connection;
30
-
31
-    /**
32
-     * @return Cache
33
-     */
34
-    public function getCache(): Cache;
35
-
36
-    /**
37
-     * @return NamingStrategyInterface
38
-     */
39
-    public function getNamingStrategy(): NamingStrategyInterface;
40
-
41
-    /**
42
-     * @return SchemaAnalyzer
43
-     */
44
-    public function getSchemaAnalyzer(): SchemaAnalyzer;
45
-
46
-    /**
47
-     * @return LoggerInterface
48
-     */
49
-    public function getLogger(): ?LoggerInterface;
50
-
51
-    /**
52
-     * @return GeneratorListenerInterface
53
-     */
54
-    public function getGeneratorEventDispatcher(): GeneratorListenerInterface;
55
-
56
-    /**
57
-     * Returns a class able to find the place of a PHP file based on the class name.
58
-     * Useful to find the path where DAOs and beans should be written to.
59
-     *
60
-     * @return PathFinderInterface
61
-     */
62
-    public function getPathFinder() : PathFinderInterface;
16
+	/**
17
+	 * @return string
18
+	 */
19
+	public function getBeanNamespace(): string;
20
+
21
+	/**
22
+	 * @return string
23
+	 */
24
+	public function getDaoNamespace(): string;
25
+
26
+	/**
27
+	 * @return Connection
28
+	 */
29
+	public function getConnection(): Connection;
30
+
31
+	/**
32
+	 * @return Cache
33
+	 */
34
+	public function getCache(): Cache;
35
+
36
+	/**
37
+	 * @return NamingStrategyInterface
38
+	 */
39
+	public function getNamingStrategy(): NamingStrategyInterface;
40
+
41
+	/**
42
+	 * @return SchemaAnalyzer
43
+	 */
44
+	public function getSchemaAnalyzer(): SchemaAnalyzer;
45
+
46
+	/**
47
+	 * @return LoggerInterface
48
+	 */
49
+	public function getLogger(): ?LoggerInterface;
50
+
51
+	/**
52
+	 * @return GeneratorListenerInterface
53
+	 */
54
+	public function getGeneratorEventDispatcher(): GeneratorListenerInterface;
55
+
56
+	/**
57
+	 * Returns a class able to find the place of a PHP file based on the class name.
58
+	 * Useful to find the path where DAOs and beans should be written to.
59
+	 *
60
+	 * @return PathFinderInterface
61
+	 */
62
+	public function getPathFinder() : PathFinderInterface;
63 63
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Utils/TDBMDaoGenerator.php 1 patch
Indentation   +377 added lines, -377 removed lines patch added patch discarded remove patch
@@ -16,144 +16,144 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class TDBMDaoGenerator
18 18
 {
19
-    /**
20
-     * @var Schema
21
-     */
22
-    private $schema;
23
-
24
-    /**
25
-     * The root directory of the project.
26
-     *
27
-     * @var string
28
-     */
29
-    private $rootPath;
30
-
31
-    /**
32
-     * Name of composer file.
33
-     *
34
-     * @var string
35
-     */
36
-    private $composerFile;
37
-
38
-    /**
39
-     * @var TDBMSchemaAnalyzer
40
-     */
41
-    private $tdbmSchemaAnalyzer;
42
-
43
-    /**
44
-     * @var EventDispatcherInterface
45
-     */
46
-    private $eventDispatcher;
47
-
48
-    /**
49
-     * @var NamingStrategyInterface
50
-     */
51
-    private $namingStrategy;
52
-    /**
53
-     * @var ConfigurationInterface
54
-     */
55
-    private $configuration;
56
-
57
-    /**
58
-     * Constructor.
59
-     *
60
-     * @param ConfigurationInterface $configuration
61
-     * @param Schema $schema
62
-     * @param TDBMSchemaAnalyzer $tdbmSchemaAnalyzer
63
-     */
64
-    public function __construct(ConfigurationInterface $configuration, Schema $schema, TDBMSchemaAnalyzer $tdbmSchemaAnalyzer)
65
-    {
66
-        $this->configuration = $configuration;
67
-        $this->schema = $schema;
68
-        $this->tdbmSchemaAnalyzer = $tdbmSchemaAnalyzer;
69
-        $this->rootPath = __DIR__.'/../../../../../../../../';
70
-        $this->namingStrategy = $configuration->getNamingStrategy();
71
-        $this->eventDispatcher = $configuration->getGeneratorEventDispatcher();
72
-    }
73
-
74
-    /**
75
-     * Generates all the daos and beans.
76
-     *
77
-     * @throws TDBMException
78
-     */
79
-    public function generateAllDaosAndBeans(): void
80
-    {
81
-        // TODO: check that no class name ends with "Base". Otherwise, there will be name clash.
82
-
83
-        $tableList = $this->schema->getTables();
84
-
85
-        // Remove all beans and daos from junction tables
86
-        $junctionTables = $this->configuration->getSchemaAnalyzer()->detectJunctionTables(true);
87
-        $junctionTableNames = array_map(function (Table $table) {
88
-            return $table->getName();
89
-        }, $junctionTables);
90
-
91
-        $tableList = array_filter($tableList, function (Table $table) use ($junctionTableNames) {
92
-            return !in_array($table->getName(), $junctionTableNames);
93
-        });
94
-
95
-        $beanDescriptors = [];
96
-
97
-        foreach ($tableList as $table) {
98
-            $beanDescriptors[] = $this->generateDaoAndBean($table);
99
-        }
100
-
101
-
102
-        $this->generateFactory($tableList);
103
-
104
-        // Let's call the list of listeners
105
-        $this->eventDispatcher->onGenerate($this->configuration, $beanDescriptors);
106
-    }
107
-
108
-    /**
109
-     * Generates in one method call the daos and the beans for one table.
110
-     *
111
-     * @param Table $table
112
-     *
113
-     * @return BeanDescriptor
114
-     * @throws TDBMException
115
-     */
116
-    private function generateDaoAndBean(Table $table) : BeanDescriptor
117
-    {
118
-        // TODO: $storeInUtc is NOT USED.
119
-        $tableName = $table->getName();
120
-        $daoName = $this->namingStrategy->getDaoClassName($tableName);
121
-        $beanName = $this->namingStrategy->getBeanClassName($tableName);
122
-        $baseBeanName = $this->namingStrategy->getBaseBeanClassName($tableName);
123
-        $baseDaoName = $this->namingStrategy->getBaseDaoClassName($tableName);
124
-
125
-        $beanDescriptor = new BeanDescriptor($table, $this->configuration->getSchemaAnalyzer(), $this->schema, $this->tdbmSchemaAnalyzer, $this->namingStrategy);
126
-        $this->generateBean($beanDescriptor, $beanName, $baseBeanName, $table);
127
-        $this->generateDao($beanDescriptor, $daoName, $baseDaoName, $beanName, $table);
128
-        return $beanDescriptor;
129
-    }
130
-
131
-    /**
132
-     * Writes the PHP bean file with all getters and setters from the table passed in parameter.
133
-     *
134
-     * @param BeanDescriptor  $beanDescriptor
135
-     * @param string          $className       The name of the class
136
-     * @param string          $baseClassName   The name of the base class which will be extended (name only, no directory)
137
-     * @param Table           $table           The table
138
-     *
139
-     * @throws TDBMException
140
-     */
141
-    public function generateBean(BeanDescriptor $beanDescriptor, $className, $baseClassName, Table $table)
142
-    {
143
-        $beannamespace = $this->configuration->getBeanNamespace();
144
-        $str = $beanDescriptor->generatePhpCode($beannamespace);
145
-
146
-        $possibleBaseFileName = $this->configuration->getPathFinder()->getPath($beannamespace.'\\Generated\\'.$baseClassName)->getPathname();
147
-
148
-        $this->ensureDirectoryExist($possibleBaseFileName);
149
-        file_put_contents($possibleBaseFileName, $str);
150
-        @chmod($possibleBaseFileName, 0664);
151
-
152
-        $possibleFileName = $this->configuration->getPathFinder()->getPath($beannamespace.'\\'.$className)->getPathname();
153
-
154
-        if (!file_exists($possibleFileName)) {
155
-            $tableName = $table->getName();
156
-            $str = "<?php
19
+	/**
20
+	 * @var Schema
21
+	 */
22
+	private $schema;
23
+
24
+	/**
25
+	 * The root directory of the project.
26
+	 *
27
+	 * @var string
28
+	 */
29
+	private $rootPath;
30
+
31
+	/**
32
+	 * Name of composer file.
33
+	 *
34
+	 * @var string
35
+	 */
36
+	private $composerFile;
37
+
38
+	/**
39
+	 * @var TDBMSchemaAnalyzer
40
+	 */
41
+	private $tdbmSchemaAnalyzer;
42
+
43
+	/**
44
+	 * @var EventDispatcherInterface
45
+	 */
46
+	private $eventDispatcher;
47
+
48
+	/**
49
+	 * @var NamingStrategyInterface
50
+	 */
51
+	private $namingStrategy;
52
+	/**
53
+	 * @var ConfigurationInterface
54
+	 */
55
+	private $configuration;
56
+
57
+	/**
58
+	 * Constructor.
59
+	 *
60
+	 * @param ConfigurationInterface $configuration
61
+	 * @param Schema $schema
62
+	 * @param TDBMSchemaAnalyzer $tdbmSchemaAnalyzer
63
+	 */
64
+	public function __construct(ConfigurationInterface $configuration, Schema $schema, TDBMSchemaAnalyzer $tdbmSchemaAnalyzer)
65
+	{
66
+		$this->configuration = $configuration;
67
+		$this->schema = $schema;
68
+		$this->tdbmSchemaAnalyzer = $tdbmSchemaAnalyzer;
69
+		$this->rootPath = __DIR__.'/../../../../../../../../';
70
+		$this->namingStrategy = $configuration->getNamingStrategy();
71
+		$this->eventDispatcher = $configuration->getGeneratorEventDispatcher();
72
+	}
73
+
74
+	/**
75
+	 * Generates all the daos and beans.
76
+	 *
77
+	 * @throws TDBMException
78
+	 */
79
+	public function generateAllDaosAndBeans(): void
80
+	{
81
+		// TODO: check that no class name ends with "Base". Otherwise, there will be name clash.
82
+
83
+		$tableList = $this->schema->getTables();
84
+
85
+		// Remove all beans and daos from junction tables
86
+		$junctionTables = $this->configuration->getSchemaAnalyzer()->detectJunctionTables(true);
87
+		$junctionTableNames = array_map(function (Table $table) {
88
+			return $table->getName();
89
+		}, $junctionTables);
90
+
91
+		$tableList = array_filter($tableList, function (Table $table) use ($junctionTableNames) {
92
+			return !in_array($table->getName(), $junctionTableNames);
93
+		});
94
+
95
+		$beanDescriptors = [];
96
+
97
+		foreach ($tableList as $table) {
98
+			$beanDescriptors[] = $this->generateDaoAndBean($table);
99
+		}
100
+
101
+
102
+		$this->generateFactory($tableList);
103
+
104
+		// Let's call the list of listeners
105
+		$this->eventDispatcher->onGenerate($this->configuration, $beanDescriptors);
106
+	}
107
+
108
+	/**
109
+	 * Generates in one method call the daos and the beans for one table.
110
+	 *
111
+	 * @param Table $table
112
+	 *
113
+	 * @return BeanDescriptor
114
+	 * @throws TDBMException
115
+	 */
116
+	private function generateDaoAndBean(Table $table) : BeanDescriptor
117
+	{
118
+		// TODO: $storeInUtc is NOT USED.
119
+		$tableName = $table->getName();
120
+		$daoName = $this->namingStrategy->getDaoClassName($tableName);
121
+		$beanName = $this->namingStrategy->getBeanClassName($tableName);
122
+		$baseBeanName = $this->namingStrategy->getBaseBeanClassName($tableName);
123
+		$baseDaoName = $this->namingStrategy->getBaseDaoClassName($tableName);
124
+
125
+		$beanDescriptor = new BeanDescriptor($table, $this->configuration->getSchemaAnalyzer(), $this->schema, $this->tdbmSchemaAnalyzer, $this->namingStrategy);
126
+		$this->generateBean($beanDescriptor, $beanName, $baseBeanName, $table);
127
+		$this->generateDao($beanDescriptor, $daoName, $baseDaoName, $beanName, $table);
128
+		return $beanDescriptor;
129
+	}
130
+
131
+	/**
132
+	 * Writes the PHP bean file with all getters and setters from the table passed in parameter.
133
+	 *
134
+	 * @param BeanDescriptor  $beanDescriptor
135
+	 * @param string          $className       The name of the class
136
+	 * @param string          $baseClassName   The name of the base class which will be extended (name only, no directory)
137
+	 * @param Table           $table           The table
138
+	 *
139
+	 * @throws TDBMException
140
+	 */
141
+	public function generateBean(BeanDescriptor $beanDescriptor, $className, $baseClassName, Table $table)
142
+	{
143
+		$beannamespace = $this->configuration->getBeanNamespace();
144
+		$str = $beanDescriptor->generatePhpCode($beannamespace);
145
+
146
+		$possibleBaseFileName = $this->configuration->getPathFinder()->getPath($beannamespace.'\\Generated\\'.$baseClassName)->getPathname();
147
+
148
+		$this->ensureDirectoryExist($possibleBaseFileName);
149
+		file_put_contents($possibleBaseFileName, $str);
150
+		@chmod($possibleBaseFileName, 0664);
151
+
152
+		$possibleFileName = $this->configuration->getPathFinder()->getPath($beannamespace.'\\'.$className)->getPathname();
153
+
154
+		if (!file_exists($possibleFileName)) {
155
+			$tableName = $table->getName();
156
+			$str = "<?php
157 157
 /*
158 158
  * This file has been automatically generated by TDBM.
159 159
  * You can edit this file as it will not be overwritten.
@@ -170,75 +170,75 @@  discard block
 block discarded – undo
170 170
 {
171 171
 }
172 172
 ";
173
-            $this->ensureDirectoryExist($possibleFileName);
174
-            file_put_contents($possibleFileName, $str);
175
-            @chmod($possibleFileName, 0664);
176
-        }
177
-    }
178
-
179
-    /**
180
-     * Tries to find a @defaultSort annotation in one of the columns.
181
-     *
182
-     * @param Table $table
183
-     *
184
-     * @return array First item: column name, Second item: column order (asc/desc)
185
-     */
186
-    private function getDefaultSortColumnFromAnnotation(Table $table)
187
-    {
188
-        $defaultSort = null;
189
-        $defaultSortDirection = null;
190
-        foreach ($table->getColumns() as $column) {
191
-            $comments = $column->getComment();
192
-            $matches = [];
193
-            if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) {
194
-                $defaultSort = $column->getName();
195
-                if (count($matches) === 3) {
196
-                    $defaultSortDirection = $matches[2];
197
-                } else {
198
-                    $defaultSortDirection = 'ASC';
199
-                }
200
-            }
201
-        }
202
-
203
-        return [$defaultSort, $defaultSortDirection];
204
-    }
205
-
206
-    /**
207
-     * Writes the PHP bean DAO with simple functions to create/get/save objects.
208
-     *
209
-     * @param BeanDescriptor  $beanDescriptor
210
-     * @param string          $className       The name of the class
211
-     * @param string          $baseClassName
212
-     * @param string          $beanClassName
213
-     * @param Table           $table
214
-     *
215
-     * @throws TDBMException
216
-     */
217
-    private function generateDao(BeanDescriptor $beanDescriptor, string $className, string $baseClassName, string $beanClassName, Table $table)
218
-    {
219
-        $daonamespace = $this->configuration->getDaoNamespace();
220
-        $beannamespace = $this->configuration->getBeanNamespace();
221
-        $tableName = $table->getName();
222
-        $primaryKeyColumns = $table->getPrimaryKeyColumns();
223
-
224
-        list($defaultSort, $defaultSortDirection) = $this->getDefaultSortColumnFromAnnotation($table);
225
-
226
-        // FIXME: lowercase tables with _ in the name should work!
227
-        $tableCamel = self::toSingular(self::toCamelCase($tableName));
228
-
229
-        $beanClassWithoutNameSpace = $beanClassName;
230
-        $beanClassName = $beannamespace.'\\'.$beanClassName;
231
-
232
-        list($usedBeans, $findByDaoCode) = $beanDescriptor->generateFindByDaoCode($beannamespace, $beanClassWithoutNameSpace);
233
-
234
-        $usedBeans[] = $beanClassName;
235
-        // Let's suppress duplicates in used beans (if any)
236
-        $usedBeans = array_flip(array_flip($usedBeans));
237
-        $useStatements = array_map(function ($usedBean) {
238
-            return "use $usedBean;\n";
239
-        }, $usedBeans);
240
-
241
-        $str = "<?php
173
+			$this->ensureDirectoryExist($possibleFileName);
174
+			file_put_contents($possibleFileName, $str);
175
+			@chmod($possibleFileName, 0664);
176
+		}
177
+	}
178
+
179
+	/**
180
+	 * Tries to find a @defaultSort annotation in one of the columns.
181
+	 *
182
+	 * @param Table $table
183
+	 *
184
+	 * @return array First item: column name, Second item: column order (asc/desc)
185
+	 */
186
+	private function getDefaultSortColumnFromAnnotation(Table $table)
187
+	{
188
+		$defaultSort = null;
189
+		$defaultSortDirection = null;
190
+		foreach ($table->getColumns() as $column) {
191
+			$comments = $column->getComment();
192
+			$matches = [];
193
+			if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) {
194
+				$defaultSort = $column->getName();
195
+				if (count($matches) === 3) {
196
+					$defaultSortDirection = $matches[2];
197
+				} else {
198
+					$defaultSortDirection = 'ASC';
199
+				}
200
+			}
201
+		}
202
+
203
+		return [$defaultSort, $defaultSortDirection];
204
+	}
205
+
206
+	/**
207
+	 * Writes the PHP bean DAO with simple functions to create/get/save objects.
208
+	 *
209
+	 * @param BeanDescriptor  $beanDescriptor
210
+	 * @param string          $className       The name of the class
211
+	 * @param string          $baseClassName
212
+	 * @param string          $beanClassName
213
+	 * @param Table           $table
214
+	 *
215
+	 * @throws TDBMException
216
+	 */
217
+	private function generateDao(BeanDescriptor $beanDescriptor, string $className, string $baseClassName, string $beanClassName, Table $table)
218
+	{
219
+		$daonamespace = $this->configuration->getDaoNamespace();
220
+		$beannamespace = $this->configuration->getBeanNamespace();
221
+		$tableName = $table->getName();
222
+		$primaryKeyColumns = $table->getPrimaryKeyColumns();
223
+
224
+		list($defaultSort, $defaultSortDirection) = $this->getDefaultSortColumnFromAnnotation($table);
225
+
226
+		// FIXME: lowercase tables with _ in the name should work!
227
+		$tableCamel = self::toSingular(self::toCamelCase($tableName));
228
+
229
+		$beanClassWithoutNameSpace = $beanClassName;
230
+		$beanClassName = $beannamespace.'\\'.$beanClassName;
231
+
232
+		list($usedBeans, $findByDaoCode) = $beanDescriptor->generateFindByDaoCode($beannamespace, $beanClassWithoutNameSpace);
233
+
234
+		$usedBeans[] = $beanClassName;
235
+		// Let's suppress duplicates in used beans (if any)
236
+		$usedBeans = array_flip(array_flip($usedBeans));
237
+		$useStatements = array_map(function ($usedBean) {
238
+			return "use $usedBean;\n";
239
+		}, $usedBeans);
240
+
241
+		$str = "<?php
242 242
 
243 243
 /*
244 244
  * This file has been automatically generated by TDBM.
@@ -314,10 +314,10 @@  discard block
 block discarded – undo
314 314
     }
315 315
     ";
316 316
 
317
-        if (count($primaryKeyColumns) === 1) {
318
-            $primaryKeyColumn = $primaryKeyColumns[0];
319
-            $primaryKeyPhpType = self::dbalTypeToPhpType($table->getColumn($primaryKeyColumn)->getType());
320
-            $str .= "
317
+		if (count($primaryKeyColumns) === 1) {
318
+			$primaryKeyColumn = $primaryKeyColumns[0];
319
+			$primaryKeyPhpType = self::dbalTypeToPhpType($table->getColumn($primaryKeyColumn)->getType());
320
+			$str .= "
321 321
     /**
322 322
      * Get $beanClassWithoutNameSpace specified by its ID (its primary key)
323 323
      * If the primary key does not exist, an exception is thrown.
@@ -332,8 +332,8 @@  discard block
 block discarded – undo
332 332
         return \$this->tdbmService->findObjectByPk('$tableName', ['$primaryKeyColumn' => \$id], [], \$lazyLoading);
333 333
     }
334 334
     ";
335
-        }
336
-        $str .= "
335
+		}
336
+		$str .= "
337 337
     /**
338 338
      * Deletes the $beanClassWithoutNameSpace passed in parameter.
339 339
      *
@@ -433,21 +433,21 @@  discard block
 block discarded – undo
433 433
     }
434 434
 ";
435 435
 
436
-        $str .= $findByDaoCode;
437
-        $str .= '}
436
+		$str .= $findByDaoCode;
437
+		$str .= '}
438 438
 ';
439 439
 
440
-        $possibleBaseFileName = $this->configuration->getPathFinder()->getPath($daonamespace.'\\Generated\\'.$baseClassName)->getPathname();
440
+		$possibleBaseFileName = $this->configuration->getPathFinder()->getPath($daonamespace.'\\Generated\\'.$baseClassName)->getPathname();
441 441
 
442
-        $this->ensureDirectoryExist($possibleBaseFileName);
443
-        file_put_contents($possibleBaseFileName, $str);
444
-        @chmod($possibleBaseFileName, 0664);
442
+		$this->ensureDirectoryExist($possibleBaseFileName);
443
+		file_put_contents($possibleBaseFileName, $str);
444
+		@chmod($possibleBaseFileName, 0664);
445 445
 
446
-        $possibleFileName = $this->configuration->getPathFinder()->getPath($daonamespace.'\\'.$className)->getPathname();
446
+		$possibleFileName = $this->configuration->getPathFinder()->getPath($daonamespace.'\\'.$className)->getPathname();
447 447
 
448
-        // Now, let's generate the "editable" class
449
-        if (!file_exists($possibleFileName)) {
450
-            $str = "<?php
448
+		// Now, let's generate the "editable" class
449
+		if (!file_exists($possibleFileName)) {
450
+			$str = "<?php
451 451
 
452 452
 /*
453 453
  * This file has been automatically generated by TDBM.
@@ -465,26 +465,26 @@  discard block
 block discarded – undo
465 465
 {
466 466
 }
467 467
 ";
468
-            $this->ensureDirectoryExist($possibleFileName);
469
-            file_put_contents($possibleFileName, $str);
470
-            @chmod($possibleFileName, 0664);
471
-        }
472
-    }
473
-
474
-    /**
475
-     * Generates the factory bean.
476
-     *
477
-     * @param Table[] $tableList
478
-     * @throws TDBMException
479
-     */
480
-    private function generateFactory(array $tableList) : void
481
-    {
482
-        $daoNamespace = $this->configuration->getDaoNamespace();
483
-        $daoFactoryClassName = $this->namingStrategy->getDaoFactoryClassName();
484
-
485
-        // For each table, let's write a property.
486
-
487
-        $str = "<?php
468
+			$this->ensureDirectoryExist($possibleFileName);
469
+			file_put_contents($possibleFileName, $str);
470
+			@chmod($possibleFileName, 0664);
471
+		}
472
+	}
473
+
474
+	/**
475
+	 * Generates the factory bean.
476
+	 *
477
+	 * @param Table[] $tableList
478
+	 * @throws TDBMException
479
+	 */
480
+	private function generateFactory(array $tableList) : void
481
+	{
482
+		$daoNamespace = $this->configuration->getDaoNamespace();
483
+		$daoFactoryClassName = $this->namingStrategy->getDaoFactoryClassName();
484
+
485
+		// For each table, let's write a property.
486
+
487
+		$str = "<?php
488 488
 
489 489
 /*
490 490
  * This file has been automatically generated by TDBM.
@@ -494,13 +494,13 @@  discard block
 block discarded – undo
494 494
 namespace {$daoNamespace}\\Generated;
495 495
 
496 496
 ";
497
-        foreach ($tableList as $table) {
498
-            $tableName = $table->getName();
499
-            $daoClassName = $this->namingStrategy->getDaoClassName($tableName);
500
-            $str .= "use {$daoNamespace}\\".$daoClassName.";\n";
501
-        }
497
+		foreach ($tableList as $table) {
498
+			$tableName = $table->getName();
499
+			$daoClassName = $this->namingStrategy->getDaoClassName($tableName);
500
+			$str .= "use {$daoNamespace}\\".$daoClassName.";\n";
501
+		}
502 502
 
503
-        $str .= "
503
+		$str .= "
504 504
 /**
505 505
  * The $daoFactoryClassName provides an easy access to all DAOs generated by TDBM.
506 506
  *
@@ -509,12 +509,12 @@  discard block
 block discarded – undo
509 509
 {
510 510
 ";
511 511
 
512
-        foreach ($tableList as $table) {
513
-            $tableName = $table->getName();
514
-            $daoClassName = $this->namingStrategy->getDaoClassName($tableName);
515
-            $daoInstanceName = self::toVariableName($daoClassName);
512
+		foreach ($tableList as $table) {
513
+			$tableName = $table->getName();
514
+			$daoClassName = $this->namingStrategy->getDaoClassName($tableName);
515
+			$daoInstanceName = self::toVariableName($daoClassName);
516 516
 
517
-            $str .= '    /**
517
+			$str .= '    /**
518 518
      * @var '.$daoClassName.'
519 519
      */
520 520
     private $'.$daoInstanceName.';
@@ -538,136 +538,136 @@  discard block
 block discarded – undo
538 538
     {
539 539
         $this->'.$daoInstanceName.' = $'.$daoInstanceName.';
540 540
     }';
541
-        }
541
+		}
542 542
 
543
-        $str .= '
543
+		$str .= '
544 544
 }
545 545
 ';
546 546
 
547
-        $possibleFileName = $this->configuration->getPathFinder()->getPath($daoNamespace.'\\Generated\\'.$daoFactoryClassName)->getPathname();
548
-
549
-        $this->ensureDirectoryExist($possibleFileName);
550
-        file_put_contents($possibleFileName, $str);
551
-        @chmod($possibleFileName, 0664);
552
-    }
553
-
554
-    /**
555
-     * Transforms a string to camelCase (except the first letter will be uppercase too).
556
-     * Underscores and spaces are removed and the first letter after the underscore is uppercased.
557
-     *
558
-     * @param $str string
559
-     *
560
-     * @return string
561
-     */
562
-    public static function toCamelCase($str)
563
-    {
564
-        $str = strtoupper(substr($str, 0, 1)).substr($str, 1);
565
-        while (true) {
566
-            if (strpos($str, '_') === false && strpos($str, ' ') === false) {
567
-                break;
568
-            }
569
-
570
-            $pos = strpos($str, '_');
571
-            if ($pos === false) {
572
-                $pos = strpos($str, ' ');
573
-            }
574
-            $before = substr($str, 0, $pos);
575
-            $after = substr($str, $pos + 1);
576
-            $str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1);
577
-        }
578
-
579
-        return $str;
580
-    }
581
-
582
-    /**
583
-     * Tries to put string to the singular form (if it is plural).
584
-     * We assume the table names are in english.
585
-     *
586
-     * @param $str string
587
-     *
588
-     * @return string
589
-     */
590
-    public static function toSingular($str)
591
-    {
592
-        return Inflector::singularize($str);
593
-    }
594
-
595
-    /**
596
-     * Put the first letter of the string in lower case.
597
-     * Very useful to transform a class name into a variable name.
598
-     *
599
-     * @param $str string
600
-     *
601
-     * @return string
602
-     */
603
-    public static function toVariableName($str)
604
-    {
605
-        return strtolower(substr($str, 0, 1)).substr($str, 1);
606
-    }
607
-
608
-    /**
609
-     * Ensures the file passed in parameter can be written in its directory.
610
-     *
611
-     * @param string $fileName
612
-     *
613
-     * @throws TDBMException
614
-     */
615
-    private function ensureDirectoryExist($fileName)
616
-    {
617
-        $dirName = dirname($fileName);
618
-        if (!file_exists($dirName)) {
619
-            $old = umask(0);
620
-            $result = mkdir($dirName, 0775, true);
621
-            umask($old);
622
-            if ($result === false) {
623
-                throw new TDBMException("Unable to create directory: '".$dirName."'.");
624
-            }
625
-        }
626
-    }
627
-
628
-    /**
629
-     * Absolute path to composer json file.
630
-     *
631
-     * @param string $composerFile
632
-     */
633
-    /*public function setComposerFile($composerFile)
547
+		$possibleFileName = $this->configuration->getPathFinder()->getPath($daoNamespace.'\\Generated\\'.$daoFactoryClassName)->getPathname();
548
+
549
+		$this->ensureDirectoryExist($possibleFileName);
550
+		file_put_contents($possibleFileName, $str);
551
+		@chmod($possibleFileName, 0664);
552
+	}
553
+
554
+	/**
555
+	 * Transforms a string to camelCase (except the first letter will be uppercase too).
556
+	 * Underscores and spaces are removed and the first letter after the underscore is uppercased.
557
+	 *
558
+	 * @param $str string
559
+	 *
560
+	 * @return string
561
+	 */
562
+	public static function toCamelCase($str)
563
+	{
564
+		$str = strtoupper(substr($str, 0, 1)).substr($str, 1);
565
+		while (true) {
566
+			if (strpos($str, '_') === false && strpos($str, ' ') === false) {
567
+				break;
568
+			}
569
+
570
+			$pos = strpos($str, '_');
571
+			if ($pos === false) {
572
+				$pos = strpos($str, ' ');
573
+			}
574
+			$before = substr($str, 0, $pos);
575
+			$after = substr($str, $pos + 1);
576
+			$str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1);
577
+		}
578
+
579
+		return $str;
580
+	}
581
+
582
+	/**
583
+	 * Tries to put string to the singular form (if it is plural).
584
+	 * We assume the table names are in english.
585
+	 *
586
+	 * @param $str string
587
+	 *
588
+	 * @return string
589
+	 */
590
+	public static function toSingular($str)
591
+	{
592
+		return Inflector::singularize($str);
593
+	}
594
+
595
+	/**
596
+	 * Put the first letter of the string in lower case.
597
+	 * Very useful to transform a class name into a variable name.
598
+	 *
599
+	 * @param $str string
600
+	 *
601
+	 * @return string
602
+	 */
603
+	public static function toVariableName($str)
604
+	{
605
+		return strtolower(substr($str, 0, 1)).substr($str, 1);
606
+	}
607
+
608
+	/**
609
+	 * Ensures the file passed in parameter can be written in its directory.
610
+	 *
611
+	 * @param string $fileName
612
+	 *
613
+	 * @throws TDBMException
614
+	 */
615
+	private function ensureDirectoryExist($fileName)
616
+	{
617
+		$dirName = dirname($fileName);
618
+		if (!file_exists($dirName)) {
619
+			$old = umask(0);
620
+			$result = mkdir($dirName, 0775, true);
621
+			umask($old);
622
+			if ($result === false) {
623
+				throw new TDBMException("Unable to create directory: '".$dirName."'.");
624
+			}
625
+		}
626
+	}
627
+
628
+	/**
629
+	 * Absolute path to composer json file.
630
+	 *
631
+	 * @param string $composerFile
632
+	 */
633
+	/*public function setComposerFile($composerFile)
634 634
     {
635 635
         $this->rootPath = dirname($composerFile).'/';
636 636
         $this->composerFile = basename($composerFile);
637 637
     }*/
638 638
 
639
-    /**
640
-     * Transforms a DBAL type into a PHP type (for PHPDoc purpose).
641
-     *
642
-     * @param Type $type The DBAL type
643
-     *
644
-     * @return string The PHP type
645
-     */
646
-    public static function dbalTypeToPhpType(Type $type)
647
-    {
648
-        $map = [
649
-            Type::TARRAY => 'array',
650
-            Type::SIMPLE_ARRAY => 'array',
651
-            'json' => 'array',  // 'json' is supported from Doctrine DBAL 2.6 only.
652
-            Type::JSON_ARRAY => 'array',
653
-            Type::BIGINT => 'string',
654
-            Type::BOOLEAN => 'bool',
655
-            Type::DATETIME => '\DateTimeInterface',
656
-            Type::DATETIMETZ => '\DateTimeInterface',
657
-            Type::DATE => '\DateTimeInterface',
658
-            Type::TIME => '\DateTimeInterface',
659
-            Type::DECIMAL => 'float',
660
-            Type::INTEGER => 'int',
661
-            Type::OBJECT => 'string',
662
-            Type::SMALLINT => 'int',
663
-            Type::STRING => 'string',
664
-            Type::TEXT => 'string',
665
-            Type::BINARY => 'string',
666
-            Type::BLOB => 'string',
667
-            Type::FLOAT => 'float',
668
-            Type::GUID => 'string',
669
-        ];
670
-
671
-        return isset($map[$type->getName()]) ? $map[$type->getName()] : $type->getName();
672
-    }
639
+	/**
640
+	 * Transforms a DBAL type into a PHP type (for PHPDoc purpose).
641
+	 *
642
+	 * @param Type $type The DBAL type
643
+	 *
644
+	 * @return string The PHP type
645
+	 */
646
+	public static function dbalTypeToPhpType(Type $type)
647
+	{
648
+		$map = [
649
+			Type::TARRAY => 'array',
650
+			Type::SIMPLE_ARRAY => 'array',
651
+			'json' => 'array',  // 'json' is supported from Doctrine DBAL 2.6 only.
652
+			Type::JSON_ARRAY => 'array',
653
+			Type::BIGINT => 'string',
654
+			Type::BOOLEAN => 'bool',
655
+			Type::DATETIME => '\DateTimeInterface',
656
+			Type::DATETIMETZ => '\DateTimeInterface',
657
+			Type::DATE => '\DateTimeInterface',
658
+			Type::TIME => '\DateTimeInterface',
659
+			Type::DECIMAL => 'float',
660
+			Type::INTEGER => 'int',
661
+			Type::OBJECT => 'string',
662
+			Type::SMALLINT => 'int',
663
+			Type::STRING => 'string',
664
+			Type::TEXT => 'string',
665
+			Type::BINARY => 'string',
666
+			Type::BLOB => 'string',
667
+			Type::FLOAT => 'float',
668
+			Type::GUID => 'string',
669
+		];
670
+
671
+		return isset($map[$type->getName()]) ? $map[$type->getName()] : $type->getName();
672
+	}
673 673
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Utils/PathFinder/PathFinderInterface.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@
 block discarded – undo
5 5
 
6 6
 interface PathFinderInterface
7 7
 {
8
-    /**
9
-     * Returns the path of a class file given the fully qualified class name.
10
-     *
11
-     * @param string $className
12
-     * @return \SplFileInfo
13
-     * @throws NoPathFoundException
14
-     */
15
-    public function getPath(string $className) : \SplFileInfo;
8
+	/**
9
+	 * Returns the path of a class file given the fully qualified class name.
10
+	 *
11
+	 * @param string $className
12
+	 * @return \SplFileInfo
13
+	 * @throws NoPathFoundException
14
+	 */
15
+	public function getPath(string $className) : \SplFileInfo;
16 16
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Utils/PathFinder/PathFinder.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -5,48 +5,48 @@
 block discarded – undo
5 5
 
6 6
 class PathFinder implements PathFinderInterface
7 7
 {
8
-    /**
9
-     * @var string
10
-     */
11
-    private $composerFile;
8
+	/**
9
+	 * @var string
10
+	 */
11
+	private $composerFile;
12 12
 
13
-    /**
14
-     * @var bool
15
-     */
16
-    private $useAutoloadDev;
13
+	/**
14
+	 * @var bool
15
+	 */
16
+	private $useAutoloadDev;
17 17
 
18
-    /**
19
-     * @var ClassNameMapper
20
-     */
21
-    private $classNameMapper;
18
+	/**
19
+	 * @var ClassNameMapper
20
+	 */
21
+	private $classNameMapper;
22 22
 
23
-    public function __construct(string $composerFile = null, bool $useAutoloadDev = false)
24
-    {
25
-        $this->composerFile = $composerFile;
26
-        $this->useAutoloadDev = $useAutoloadDev;
27
-    }
23
+	public function __construct(string $composerFile = null, bool $useAutoloadDev = false)
24
+	{
25
+		$this->composerFile = $composerFile;
26
+		$this->useAutoloadDev = $useAutoloadDev;
27
+	}
28 28
 
29
-    private function getClassNameMapper() : ClassNameMapper
30
-    {
31
-        if ($this->classNameMapper === null) {
32
-            $this->classNameMapper = ClassNameMapper::createFromComposerFile($this->composerFile, null, $this->useAutoloadDev);
33
-        }
34
-        return $this->classNameMapper;
35
-    }
29
+	private function getClassNameMapper() : ClassNameMapper
30
+	{
31
+		if ($this->classNameMapper === null) {
32
+			$this->classNameMapper = ClassNameMapper::createFromComposerFile($this->composerFile, null, $this->useAutoloadDev);
33
+		}
34
+		return $this->classNameMapper;
35
+	}
36 36
 
37
-    /**
38
-     * Returns the path of a class file given the fully qualified class name.
39
-     *
40
-     * @param string $className
41
-     * @return \SplFileInfo
42
-     * @throws NoPathFoundException
43
-     */
44
-    public function getPath(string $className): \SplFileInfo
45
-    {
46
-        $paths = $this->getClassNameMapper()->getPossibleFileNames($className);
47
-        if (empty($paths)) {
48
-            throw NoPathFoundException::create($className);
49
-        }
50
-        return new \SplFileInfo($paths[0]);
51
-    }
37
+	/**
38
+	 * Returns the path of a class file given the fully qualified class name.
39
+	 *
40
+	 * @param string $className
41
+	 * @return \SplFileInfo
42
+	 * @throws NoPathFoundException
43
+	 */
44
+	public function getPath(string $className): \SplFileInfo
45
+	{
46
+		$paths = $this->getClassNameMapper()->getPossibleFileNames($className);
47
+		if (empty($paths)) {
48
+			throw NoPathFoundException::create($className);
49
+		}
50
+		return new \SplFileInfo($paths[0]);
51
+	}
52 52
 }
Please login to merge, or discard this patch.