@@ -44,7 +44,7 @@ |
||
| 44 | 44 | /** |
| 45 | 45 | * @return LoggerInterface |
| 46 | 46 | */ |
| 47 | - public function getLogger(): ?LoggerInterface; |
|
| 47 | + public function getLogger(): ? LoggerInterface; |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @return GeneratorListenerInterface |
@@ -13,51 +13,51 @@ |
||
| 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 | } |
@@ -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 | } |
@@ -87,7 +87,7 @@ |
||
| 87 | 87 | /** |
| 88 | 88 | * @return LoggerInterface |
| 89 | 89 | */ |
| 90 | - public function getLogger(): ?LoggerInterface |
|
| 90 | + public function getLogger(): ? LoggerInterface |
|
| 91 | 91 | { |
| 92 | 92 | return $this->configuration->getLogger(); |
| 93 | 93 | } |
@@ -20,103 +20,103 @@ |
||
| 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 | } |
@@ -13,48 +13,48 @@ |
||
| 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 | } |
@@ -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) { |
@@ -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,171 +17,171 @@ |
||
| 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 | } |
@@ -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 | } |