@@ -135,7 +135,7 @@ |
||
135 | 135 | return $configuration->getProperty($property)->getValue(); |
136 | 136 | } |
137 | 137 | |
138 | - private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ?string $value) |
|
138 | + private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ? string $value) |
|
139 | 139 | { |
140 | 140 | $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName); |
141 | 141 | if ($configuration === null) { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @Action |
83 | 83 | * |
84 | 84 | * @param string $name |
85 | - * @param bool $selfedit |
|
85 | + * @param string|boolean $selfedit |
|
86 | 86 | */ |
87 | 87 | public function generate($name, $daonamespace, $beannamespace, $daofactoryinstancename, /*$storeInUtc = 0,*/ $selfedit = 'false', $useCustomComposer = false, $composerFile = '') |
88 | 88 | { |
@@ -102,6 +102,8 @@ discard block |
||
102 | 102 | * @param string $daonamespace |
103 | 103 | * @param string $beannamespace |
104 | 104 | * @param string $selfedit |
105 | + * @param boolean $useCustomComposer |
|
106 | + * @param string $composerFile |
|
105 | 107 | * |
106 | 108 | * @throws \Mouf\MoufException |
107 | 109 | */ |
@@ -6,7 +6,6 @@ |
||
6 | 6 | use Mouf\Controllers\AbstractMoufInstanceController; |
7 | 7 | use Mouf\Database\TDBM\TDBMService; |
8 | 8 | use Mouf\Database\TDBM\Utils\PathFinder\PathFinder; |
9 | -use Mouf\Database\TDBM\Utils\TDBMDaoGenerator; |
|
10 | 9 | use Mouf\Html\HtmlElement\HtmlBlock; |
11 | 10 | use Mouf\MoufManager; |
12 | 11 | use Mouf\InstanceProxy; |
@@ -19,134 +19,134 @@ |
||
19 | 19 | */ |
20 | 20 | class TdbmController extends AbstractMoufInstanceController |
21 | 21 | { |
22 | - /** |
|
23 | - * @var HtmlBlock |
|
24 | - */ |
|
25 | - public $content; |
|
26 | - |
|
27 | - protected $daoNamespace; |
|
28 | - protected $beanNamespace; |
|
29 | - protected $daoFactoryInstanceName; |
|
30 | - protected $autoloadDetected; |
|
31 | - ///protected $storeInUtc; |
|
32 | - protected $useCustomComposer; |
|
33 | - protected $composerFile; |
|
34 | - |
|
35 | - /** |
|
36 | - * Admin page used to display the DAO generation form. |
|
37 | - * |
|
38 | - * @Action |
|
39 | - */ |
|
40 | - public function defaultAction($name, $selfedit = 'false') |
|
41 | - { |
|
42 | - $this->initController($name, $selfedit); |
|
43 | - |
|
44 | - // Fill variables |
|
45 | - $this->daoNamespace = self::getFromConfiguration($this->moufManager, $name, 'daoNamespace'); |
|
46 | - $this->beanNamespace = self::getFromConfiguration($this->moufManager, $name, 'beanNamespace'); |
|
47 | - $this->daoFactoryInstanceName = self::getFromConfiguration($this->moufManager, $name, 'daoFactoryInstanceName'); |
|
48 | - //$this->storeInUtc = self::getFromConfiguration($this->moufManager, $name, 'storeInUtc'); |
|
49 | - $pathFinder = self::getFromConfiguration($this->moufManager, $name, 'pathFinder'); |
|
50 | - if ($pathFinder !== null) { |
|
51 | - $this->composerFile = $pathFinder->getConstructorArgumentProperty('composerFile')->getValue(); |
|
52 | - } else { |
|
53 | - $this->composerFile = null; |
|
54 | - } |
|
55 | - $this->useCustomComposer = $this->composerFile ? true : false; |
|
56 | - |
|
57 | - if ($this->daoNamespace == null && $this->beanNamespace == null) { |
|
58 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
59 | - |
|
60 | - $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
61 | - if ($autoloadNamespaces) { |
|
62 | - $this->autoloadDetected = true; |
|
63 | - $rootNamespace = $autoloadNamespaces[0]; |
|
64 | - $this->daoNamespace = $rootNamespace.'Dao'; |
|
65 | - $this->beanNamespace = $rootNamespace.'Dao\\Bean'; |
|
66 | - } else { |
|
67 | - $this->autoloadDetected = false; |
|
68 | - $this->daoNamespace = 'YourApplication\\Dao'; |
|
69 | - $this->beanNamespace = 'YourApplication\\Dao\\Bean'; |
|
70 | - } |
|
71 | - } else { |
|
72 | - $this->autoloadDetected = true; |
|
73 | - } |
|
74 | - |
|
75 | - $this->content->addFile(__DIR__.'/../../../../views/tdbmGenerate.php', $this); |
|
76 | - $this->template->toHtml(); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * This action generates the DAOs and Beans for the TDBM service passed in parameter. |
|
81 | - * |
|
82 | - * @Action |
|
83 | - * |
|
84 | - * @param string $name |
|
85 | - * @param bool $selfedit |
|
86 | - */ |
|
87 | - public function generate($name, $daonamespace, $beannamespace, $daofactoryinstancename, /*$storeInUtc = 0,*/ $selfedit = 'false', $useCustomComposer = false, $composerFile = '') |
|
88 | - { |
|
89 | - $this->initController($name, $selfedit); |
|
90 | - |
|
91 | - self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit, /*$storeInUtc,*/ $useCustomComposer, $composerFile); |
|
92 | - |
|
93 | - // TODO: better: we should redirect to a screen that list the number of DAOs generated, etc... |
|
94 | - header('Location: '.ROOT_URL.'ajaxinstance/?name='.urlencode($name).'&selfedit='.$selfedit); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * This function generates the DAOs and Beans for the TDBM service passed in parameter. |
|
99 | - * |
|
100 | - * @param MoufManager $moufManager |
|
101 | - * @param string $name |
|
102 | - * @param string $daonamespace |
|
103 | - * @param string $beannamespace |
|
104 | - * @param string $selfedit |
|
105 | - * |
|
106 | - * @throws \Mouf\MoufException |
|
107 | - */ |
|
108 | - public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit = 'false', /*$storeInUtc = null,*/ $useCustomComposer = null, $composerFile = null) |
|
109 | - { |
|
110 | - self::setInConfiguration($moufManager, $name, 'daoNamespace', $daonamespace); |
|
111 | - self::setInConfiguration($moufManager, $name, 'beanNamespace', $beannamespace); |
|
112 | - self::setInConfiguration($moufManager, $name, 'daoFactoryInstanceName', $daofactoryinstancename); |
|
113 | - //self::setInConfiguration($moufManager, $name, 'storeInUtc', $storeInUtc); |
|
114 | - if ($useCustomComposer) { |
|
115 | - $pathFinder = $moufManager->createInstance(PathFinder::class); |
|
116 | - $pathFinder->getConstructorArgumentProperty('composerFile')->setValue($composerFile); |
|
117 | - self::setInConfiguration($moufManager, $name, 'pathFinder', $pathFinder); |
|
118 | - } else { |
|
119 | - self::setInConfiguration($moufManager, $name, 'pathFinder', null); |
|
120 | - } |
|
121 | - // Let's rewrite before calling the DAO generator |
|
122 | - $moufManager->rewriteMouf(); |
|
123 | - |
|
124 | - |
|
125 | - $tdbmService = new InstanceProxy($name); |
|
126 | - /* @var $tdbmService TDBMService */ |
|
127 | - $tdbmService->generateAllDaosAndBeans(); |
|
128 | - } |
|
129 | - |
|
130 | - private static function getConfigurationDescriptor(MoufManager $moufManager, string $tdbmInstanceName) |
|
131 | - { |
|
132 | - return $moufManager->getInstanceDescriptor($tdbmInstanceName)->getConstructorArgumentProperty('configuration')->getValue(); |
|
133 | - } |
|
134 | - |
|
135 | - private static function getFromConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property) |
|
136 | - { |
|
137 | - $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName); |
|
138 | - if ($configuration === null) { |
|
139 | - throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.'); |
|
140 | - } |
|
141 | - return $configuration->getProperty($property)->getValue(); |
|
142 | - } |
|
143 | - |
|
144 | - private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ?string $value) |
|
145 | - { |
|
146 | - $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName); |
|
147 | - if ($configuration === null) { |
|
148 | - throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.'); |
|
149 | - } |
|
150 | - $configuration->getProperty($property)->setValue($value); |
|
151 | - } |
|
22 | + /** |
|
23 | + * @var HtmlBlock |
|
24 | + */ |
|
25 | + public $content; |
|
26 | + |
|
27 | + protected $daoNamespace; |
|
28 | + protected $beanNamespace; |
|
29 | + protected $daoFactoryInstanceName; |
|
30 | + protected $autoloadDetected; |
|
31 | + ///protected $storeInUtc; |
|
32 | + protected $useCustomComposer; |
|
33 | + protected $composerFile; |
|
34 | + |
|
35 | + /** |
|
36 | + * Admin page used to display the DAO generation form. |
|
37 | + * |
|
38 | + * @Action |
|
39 | + */ |
|
40 | + public function defaultAction($name, $selfedit = 'false') |
|
41 | + { |
|
42 | + $this->initController($name, $selfedit); |
|
43 | + |
|
44 | + // Fill variables |
|
45 | + $this->daoNamespace = self::getFromConfiguration($this->moufManager, $name, 'daoNamespace'); |
|
46 | + $this->beanNamespace = self::getFromConfiguration($this->moufManager, $name, 'beanNamespace'); |
|
47 | + $this->daoFactoryInstanceName = self::getFromConfiguration($this->moufManager, $name, 'daoFactoryInstanceName'); |
|
48 | + //$this->storeInUtc = self::getFromConfiguration($this->moufManager, $name, 'storeInUtc'); |
|
49 | + $pathFinder = self::getFromConfiguration($this->moufManager, $name, 'pathFinder'); |
|
50 | + if ($pathFinder !== null) { |
|
51 | + $this->composerFile = $pathFinder->getConstructorArgumentProperty('composerFile')->getValue(); |
|
52 | + } else { |
|
53 | + $this->composerFile = null; |
|
54 | + } |
|
55 | + $this->useCustomComposer = $this->composerFile ? true : false; |
|
56 | + |
|
57 | + if ($this->daoNamespace == null && $this->beanNamespace == null) { |
|
58 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
59 | + |
|
60 | + $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
61 | + if ($autoloadNamespaces) { |
|
62 | + $this->autoloadDetected = true; |
|
63 | + $rootNamespace = $autoloadNamespaces[0]; |
|
64 | + $this->daoNamespace = $rootNamespace.'Dao'; |
|
65 | + $this->beanNamespace = $rootNamespace.'Dao\\Bean'; |
|
66 | + } else { |
|
67 | + $this->autoloadDetected = false; |
|
68 | + $this->daoNamespace = 'YourApplication\\Dao'; |
|
69 | + $this->beanNamespace = 'YourApplication\\Dao\\Bean'; |
|
70 | + } |
|
71 | + } else { |
|
72 | + $this->autoloadDetected = true; |
|
73 | + } |
|
74 | + |
|
75 | + $this->content->addFile(__DIR__.'/../../../../views/tdbmGenerate.php', $this); |
|
76 | + $this->template->toHtml(); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * This action generates the DAOs and Beans for the TDBM service passed in parameter. |
|
81 | + * |
|
82 | + * @Action |
|
83 | + * |
|
84 | + * @param string $name |
|
85 | + * @param bool $selfedit |
|
86 | + */ |
|
87 | + public function generate($name, $daonamespace, $beannamespace, $daofactoryinstancename, /*$storeInUtc = 0,*/ $selfedit = 'false', $useCustomComposer = false, $composerFile = '') |
|
88 | + { |
|
89 | + $this->initController($name, $selfedit); |
|
90 | + |
|
91 | + self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit, /*$storeInUtc,*/ $useCustomComposer, $composerFile); |
|
92 | + |
|
93 | + // TODO: better: we should redirect to a screen that list the number of DAOs generated, etc... |
|
94 | + header('Location: '.ROOT_URL.'ajaxinstance/?name='.urlencode($name).'&selfedit='.$selfedit); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * This function generates the DAOs and Beans for the TDBM service passed in parameter. |
|
99 | + * |
|
100 | + * @param MoufManager $moufManager |
|
101 | + * @param string $name |
|
102 | + * @param string $daonamespace |
|
103 | + * @param string $beannamespace |
|
104 | + * @param string $selfedit |
|
105 | + * |
|
106 | + * @throws \Mouf\MoufException |
|
107 | + */ |
|
108 | + public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit = 'false', /*$storeInUtc = null,*/ $useCustomComposer = null, $composerFile = null) |
|
109 | + { |
|
110 | + self::setInConfiguration($moufManager, $name, 'daoNamespace', $daonamespace); |
|
111 | + self::setInConfiguration($moufManager, $name, 'beanNamespace', $beannamespace); |
|
112 | + self::setInConfiguration($moufManager, $name, 'daoFactoryInstanceName', $daofactoryinstancename); |
|
113 | + //self::setInConfiguration($moufManager, $name, 'storeInUtc', $storeInUtc); |
|
114 | + if ($useCustomComposer) { |
|
115 | + $pathFinder = $moufManager->createInstance(PathFinder::class); |
|
116 | + $pathFinder->getConstructorArgumentProperty('composerFile')->setValue($composerFile); |
|
117 | + self::setInConfiguration($moufManager, $name, 'pathFinder', $pathFinder); |
|
118 | + } else { |
|
119 | + self::setInConfiguration($moufManager, $name, 'pathFinder', null); |
|
120 | + } |
|
121 | + // Let's rewrite before calling the DAO generator |
|
122 | + $moufManager->rewriteMouf(); |
|
123 | + |
|
124 | + |
|
125 | + $tdbmService = new InstanceProxy($name); |
|
126 | + /* @var $tdbmService TDBMService */ |
|
127 | + $tdbmService->generateAllDaosAndBeans(); |
|
128 | + } |
|
129 | + |
|
130 | + private static function getConfigurationDescriptor(MoufManager $moufManager, string $tdbmInstanceName) |
|
131 | + { |
|
132 | + return $moufManager->getInstanceDescriptor($tdbmInstanceName)->getConstructorArgumentProperty('configuration')->getValue(); |
|
133 | + } |
|
134 | + |
|
135 | + private static function getFromConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property) |
|
136 | + { |
|
137 | + $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName); |
|
138 | + if ($configuration === null) { |
|
139 | + throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.'); |
|
140 | + } |
|
141 | + return $configuration->getProperty($property)->getValue(); |
|
142 | + } |
|
143 | + |
|
144 | + private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ?string $value) |
|
145 | + { |
|
146 | + $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName); |
|
147 | + if ($configuration === null) { |
|
148 | + throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.'); |
|
149 | + } |
|
150 | + $configuration->getProperty($property)->setValue($value); |
|
151 | + } |
|
152 | 152 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | <input type="hidden" id="selfedit" name="selfedit" value="<?php echo plainstring_to_htmlprotected($this->selfedit) ?>" /> |
9 | 9 | |
10 | 10 | <?php if (!$this->autoloadDetected) { |
11 | - ?> |
|
11 | + ?> |
|
12 | 12 | <div class="alert">Warning! TDBM could not detect the autoload section of your composer.json file. |
13 | 13 | Unless you are developing your own autoload system, you should configure <strong>composer.json</strong> to <a href="http://getcomposer.org/doc/01-basic-usage.md#autoloading" target="_blank">define a source directory and a root namespace using PSR-0</a>.</div> |
14 | 14 | <?php |
@@ -11,58 +11,58 @@ |
||
11 | 11 | class MoufDiListener implements GeneratorListenerInterface |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param ConfigurationInterface $configuration |
|
16 | - * @param BeanDescriptorInterface[] $beanDescriptors |
|
17 | - */ |
|
18 | - public function onGenerate(ConfigurationInterface $configuration, array $beanDescriptors): void |
|
19 | - { |
|
20 | - // Let's generate the needed instance in Mouf. |
|
21 | - $moufManager = MoufManager::getMoufManager(); |
|
14 | + /** |
|
15 | + * @param ConfigurationInterface $configuration |
|
16 | + * @param BeanDescriptorInterface[] $beanDescriptors |
|
17 | + */ |
|
18 | + public function onGenerate(ConfigurationInterface $configuration, array $beanDescriptors): void |
|
19 | + { |
|
20 | + // Let's generate the needed instance in Mouf. |
|
21 | + $moufManager = MoufManager::getMoufManager(); |
|
22 | 22 | |
23 | - $daoFactoryInstanceName = null; |
|
24 | - if ($configuration instanceof MoufConfiguration) { |
|
25 | - $daoFactoryInstanceName = $configuration->getDaoFactoryInstanceName(); |
|
26 | - $daoFactoryClassName = $configuration->getDaoNamespace().'\\Generated\\'.$configuration->getNamingStrategy()->getDaoFactoryClassName(); |
|
27 | - $moufManager->declareComponent($daoFactoryInstanceName, $daoFactoryClassName, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS); |
|
28 | - } |
|
23 | + $daoFactoryInstanceName = null; |
|
24 | + if ($configuration instanceof MoufConfiguration) { |
|
25 | + $daoFactoryInstanceName = $configuration->getDaoFactoryInstanceName(); |
|
26 | + $daoFactoryClassName = $configuration->getDaoNamespace().'\\Generated\\'.$configuration->getNamingStrategy()->getDaoFactoryClassName(); |
|
27 | + $moufManager->declareComponent($daoFactoryInstanceName, $daoFactoryClassName, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS); |
|
28 | + } |
|
29 | 29 | |
30 | - $tdbmServiceInstanceName = $this->getTdbmInstanceName($configuration); |
|
30 | + $tdbmServiceInstanceName = $this->getTdbmInstanceName($configuration); |
|
31 | 31 | |
32 | - foreach ($beanDescriptors as $beanDescriptor) { |
|
33 | - $daoName = $beanDescriptor->getDaoClassName(); |
|
32 | + foreach ($beanDescriptors as $beanDescriptor) { |
|
33 | + $daoName = $beanDescriptor->getDaoClassName(); |
|
34 | 34 | |
35 | - $instanceName = TDBMDaoGenerator::toVariableName($daoName); |
|
36 | - if (!$moufManager->instanceExists($instanceName)) { |
|
37 | - $moufManager->declareComponent($instanceName, $configuration->getDaoNamespace().'\\'.$daoName); |
|
38 | - } |
|
39 | - $moufManager->setParameterViaConstructor($instanceName, 0, $tdbmServiceInstanceName, 'object'); |
|
40 | - if ($daoFactoryInstanceName !== null) { |
|
41 | - $moufManager->bindComponentViaSetter($daoFactoryInstanceName, 'set'.$daoName, $instanceName); |
|
42 | - } |
|
43 | - } |
|
35 | + $instanceName = TDBMDaoGenerator::toVariableName($daoName); |
|
36 | + if (!$moufManager->instanceExists($instanceName)) { |
|
37 | + $moufManager->declareComponent($instanceName, $configuration->getDaoNamespace().'\\'.$daoName); |
|
38 | + } |
|
39 | + $moufManager->setParameterViaConstructor($instanceName, 0, $tdbmServiceInstanceName, 'object'); |
|
40 | + if ($daoFactoryInstanceName !== null) { |
|
41 | + $moufManager->bindComponentViaSetter($daoFactoryInstanceName, 'set'.$daoName, $instanceName); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | - $moufManager->rewriteMouf(); |
|
46 | - } |
|
45 | + $moufManager->rewriteMouf(); |
|
46 | + } |
|
47 | 47 | |
48 | - private function getTdbmInstanceName(ConfigurationInterface $configuration) : string |
|
49 | - { |
|
50 | - $moufManager = MoufManager::getMoufManager(); |
|
48 | + private function getTdbmInstanceName(ConfigurationInterface $configuration) : string |
|
49 | + { |
|
50 | + $moufManager = MoufManager::getMoufManager(); |
|
51 | 51 | |
52 | - $configurationInstanceName = $moufManager->findInstanceName($configuration); |
|
53 | - if (!$configurationInstanceName) { |
|
54 | - throw new \TDBMException('Could not find TDBM instance for configuration object.'); |
|
55 | - } |
|
52 | + $configurationInstanceName = $moufManager->findInstanceName($configuration); |
|
53 | + if (!$configurationInstanceName) { |
|
54 | + throw new \TDBMException('Could not find TDBM instance for configuration object.'); |
|
55 | + } |
|
56 | 56 | |
57 | - // Let's find the configuration |
|
58 | - $tdbmServicesNames = $moufManager->findInstances(TDBMService::class); |
|
57 | + // Let's find the configuration |
|
58 | + $tdbmServicesNames = $moufManager->findInstances(TDBMService::class); |
|
59 | 59 | |
60 | - foreach ($tdbmServicesNames as $name) { |
|
61 | - if ($moufManager->getInstanceDescriptor($name)->getConstructorArgumentProperty('configuration')->getValue()->getName() === $configurationInstanceName) { |
|
62 | - return $name; |
|
63 | - } |
|
64 | - } |
|
60 | + foreach ($tdbmServicesNames as $name) { |
|
61 | + if ($moufManager->getInstanceDescriptor($name)->getConstructorArgumentProperty('configuration')->getValue()->getName() === $configurationInstanceName) { |
|
62 | + return $name; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - throw new \TDBMException('Could not find TDBMService instance.'); |
|
67 | - } |
|
66 | + throw new \TDBMException('Could not find TDBMService instance.'); |
|
67 | + } |
|
68 | 68 | } |
@@ -7,168 +7,168 @@ |
||
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 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | $alteredConf = new AlteredConfiguration($this->configuration); |
40 | 40 | |
41 | 41 | |
42 | - $loggers = [ new ConsoleLogger($output) ]; |
|
42 | + $loggers = [new ConsoleLogger($output)]; |
|
43 | 43 | |
44 | 44 | $logger = $alteredConf->getLogger(); |
45 | 45 | if ($logger) { |
@@ -12,48 +12,48 @@ |
||
12 | 12 | class GenerateCommand extends Command |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @var ConfigurationInterface |
|
17 | - */ |
|
18 | - private $configuration; |
|
15 | + /** |
|
16 | + * @var ConfigurationInterface |
|
17 | + */ |
|
18 | + private $configuration; |
|
19 | 19 | |
20 | - public function __construct(ConfigurationInterface $configuration) |
|
21 | - { |
|
22 | - parent::__construct(); |
|
23 | - $this->configuration = $configuration; |
|
24 | - } |
|
20 | + public function __construct(ConfigurationInterface $configuration) |
|
21 | + { |
|
22 | + parent::__construct(); |
|
23 | + $this->configuration = $configuration; |
|
24 | + } |
|
25 | 25 | |
26 | - protected function configure() |
|
27 | - { |
|
28 | - $this->setName('tdbm:generate') |
|
29 | - ->setDescription('Generates DAOs and beans.') |
|
30 | - ->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.') |
|
31 | - ; |
|
32 | - } |
|
26 | + protected function configure() |
|
27 | + { |
|
28 | + $this->setName('tdbm:generate') |
|
29 | + ->setDescription('Generates DAOs and beans.') |
|
30 | + ->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.') |
|
31 | + ; |
|
32 | + } |
|
33 | 33 | |
34 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
35 | - { |
|
36 | - // TODO: externalize composer.json file for autoloading (no more parameters for generateAllDaosAndBeans) |
|
34 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
35 | + { |
|
36 | + // TODO: externalize composer.json file for autoloading (no more parameters for generateAllDaosAndBeans) |
|
37 | 37 | |
38 | - $alteredConf = new AlteredConfiguration($this->configuration); |
|
38 | + $alteredConf = new AlteredConfiguration($this->configuration); |
|
39 | 39 | |
40 | 40 | |
41 | - $loggers = [ new ConsoleLogger($output) ]; |
|
41 | + $loggers = [ new ConsoleLogger($output) ]; |
|
42 | 42 | |
43 | - $logger = $alteredConf->getLogger(); |
|
44 | - if ($logger) { |
|
45 | - $loggers[] = $logger; |
|
46 | - } |
|
43 | + $logger = $alteredConf->getLogger(); |
|
44 | + if ($logger) { |
|
45 | + $loggers[] = $logger; |
|
46 | + } |
|
47 | 47 | |
48 | - $multiLogger = new MultiLogger($loggers); |
|
48 | + $multiLogger = new MultiLogger($loggers); |
|
49 | 49 | |
50 | - $alteredConf->setLogger($multiLogger); |
|
50 | + $alteredConf->setLogger($multiLogger); |
|
51 | 51 | |
52 | - $multiLogger->notice('Starting regenerating DAOs and beans'); |
|
52 | + $multiLogger->notice('Starting regenerating DAOs and beans'); |
|
53 | 53 | |
54 | - $tdbmService = new TDBMService($this->configuration); |
|
55 | - $tdbmService->generateAllDaosAndBeans(); |
|
54 | + $tdbmService = new TDBMService($this->configuration); |
|
55 | + $tdbmService->generateAllDaosAndBeans(); |
|
56 | 56 | |
57 | - $multiLogger->notice('Finished regenerating DAOs and beans'); |
|
58 | - } |
|
57 | + $multiLogger->notice('Finished regenerating DAOs and beans'); |
|
58 | + } |
|
59 | 59 | } |
@@ -135,7 +135,7 @@ |
||
135 | 135 | /** |
136 | 136 | * @return LoggerInterface |
137 | 137 | */ |
138 | - public function getLogger(): ?LoggerInterface |
|
138 | + public function getLogger(): ? LoggerInterface |
|
139 | 139 | { |
140 | 140 | return $this->logger; |
141 | 141 | } |
@@ -17,165 +17,165 @@ |
||
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 | - /** |
|
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->pathFinder = new PathFinder(); |
|
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 | - * Returns a class able to find the place of a PHP file based on the class name. |
|
165 | - * Useful to find the path where DAOs and beans should be written to. |
|
166 | - * |
|
167 | - * @return PathFinderInterface |
|
168 | - */ |
|
169 | - public function getPathFinder(): PathFinderInterface |
|
170 | - { |
|
171 | - return $this->pathFinder; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param PathFinderInterface $pathFinder |
|
176 | - */ |
|
177 | - public function setPathFinder(PathFinderInterface $pathFinder) |
|
178 | - { |
|
179 | - $this->pathFinder = $pathFinder; |
|
180 | - } |
|
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 | + /** |
|
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->pathFinder = new PathFinder(); |
|
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 | + * Returns a class able to find the place of a PHP file based on the class name. |
|
165 | + * Useful to find the path where DAOs and beans should be written to. |
|
166 | + * |
|
167 | + * @return PathFinderInterface |
|
168 | + */ |
|
169 | + public function getPathFinder(): PathFinderInterface |
|
170 | + { |
|
171 | + return $this->pathFinder; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param PathFinderInterface $pathFinder |
|
176 | + */ |
|
177 | + public function setPathFinder(PathFinderInterface $pathFinder) |
|
178 | + { |
|
179 | + $this->pathFinder = $pathFinder; |
|
180 | + } |
|
181 | 181 | } |
@@ -5,12 +5,12 @@ |
||
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 | } |
@@ -5,48 +5,48 @@ |
||
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 | } |
@@ -10,8 +10,8 @@ |
||
10 | 10 | */ |
11 | 11 | class NoPathFoundException extends TDBMException |
12 | 12 | { |
13 | - public static function create(string $className) |
|
14 | - { |
|
15 | - return new self(sprintf('Could not find a path where class %s would be autoloadable. Maybe consider editing your composer.json autoload section accordingly.', $className)); |
|
16 | - } |
|
13 | + public static function create(string $className) |
|
14 | + { |
|
15 | + return new self(sprintf('Could not find a path where class %s would be autoloadable. Maybe consider editing your composer.json autoload section accordingly.', $className)); |
|
16 | + } |
|
17 | 17 | } |