@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @Action |
77 | 77 | * |
78 | 78 | * @param string $name |
79 | - * @param bool $selfedit |
|
79 | + * @param string|boolean $selfedit |
|
80 | 80 | */ |
81 | 81 | public function generate($name, $daonamespace, $beannamespace, $daofactoryinstancename, /*$storeInUtc = 0,*/ $selfedit = 'false', $useCustomComposer = false, $composerFile = '') |
82 | 82 | { |
@@ -95,9 +95,10 @@ discard block |
||
95 | 95 | * @param string $name |
96 | 96 | * @param string $daonamespace |
97 | 97 | * @param string $beannamespace |
98 | - * @param string $daofactoryclassname |
|
99 | 98 | * @param string $daofactoryinstancename |
100 | 99 | * @param string $selfedit |
100 | + * @param boolean $useCustomComposer |
|
101 | + * @param string $composerFile |
|
101 | 102 | * |
102 | 103 | * @throws \Mouf\MoufException |
103 | 104 | */ |
@@ -18,129 +18,129 @@ |
||
18 | 18 | */ |
19 | 19 | class TdbmController extends AbstractMoufInstanceController |
20 | 20 | { |
21 | - /** |
|
22 | - * @var HtmlBlock |
|
23 | - */ |
|
24 | - public $content; |
|
25 | - |
|
26 | - protected $daoNamespace; |
|
27 | - protected $beanNamespace; |
|
28 | - protected $daoFactoryInstanceName; |
|
29 | - protected $autoloadDetected; |
|
30 | - ///protected $storeInUtc; |
|
31 | - protected $useCustomComposer; |
|
32 | - protected $composerFile; |
|
33 | - |
|
34 | - /** |
|
35 | - * Admin page used to display the DAO generation form. |
|
36 | - * |
|
37 | - * @Action |
|
38 | - */ |
|
39 | - public function defaultAction($name, $selfedit = 'false') |
|
40 | - { |
|
41 | - $this->initController($name, $selfedit); |
|
42 | - |
|
43 | - // Fill variables |
|
44 | - $this->daoNamespace = self::getFromConfiguration($this->moufManager, $name, 'daoNamespace'); |
|
45 | - $this->beanNamespace = self::getFromConfiguration($this->moufManager, $name, 'beanNamespace'); |
|
46 | - $this->daoFactoryInstanceName = self::getFromConfiguration($this->moufManager, $name, 'daoFactoryInstanceName'); |
|
47 | - //$this->storeInUtc = self::getFromConfiguration($this->moufManager, $name, 'storeInUtc'); |
|
48 | - $this->composerFile = self::getFromConfiguration($this->moufManager, $name, 'customComposerFile'); |
|
49 | - $this->useCustomComposer = $this->composerFile ? true : false; |
|
50 | - |
|
51 | - if ($this->daoNamespace == null && $this->beanNamespace == null) { |
|
52 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
53 | - |
|
54 | - $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
55 | - if ($autoloadNamespaces) { |
|
56 | - $this->autoloadDetected = true; |
|
57 | - $rootNamespace = $autoloadNamespaces[0]; |
|
58 | - $this->daoNamespace = $rootNamespace.'Dao'; |
|
59 | - $this->beanNamespace = $rootNamespace.'Dao\\Bean'; |
|
60 | - } else { |
|
61 | - $this->autoloadDetected = false; |
|
62 | - $this->daoNamespace = 'YourApplication\\Dao'; |
|
63 | - $this->beanNamespace = 'YourApplication\\Dao\\Bean'; |
|
64 | - } |
|
65 | - } else { |
|
66 | - $this->autoloadDetected = true; |
|
67 | - } |
|
68 | - |
|
69 | - $this->content->addFile(__DIR__.'/../../../../views/tdbmGenerate.php', $this); |
|
70 | - $this->template->toHtml(); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * This action generates the DAOs and Beans for the TDBM service passed in parameter. |
|
75 | - * |
|
76 | - * @Action |
|
77 | - * |
|
78 | - * @param string $name |
|
79 | - * @param bool $selfedit |
|
80 | - */ |
|
81 | - public function generate($name, $daonamespace, $beannamespace, $daofactoryinstancename, /*$storeInUtc = 0,*/ $selfedit = 'false', $useCustomComposer = false, $composerFile = '') |
|
82 | - { |
|
83 | - $this->initController($name, $selfedit); |
|
84 | - |
|
85 | - self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit, /*$storeInUtc,*/ $useCustomComposer, $composerFile); |
|
86 | - |
|
87 | - // TODO: better: we should redirect to a screen that list the number of DAOs generated, etc... |
|
88 | - header('Location: '.ROOT_URL.'ajaxinstance/?name='.urlencode($name).'&selfedit='.$selfedit); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * This function generates the DAOs and Beans for the TDBM service passed in parameter. |
|
93 | - * |
|
94 | - * @param MoufManager $moufManager |
|
95 | - * @param string $name |
|
96 | - * @param string $daonamespace |
|
97 | - * @param string $beannamespace |
|
98 | - * @param string $daofactoryclassname |
|
99 | - * @param string $daofactoryinstancename |
|
100 | - * @param string $selfedit |
|
101 | - * |
|
102 | - * @throws \Mouf\MoufException |
|
103 | - */ |
|
104 | - public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit = 'false', /*$storeInUtc = null,*/ $useCustomComposer = null, $composerFile = null) |
|
105 | - { |
|
106 | - self::setInConfiguration($moufManager, $name, 'daoNamespace', $daonamespace); |
|
107 | - self::setInConfiguration($moufManager, $name, 'beanNamespace', $beannamespace); |
|
108 | - self::setInConfiguration($moufManager, $name, 'daoFactoryInstanceName', $daofactoryinstancename); |
|
109 | - //self::setInConfiguration($moufManager, $name, 'storeInUtc', $storeInUtc); |
|
110 | - if ($useCustomComposer) { |
|
111 | - self::setInConfiguration($moufManager, $name, 'customComposerFile', $composerFile); |
|
112 | - } else { |
|
113 | - self::setInConfiguration($moufManager, $name, 'customComposerFile', null); |
|
114 | - } |
|
115 | - // Let's rewrite before calling the DAO generator |
|
116 | - $moufManager->rewriteMouf(); |
|
117 | - |
|
118 | - |
|
119 | - $tdbmService = new InstanceProxy($name); |
|
120 | - /* @var $tdbmService TDBMService */ |
|
121 | - $tdbmService->generateAllDaosAndBeans(($useCustomComposer ? $composerFile : null)); |
|
122 | - } |
|
123 | - |
|
124 | - private static function getConfigurationDescriptor(MoufManager $moufManager, string $tdbmInstanceName) |
|
125 | - { |
|
126 | - return $moufManager->getInstanceDescriptor($tdbmInstanceName)->getConstructorArgumentProperty('configuration')->getValue(); |
|
127 | - } |
|
128 | - |
|
129 | - private static function getFromConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property) |
|
130 | - { |
|
131 | - $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName); |
|
132 | - if ($configuration === null) { |
|
133 | - throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.'); |
|
134 | - } |
|
135 | - return $configuration->getProperty($property)->getValue(); |
|
136 | - } |
|
137 | - |
|
138 | - private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ?string $value) |
|
139 | - { |
|
140 | - $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName); |
|
141 | - if ($configuration === null) { |
|
142 | - throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.'); |
|
143 | - } |
|
144 | - $configuration->getProperty($property)->setValue($value); |
|
145 | - } |
|
21 | + /** |
|
22 | + * @var HtmlBlock |
|
23 | + */ |
|
24 | + public $content; |
|
25 | + |
|
26 | + protected $daoNamespace; |
|
27 | + protected $beanNamespace; |
|
28 | + protected $daoFactoryInstanceName; |
|
29 | + protected $autoloadDetected; |
|
30 | + ///protected $storeInUtc; |
|
31 | + protected $useCustomComposer; |
|
32 | + protected $composerFile; |
|
33 | + |
|
34 | + /** |
|
35 | + * Admin page used to display the DAO generation form. |
|
36 | + * |
|
37 | + * @Action |
|
38 | + */ |
|
39 | + public function defaultAction($name, $selfedit = 'false') |
|
40 | + { |
|
41 | + $this->initController($name, $selfedit); |
|
42 | + |
|
43 | + // Fill variables |
|
44 | + $this->daoNamespace = self::getFromConfiguration($this->moufManager, $name, 'daoNamespace'); |
|
45 | + $this->beanNamespace = self::getFromConfiguration($this->moufManager, $name, 'beanNamespace'); |
|
46 | + $this->daoFactoryInstanceName = self::getFromConfiguration($this->moufManager, $name, 'daoFactoryInstanceName'); |
|
47 | + //$this->storeInUtc = self::getFromConfiguration($this->moufManager, $name, 'storeInUtc'); |
|
48 | + $this->composerFile = self::getFromConfiguration($this->moufManager, $name, 'customComposerFile'); |
|
49 | + $this->useCustomComposer = $this->composerFile ? true : false; |
|
50 | + |
|
51 | + if ($this->daoNamespace == null && $this->beanNamespace == null) { |
|
52 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
53 | + |
|
54 | + $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
55 | + if ($autoloadNamespaces) { |
|
56 | + $this->autoloadDetected = true; |
|
57 | + $rootNamespace = $autoloadNamespaces[0]; |
|
58 | + $this->daoNamespace = $rootNamespace.'Dao'; |
|
59 | + $this->beanNamespace = $rootNamespace.'Dao\\Bean'; |
|
60 | + } else { |
|
61 | + $this->autoloadDetected = false; |
|
62 | + $this->daoNamespace = 'YourApplication\\Dao'; |
|
63 | + $this->beanNamespace = 'YourApplication\\Dao\\Bean'; |
|
64 | + } |
|
65 | + } else { |
|
66 | + $this->autoloadDetected = true; |
|
67 | + } |
|
68 | + |
|
69 | + $this->content->addFile(__DIR__.'/../../../../views/tdbmGenerate.php', $this); |
|
70 | + $this->template->toHtml(); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * This action generates the DAOs and Beans for the TDBM service passed in parameter. |
|
75 | + * |
|
76 | + * @Action |
|
77 | + * |
|
78 | + * @param string $name |
|
79 | + * @param bool $selfedit |
|
80 | + */ |
|
81 | + public function generate($name, $daonamespace, $beannamespace, $daofactoryinstancename, /*$storeInUtc = 0,*/ $selfedit = 'false', $useCustomComposer = false, $composerFile = '') |
|
82 | + { |
|
83 | + $this->initController($name, $selfedit); |
|
84 | + |
|
85 | + self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit, /*$storeInUtc,*/ $useCustomComposer, $composerFile); |
|
86 | + |
|
87 | + // TODO: better: we should redirect to a screen that list the number of DAOs generated, etc... |
|
88 | + header('Location: '.ROOT_URL.'ajaxinstance/?name='.urlencode($name).'&selfedit='.$selfedit); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * This function generates the DAOs and Beans for the TDBM service passed in parameter. |
|
93 | + * |
|
94 | + * @param MoufManager $moufManager |
|
95 | + * @param string $name |
|
96 | + * @param string $daonamespace |
|
97 | + * @param string $beannamespace |
|
98 | + * @param string $daofactoryclassname |
|
99 | + * @param string $daofactoryinstancename |
|
100 | + * @param string $selfedit |
|
101 | + * |
|
102 | + * @throws \Mouf\MoufException |
|
103 | + */ |
|
104 | + public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryinstancename, $selfedit = 'false', /*$storeInUtc = null,*/ $useCustomComposer = null, $composerFile = null) |
|
105 | + { |
|
106 | + self::setInConfiguration($moufManager, $name, 'daoNamespace', $daonamespace); |
|
107 | + self::setInConfiguration($moufManager, $name, 'beanNamespace', $beannamespace); |
|
108 | + self::setInConfiguration($moufManager, $name, 'daoFactoryInstanceName', $daofactoryinstancename); |
|
109 | + //self::setInConfiguration($moufManager, $name, 'storeInUtc', $storeInUtc); |
|
110 | + if ($useCustomComposer) { |
|
111 | + self::setInConfiguration($moufManager, $name, 'customComposerFile', $composerFile); |
|
112 | + } else { |
|
113 | + self::setInConfiguration($moufManager, $name, 'customComposerFile', null); |
|
114 | + } |
|
115 | + // Let's rewrite before calling the DAO generator |
|
116 | + $moufManager->rewriteMouf(); |
|
117 | + |
|
118 | + |
|
119 | + $tdbmService = new InstanceProxy($name); |
|
120 | + /* @var $tdbmService TDBMService */ |
|
121 | + $tdbmService->generateAllDaosAndBeans(($useCustomComposer ? $composerFile : null)); |
|
122 | + } |
|
123 | + |
|
124 | + private static function getConfigurationDescriptor(MoufManager $moufManager, string $tdbmInstanceName) |
|
125 | + { |
|
126 | + return $moufManager->getInstanceDescriptor($tdbmInstanceName)->getConstructorArgumentProperty('configuration')->getValue(); |
|
127 | + } |
|
128 | + |
|
129 | + private static function getFromConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property) |
|
130 | + { |
|
131 | + $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName); |
|
132 | + if ($configuration === null) { |
|
133 | + throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.'); |
|
134 | + } |
|
135 | + return $configuration->getProperty($property)->getValue(); |
|
136 | + } |
|
137 | + |
|
138 | + private static function setInConfiguration(MoufManager $moufManager, string $tdbmInstanceName, string $property, ?string $value) |
|
139 | + { |
|
140 | + $configuration = self::getConfigurationDescriptor($moufManager, $tdbmInstanceName); |
|
141 | + if ($configuration === null) { |
|
142 | + throw new \RuntimeException('Unable to find the configuration object linked to TDBMService.'); |
|
143 | + } |
|
144 | + $configuration->getProperty($property)->setValue($value); |
|
145 | + } |
|
146 | 146 | } |
@@ -616,7 +616,7 @@ |
||
616 | 616 | * Tries to put string to the singular form (if it is plural). |
617 | 617 | * We assume the table names are in english. |
618 | 618 | * |
619 | - * @param $str string |
|
619 | + * @param string $str string |
|
620 | 620 | * |
621 | 621 | * @return string |
622 | 622 | */ |
@@ -18,157 +18,157 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class TDBMDaoGenerator |
20 | 20 | { |
21 | - /** |
|
22 | - * @var Schema |
|
23 | - */ |
|
24 | - private $schema; |
|
25 | - |
|
26 | - /** |
|
27 | - * The root directory of the project. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - private $rootPath; |
|
32 | - |
|
33 | - /** |
|
34 | - * Name of composer file. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private $composerFile; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var TDBMSchemaAnalyzer |
|
42 | - */ |
|
43 | - private $tdbmSchemaAnalyzer; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - private $eventDispatcher; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var NamingStrategyInterface |
|
52 | - */ |
|
53 | - private $namingStrategy; |
|
54 | - /** |
|
55 | - * @var ConfigurationInterface |
|
56 | - */ |
|
57 | - private $configuration; |
|
58 | - |
|
59 | - /** |
|
60 | - * Constructor. |
|
61 | - * |
|
62 | - * @param ConfigurationInterface $configuration |
|
63 | - * @param Schema $schema |
|
64 | - * @param TDBMSchemaAnalyzer $tdbmSchemaAnalyzer |
|
65 | - */ |
|
66 | - public function __construct(ConfigurationInterface $configuration, Schema $schema, TDBMSchemaAnalyzer $tdbmSchemaAnalyzer) |
|
67 | - { |
|
68 | - $this->configuration = $configuration; |
|
69 | - $this->schema = $schema; |
|
70 | - $this->tdbmSchemaAnalyzer = $tdbmSchemaAnalyzer; |
|
71 | - $this->rootPath = __DIR__.'/../../../../../../../../'; |
|
72 | - $this->composerFile = 'composer.json'; |
|
73 | - $this->namingStrategy = $configuration->getNamingStrategy(); |
|
74 | - $this->eventDispatcher = $configuration->getGeneratorEventDispatcher(); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Generates all the daos and beans. |
|
79 | - * |
|
80 | - * @throws TDBMException |
|
81 | - */ |
|
82 | - public function generateAllDaosAndBeans(): void |
|
83 | - { |
|
84 | - $classNameMapper = ClassNameMapper::createFromComposerFile($this->rootPath.$this->composerFile); |
|
85 | - // TODO: check that no class name ends with "Base". Otherwise, there will be name clash. |
|
86 | - |
|
87 | - $tableList = $this->schema->getTables(); |
|
88 | - |
|
89 | - // Remove all beans and daos from junction tables |
|
90 | - $junctionTables = $this->configuration->getSchemaAnalyzer()->detectJunctionTables(true); |
|
91 | - $junctionTableNames = array_map(function (Table $table) { |
|
92 | - return $table->getName(); |
|
93 | - }, $junctionTables); |
|
94 | - |
|
95 | - $tableList = array_filter($tableList, function (Table $table) use ($junctionTableNames) { |
|
96 | - return !in_array($table->getName(), $junctionTableNames); |
|
97 | - }); |
|
98 | - |
|
99 | - $beanDescriptors = []; |
|
100 | - |
|
101 | - foreach ($tableList as $table) { |
|
102 | - $beanDescriptors[] = $this->generateDaoAndBean($table, $classNameMapper); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - $this->generateFactory($tableList, $classNameMapper); |
|
107 | - |
|
108 | - // Let's call the list of listeners |
|
109 | - $this->eventDispatcher->onGenerate($this->configuration, $beanDescriptors); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Generates in one method call the daos and the beans for one table. |
|
114 | - * |
|
115 | - * @param Table $table |
|
116 | - * @param ClassNameMapper $classNameMapper |
|
117 | - * |
|
118 | - * @return BeanDescriptor |
|
119 | - * @throws TDBMException |
|
120 | - */ |
|
121 | - private function generateDaoAndBean(Table $table, ClassNameMapper $classNameMapper) : BeanDescriptor |
|
122 | - { |
|
123 | - // TODO: $storeInUtc is NOT USED. |
|
124 | - $tableName = $table->getName(); |
|
125 | - $daoName = $this->namingStrategy->getDaoClassName($tableName); |
|
126 | - $beanName = $this->namingStrategy->getBeanClassName($tableName); |
|
127 | - $baseBeanName = $this->namingStrategy->getBaseBeanClassName($tableName); |
|
128 | - $baseDaoName = $this->namingStrategy->getBaseDaoClassName($tableName); |
|
129 | - |
|
130 | - $beanDescriptor = new BeanDescriptor($table, $this->configuration->getSchemaAnalyzer(), $this->schema, $this->tdbmSchemaAnalyzer, $this->namingStrategy); |
|
131 | - $this->generateBean($beanDescriptor, $beanName, $baseBeanName, $table, $classNameMapper); |
|
132 | - $this->generateDao($beanDescriptor, $daoName, $baseDaoName, $beanName, $table, $classNameMapper); |
|
133 | - return $beanDescriptor; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Writes the PHP bean file with all getters and setters from the table passed in parameter. |
|
138 | - * |
|
139 | - * @param BeanDescriptor $beanDescriptor |
|
140 | - * @param string $className The name of the class |
|
141 | - * @param string $baseClassName The name of the base class which will be extended (name only, no directory) |
|
142 | - * @param Table $table The table |
|
143 | - * @param ClassNameMapper $classNameMapper |
|
144 | - * |
|
145 | - * @throws TDBMException |
|
146 | - */ |
|
147 | - public function generateBean(BeanDescriptor $beanDescriptor, $className, $baseClassName, Table $table, ClassNameMapper $classNameMapper) |
|
148 | - { |
|
149 | - $beannamespace = $this->configuration->getBeanNamespace(); |
|
150 | - $str = $beanDescriptor->generatePhpCode($beannamespace); |
|
151 | - |
|
152 | - $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($beannamespace.'\\Generated\\'.$baseClassName); |
|
153 | - if (empty($possibleBaseFileNames)) { |
|
154 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace.'\\'.$baseClassName.'" is not autoloadable.'); |
|
155 | - } |
|
156 | - $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0]; |
|
157 | - |
|
158 | - $this->ensureDirectoryExist($possibleBaseFileName); |
|
159 | - file_put_contents($possibleBaseFileName, $str); |
|
160 | - @chmod($possibleBaseFileName, 0664); |
|
161 | - |
|
162 | - $possibleFileNames = $classNameMapper->getPossibleFileNames($beannamespace.'\\'.$className); |
|
163 | - if (empty($possibleFileNames)) { |
|
164 | - // @codeCoverageIgnoreStart |
|
165 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace.'\\'.$className.'" is not autoloadable.'); |
|
166 | - // @codeCoverageIgnoreEnd |
|
167 | - } |
|
168 | - $possibleFileName = $this->rootPath.$possibleFileNames[0]; |
|
169 | - if (!file_exists($possibleFileName)) { |
|
170 | - $tableName = $table->getName(); |
|
171 | - $str = "<?php |
|
21 | + /** |
|
22 | + * @var Schema |
|
23 | + */ |
|
24 | + private $schema; |
|
25 | + |
|
26 | + /** |
|
27 | + * The root directory of the project. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + private $rootPath; |
|
32 | + |
|
33 | + /** |
|
34 | + * Name of composer file. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private $composerFile; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var TDBMSchemaAnalyzer |
|
42 | + */ |
|
43 | + private $tdbmSchemaAnalyzer; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + private $eventDispatcher; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var NamingStrategyInterface |
|
52 | + */ |
|
53 | + private $namingStrategy; |
|
54 | + /** |
|
55 | + * @var ConfigurationInterface |
|
56 | + */ |
|
57 | + private $configuration; |
|
58 | + |
|
59 | + /** |
|
60 | + * Constructor. |
|
61 | + * |
|
62 | + * @param ConfigurationInterface $configuration |
|
63 | + * @param Schema $schema |
|
64 | + * @param TDBMSchemaAnalyzer $tdbmSchemaAnalyzer |
|
65 | + */ |
|
66 | + public function __construct(ConfigurationInterface $configuration, Schema $schema, TDBMSchemaAnalyzer $tdbmSchemaAnalyzer) |
|
67 | + { |
|
68 | + $this->configuration = $configuration; |
|
69 | + $this->schema = $schema; |
|
70 | + $this->tdbmSchemaAnalyzer = $tdbmSchemaAnalyzer; |
|
71 | + $this->rootPath = __DIR__.'/../../../../../../../../'; |
|
72 | + $this->composerFile = 'composer.json'; |
|
73 | + $this->namingStrategy = $configuration->getNamingStrategy(); |
|
74 | + $this->eventDispatcher = $configuration->getGeneratorEventDispatcher(); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Generates all the daos and beans. |
|
79 | + * |
|
80 | + * @throws TDBMException |
|
81 | + */ |
|
82 | + public function generateAllDaosAndBeans(): void |
|
83 | + { |
|
84 | + $classNameMapper = ClassNameMapper::createFromComposerFile($this->rootPath.$this->composerFile); |
|
85 | + // TODO: check that no class name ends with "Base". Otherwise, there will be name clash. |
|
86 | + |
|
87 | + $tableList = $this->schema->getTables(); |
|
88 | + |
|
89 | + // Remove all beans and daos from junction tables |
|
90 | + $junctionTables = $this->configuration->getSchemaAnalyzer()->detectJunctionTables(true); |
|
91 | + $junctionTableNames = array_map(function (Table $table) { |
|
92 | + return $table->getName(); |
|
93 | + }, $junctionTables); |
|
94 | + |
|
95 | + $tableList = array_filter($tableList, function (Table $table) use ($junctionTableNames) { |
|
96 | + return !in_array($table->getName(), $junctionTableNames); |
|
97 | + }); |
|
98 | + |
|
99 | + $beanDescriptors = []; |
|
100 | + |
|
101 | + foreach ($tableList as $table) { |
|
102 | + $beanDescriptors[] = $this->generateDaoAndBean($table, $classNameMapper); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + $this->generateFactory($tableList, $classNameMapper); |
|
107 | + |
|
108 | + // Let's call the list of listeners |
|
109 | + $this->eventDispatcher->onGenerate($this->configuration, $beanDescriptors); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Generates in one method call the daos and the beans for one table. |
|
114 | + * |
|
115 | + * @param Table $table |
|
116 | + * @param ClassNameMapper $classNameMapper |
|
117 | + * |
|
118 | + * @return BeanDescriptor |
|
119 | + * @throws TDBMException |
|
120 | + */ |
|
121 | + private function generateDaoAndBean(Table $table, ClassNameMapper $classNameMapper) : BeanDescriptor |
|
122 | + { |
|
123 | + // TODO: $storeInUtc is NOT USED. |
|
124 | + $tableName = $table->getName(); |
|
125 | + $daoName = $this->namingStrategy->getDaoClassName($tableName); |
|
126 | + $beanName = $this->namingStrategy->getBeanClassName($tableName); |
|
127 | + $baseBeanName = $this->namingStrategy->getBaseBeanClassName($tableName); |
|
128 | + $baseDaoName = $this->namingStrategy->getBaseDaoClassName($tableName); |
|
129 | + |
|
130 | + $beanDescriptor = new BeanDescriptor($table, $this->configuration->getSchemaAnalyzer(), $this->schema, $this->tdbmSchemaAnalyzer, $this->namingStrategy); |
|
131 | + $this->generateBean($beanDescriptor, $beanName, $baseBeanName, $table, $classNameMapper); |
|
132 | + $this->generateDao($beanDescriptor, $daoName, $baseDaoName, $beanName, $table, $classNameMapper); |
|
133 | + return $beanDescriptor; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Writes the PHP bean file with all getters and setters from the table passed in parameter. |
|
138 | + * |
|
139 | + * @param BeanDescriptor $beanDescriptor |
|
140 | + * @param string $className The name of the class |
|
141 | + * @param string $baseClassName The name of the base class which will be extended (name only, no directory) |
|
142 | + * @param Table $table The table |
|
143 | + * @param ClassNameMapper $classNameMapper |
|
144 | + * |
|
145 | + * @throws TDBMException |
|
146 | + */ |
|
147 | + public function generateBean(BeanDescriptor $beanDescriptor, $className, $baseClassName, Table $table, ClassNameMapper $classNameMapper) |
|
148 | + { |
|
149 | + $beannamespace = $this->configuration->getBeanNamespace(); |
|
150 | + $str = $beanDescriptor->generatePhpCode($beannamespace); |
|
151 | + |
|
152 | + $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($beannamespace.'\\Generated\\'.$baseClassName); |
|
153 | + if (empty($possibleBaseFileNames)) { |
|
154 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace.'\\'.$baseClassName.'" is not autoloadable.'); |
|
155 | + } |
|
156 | + $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0]; |
|
157 | + |
|
158 | + $this->ensureDirectoryExist($possibleBaseFileName); |
|
159 | + file_put_contents($possibleBaseFileName, $str); |
|
160 | + @chmod($possibleBaseFileName, 0664); |
|
161 | + |
|
162 | + $possibleFileNames = $classNameMapper->getPossibleFileNames($beannamespace.'\\'.$className); |
|
163 | + if (empty($possibleFileNames)) { |
|
164 | + // @codeCoverageIgnoreStart |
|
165 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace.'\\'.$className.'" is not autoloadable.'); |
|
166 | + // @codeCoverageIgnoreEnd |
|
167 | + } |
|
168 | + $possibleFileName = $this->rootPath.$possibleFileNames[0]; |
|
169 | + if (!file_exists($possibleFileName)) { |
|
170 | + $tableName = $table->getName(); |
|
171 | + $str = "<?php |
|
172 | 172 | /* |
173 | 173 | * This file has been automatically generated by TDBM. |
174 | 174 | * You can edit this file as it will not be overwritten. |
@@ -185,76 +185,76 @@ discard block |
||
185 | 185 | { |
186 | 186 | } |
187 | 187 | "; |
188 | - $this->ensureDirectoryExist($possibleFileName); |
|
189 | - file_put_contents($possibleFileName, $str); |
|
190 | - @chmod($possibleFileName, 0664); |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Tries to find a @defaultSort annotation in one of the columns. |
|
196 | - * |
|
197 | - * @param Table $table |
|
198 | - * |
|
199 | - * @return array First item: column name, Second item: column order (asc/desc) |
|
200 | - */ |
|
201 | - private function getDefaultSortColumnFromAnnotation(Table $table) |
|
202 | - { |
|
203 | - $defaultSort = null; |
|
204 | - $defaultSortDirection = null; |
|
205 | - foreach ($table->getColumns() as $column) { |
|
206 | - $comments = $column->getComment(); |
|
207 | - $matches = []; |
|
208 | - if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) { |
|
209 | - $defaultSort = $column->getName(); |
|
210 | - if (count($matches) === 3) { |
|
211 | - $defaultSortDirection = $matches[2]; |
|
212 | - } else { |
|
213 | - $defaultSortDirection = 'ASC'; |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - return [$defaultSort, $defaultSortDirection]; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Writes the PHP bean DAO with simple functions to create/get/save objects. |
|
223 | - * |
|
224 | - * @param BeanDescriptor $beanDescriptor |
|
225 | - * @param string $className The name of the class |
|
226 | - * @param string $baseClassName |
|
227 | - * @param string $beanClassName |
|
228 | - * @param Table $table |
|
229 | - * @param ClassNameMapper $classNameMapper |
|
230 | - * |
|
231 | - * @throws TDBMException |
|
232 | - */ |
|
233 | - private function generateDao(BeanDescriptor $beanDescriptor, string $className, string $baseClassName, string $beanClassName, Table $table, ClassNameMapper $classNameMapper) |
|
234 | - { |
|
235 | - $daonamespace = $this->configuration->getDaoNamespace(); |
|
236 | - $beannamespace = $this->configuration->getBeanNamespace(); |
|
237 | - $tableName = $table->getName(); |
|
238 | - $primaryKeyColumns = $table->getPrimaryKeyColumns(); |
|
239 | - |
|
240 | - list($defaultSort, $defaultSortDirection) = $this->getDefaultSortColumnFromAnnotation($table); |
|
241 | - |
|
242 | - // FIXME: lowercase tables with _ in the name should work! |
|
243 | - $tableCamel = self::toSingular(self::toCamelCase($tableName)); |
|
244 | - |
|
245 | - $beanClassWithoutNameSpace = $beanClassName; |
|
246 | - $beanClassName = $beannamespace.'\\'.$beanClassName; |
|
247 | - |
|
248 | - list($usedBeans, $findByDaoCode) = $beanDescriptor->generateFindByDaoCode($beannamespace, $beanClassWithoutNameSpace); |
|
249 | - |
|
250 | - $usedBeans[] = $beanClassName; |
|
251 | - // Let's suppress duplicates in used beans (if any) |
|
252 | - $usedBeans = array_flip(array_flip($usedBeans)); |
|
253 | - $useStatements = array_map(function ($usedBean) { |
|
254 | - return "use $usedBean;\n"; |
|
255 | - }, $usedBeans); |
|
256 | - |
|
257 | - $str = "<?php |
|
188 | + $this->ensureDirectoryExist($possibleFileName); |
|
189 | + file_put_contents($possibleFileName, $str); |
|
190 | + @chmod($possibleFileName, 0664); |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Tries to find a @defaultSort annotation in one of the columns. |
|
196 | + * |
|
197 | + * @param Table $table |
|
198 | + * |
|
199 | + * @return array First item: column name, Second item: column order (asc/desc) |
|
200 | + */ |
|
201 | + private function getDefaultSortColumnFromAnnotation(Table $table) |
|
202 | + { |
|
203 | + $defaultSort = null; |
|
204 | + $defaultSortDirection = null; |
|
205 | + foreach ($table->getColumns() as $column) { |
|
206 | + $comments = $column->getComment(); |
|
207 | + $matches = []; |
|
208 | + if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) { |
|
209 | + $defaultSort = $column->getName(); |
|
210 | + if (count($matches) === 3) { |
|
211 | + $defaultSortDirection = $matches[2]; |
|
212 | + } else { |
|
213 | + $defaultSortDirection = 'ASC'; |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + return [$defaultSort, $defaultSortDirection]; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Writes the PHP bean DAO with simple functions to create/get/save objects. |
|
223 | + * |
|
224 | + * @param BeanDescriptor $beanDescriptor |
|
225 | + * @param string $className The name of the class |
|
226 | + * @param string $baseClassName |
|
227 | + * @param string $beanClassName |
|
228 | + * @param Table $table |
|
229 | + * @param ClassNameMapper $classNameMapper |
|
230 | + * |
|
231 | + * @throws TDBMException |
|
232 | + */ |
|
233 | + private function generateDao(BeanDescriptor $beanDescriptor, string $className, string $baseClassName, string $beanClassName, Table $table, ClassNameMapper $classNameMapper) |
|
234 | + { |
|
235 | + $daonamespace = $this->configuration->getDaoNamespace(); |
|
236 | + $beannamespace = $this->configuration->getBeanNamespace(); |
|
237 | + $tableName = $table->getName(); |
|
238 | + $primaryKeyColumns = $table->getPrimaryKeyColumns(); |
|
239 | + |
|
240 | + list($defaultSort, $defaultSortDirection) = $this->getDefaultSortColumnFromAnnotation($table); |
|
241 | + |
|
242 | + // FIXME: lowercase tables with _ in the name should work! |
|
243 | + $tableCamel = self::toSingular(self::toCamelCase($tableName)); |
|
244 | + |
|
245 | + $beanClassWithoutNameSpace = $beanClassName; |
|
246 | + $beanClassName = $beannamespace.'\\'.$beanClassName; |
|
247 | + |
|
248 | + list($usedBeans, $findByDaoCode) = $beanDescriptor->generateFindByDaoCode($beannamespace, $beanClassWithoutNameSpace); |
|
249 | + |
|
250 | + $usedBeans[] = $beanClassName; |
|
251 | + // Let's suppress duplicates in used beans (if any) |
|
252 | + $usedBeans = array_flip(array_flip($usedBeans)); |
|
253 | + $useStatements = array_map(function ($usedBean) { |
|
254 | + return "use $usedBean;\n"; |
|
255 | + }, $usedBeans); |
|
256 | + |
|
257 | + $str = "<?php |
|
258 | 258 | |
259 | 259 | /* |
260 | 260 | * This file has been automatically generated by TDBM. |
@@ -330,10 +330,10 @@ discard block |
||
330 | 330 | } |
331 | 331 | "; |
332 | 332 | |
333 | - if (count($primaryKeyColumns) === 1) { |
|
334 | - $primaryKeyColumn = $primaryKeyColumns[0]; |
|
335 | - $primaryKeyPhpType = self::dbalTypeToPhpType($table->getColumn($primaryKeyColumn)->getType()); |
|
336 | - $str .= " |
|
333 | + if (count($primaryKeyColumns) === 1) { |
|
334 | + $primaryKeyColumn = $primaryKeyColumns[0]; |
|
335 | + $primaryKeyPhpType = self::dbalTypeToPhpType($table->getColumn($primaryKeyColumn)->getType()); |
|
336 | + $str .= " |
|
337 | 337 | /** |
338 | 338 | * Get $beanClassWithoutNameSpace specified by its ID (its primary key) |
339 | 339 | * If the primary key does not exist, an exception is thrown. |
@@ -348,8 +348,8 @@ discard block |
||
348 | 348 | return \$this->tdbmService->findObjectByPk('$tableName', ['$primaryKeyColumn' => \$id], [], \$lazyLoading); |
349 | 349 | } |
350 | 350 | "; |
351 | - } |
|
352 | - $str .= " |
|
351 | + } |
|
352 | + $str .= " |
|
353 | 353 | /** |
354 | 354 | * Deletes the $beanClassWithoutNameSpace passed in parameter. |
355 | 355 | * |
@@ -449,33 +449,33 @@ discard block |
||
449 | 449 | } |
450 | 450 | "; |
451 | 451 | |
452 | - $str .= $findByDaoCode; |
|
453 | - $str .= '} |
|
452 | + $str .= $findByDaoCode; |
|
453 | + $str .= '} |
|
454 | 454 | '; |
455 | 455 | |
456 | - $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($daonamespace.'\\Generated\\'.$baseClassName); |
|
457 | - if (empty($possibleBaseFileNames)) { |
|
458 | - // @codeCoverageIgnoreStart |
|
459 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daonamespace.'\\Generated\\'.$baseClassName.'" is not autoloadable.'); |
|
460 | - // @codeCoverageIgnoreEnd |
|
461 | - } |
|
462 | - $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0]; |
|
463 | - |
|
464 | - $this->ensureDirectoryExist($possibleBaseFileName); |
|
465 | - file_put_contents($possibleBaseFileName, $str); |
|
466 | - @chmod($possibleBaseFileName, 0664); |
|
467 | - |
|
468 | - $possibleFileNames = $classNameMapper->getPossibleFileNames($daonamespace.'\\'.$className); |
|
469 | - if (empty($possibleFileNames)) { |
|
470 | - // @codeCoverageIgnoreStart |
|
471 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daonamespace.'\\'.$className.'" is not autoloadable.'); |
|
472 | - // @codeCoverageIgnoreEnd |
|
473 | - } |
|
474 | - $possibleFileName = $this->rootPath.$possibleFileNames[0]; |
|
475 | - |
|
476 | - // Now, let's generate the "editable" class |
|
477 | - if (!file_exists($possibleFileName)) { |
|
478 | - $str = "<?php |
|
456 | + $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($daonamespace.'\\Generated\\'.$baseClassName); |
|
457 | + if (empty($possibleBaseFileNames)) { |
|
458 | + // @codeCoverageIgnoreStart |
|
459 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daonamespace.'\\Generated\\'.$baseClassName.'" is not autoloadable.'); |
|
460 | + // @codeCoverageIgnoreEnd |
|
461 | + } |
|
462 | + $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0]; |
|
463 | + |
|
464 | + $this->ensureDirectoryExist($possibleBaseFileName); |
|
465 | + file_put_contents($possibleBaseFileName, $str); |
|
466 | + @chmod($possibleBaseFileName, 0664); |
|
467 | + |
|
468 | + $possibleFileNames = $classNameMapper->getPossibleFileNames($daonamespace.'\\'.$className); |
|
469 | + if (empty($possibleFileNames)) { |
|
470 | + // @codeCoverageIgnoreStart |
|
471 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daonamespace.'\\'.$className.'" is not autoloadable.'); |
|
472 | + // @codeCoverageIgnoreEnd |
|
473 | + } |
|
474 | + $possibleFileName = $this->rootPath.$possibleFileNames[0]; |
|
475 | + |
|
476 | + // Now, let's generate the "editable" class |
|
477 | + if (!file_exists($possibleFileName)) { |
|
478 | + $str = "<?php |
|
479 | 479 | |
480 | 480 | /* |
481 | 481 | * This file has been automatically generated by TDBM. |
@@ -493,27 +493,27 @@ discard block |
||
493 | 493 | { |
494 | 494 | } |
495 | 495 | "; |
496 | - $this->ensureDirectoryExist($possibleFileName); |
|
497 | - file_put_contents($possibleFileName, $str); |
|
498 | - @chmod($possibleFileName, 0664); |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Generates the factory bean. |
|
504 | - * |
|
505 | - * @param Table[] $tableList |
|
506 | - * @param ClassNameMapper $classNameMapper |
|
507 | - * @throws TDBMException |
|
508 | - */ |
|
509 | - private function generateFactory(array $tableList, ClassNameMapper $classNameMapper) : void |
|
510 | - { |
|
511 | - $daoNamespace = $this->configuration->getDaoNamespace(); |
|
512 | - $daoFactoryClassName = $this->namingStrategy->getDaoFactoryClassName(); |
|
513 | - |
|
514 | - // For each table, let's write a property. |
|
515 | - |
|
516 | - $str = "<?php |
|
496 | + $this->ensureDirectoryExist($possibleFileName); |
|
497 | + file_put_contents($possibleFileName, $str); |
|
498 | + @chmod($possibleFileName, 0664); |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Generates the factory bean. |
|
504 | + * |
|
505 | + * @param Table[] $tableList |
|
506 | + * @param ClassNameMapper $classNameMapper |
|
507 | + * @throws TDBMException |
|
508 | + */ |
|
509 | + private function generateFactory(array $tableList, ClassNameMapper $classNameMapper) : void |
|
510 | + { |
|
511 | + $daoNamespace = $this->configuration->getDaoNamespace(); |
|
512 | + $daoFactoryClassName = $this->namingStrategy->getDaoFactoryClassName(); |
|
513 | + |
|
514 | + // For each table, let's write a property. |
|
515 | + |
|
516 | + $str = "<?php |
|
517 | 517 | |
518 | 518 | /* |
519 | 519 | * This file has been automatically generated by TDBM. |
@@ -523,13 +523,13 @@ discard block |
||
523 | 523 | namespace {$daoNamespace}\\Generated; |
524 | 524 | |
525 | 525 | "; |
526 | - foreach ($tableList as $table) { |
|
527 | - $tableName = $table->getName(); |
|
528 | - $daoClassName = $this->namingStrategy->getDaoClassName($tableName); |
|
529 | - $str .= "use {$daoNamespace}\\".$daoClassName.";\n"; |
|
530 | - } |
|
526 | + foreach ($tableList as $table) { |
|
527 | + $tableName = $table->getName(); |
|
528 | + $daoClassName = $this->namingStrategy->getDaoClassName($tableName); |
|
529 | + $str .= "use {$daoNamespace}\\".$daoClassName.";\n"; |
|
530 | + } |
|
531 | 531 | |
532 | - $str .= " |
|
532 | + $str .= " |
|
533 | 533 | /** |
534 | 534 | * The $daoFactoryClassName provides an easy access to all DAOs generated by TDBM. |
535 | 535 | * |
@@ -538,12 +538,12 @@ discard block |
||
538 | 538 | { |
539 | 539 | "; |
540 | 540 | |
541 | - foreach ($tableList as $table) { |
|
542 | - $tableName = $table->getName(); |
|
543 | - $daoClassName = $this->namingStrategy->getDaoClassName($tableName); |
|
544 | - $daoInstanceName = self::toVariableName($daoClassName); |
|
541 | + foreach ($tableList as $table) { |
|
542 | + $tableName = $table->getName(); |
|
543 | + $daoClassName = $this->namingStrategy->getDaoClassName($tableName); |
|
544 | + $daoInstanceName = self::toVariableName($daoClassName); |
|
545 | 545 | |
546 | - $str .= ' /** |
|
546 | + $str .= ' /** |
|
547 | 547 | * @var '.$daoClassName.' |
548 | 548 | */ |
549 | 549 | private $'.$daoInstanceName.'; |
@@ -567,139 +567,139 @@ discard block |
||
567 | 567 | { |
568 | 568 | $this->'.$daoInstanceName.' = $'.$daoInstanceName.'; |
569 | 569 | }'; |
570 | - } |
|
570 | + } |
|
571 | 571 | |
572 | - $str .= ' |
|
572 | + $str .= ' |
|
573 | 573 | } |
574 | 574 | '; |
575 | 575 | |
576 | - $possibleFileNames = $classNameMapper->getPossibleFileNames($daoNamespace.'\\Generated\\'.$daoFactoryClassName); |
|
577 | - if (empty($possibleFileNames)) { |
|
578 | - throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daoNamespace.'\\'.$daoFactoryClassName.'" is not autoloadable.'); |
|
579 | - } |
|
580 | - $possibleFileName = $this->rootPath.$possibleFileNames[0]; |
|
581 | - |
|
582 | - $this->ensureDirectoryExist($possibleFileName); |
|
583 | - file_put_contents($possibleFileName, $str); |
|
584 | - @chmod($possibleFileName, 0664); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Transforms a string to camelCase (except the first letter will be uppercase too). |
|
589 | - * Underscores and spaces are removed and the first letter after the underscore is uppercased. |
|
590 | - * |
|
591 | - * @param $str string |
|
592 | - * |
|
593 | - * @return string |
|
594 | - */ |
|
595 | - public static function toCamelCase($str) |
|
596 | - { |
|
597 | - $str = strtoupper(substr($str, 0, 1)).substr($str, 1); |
|
598 | - while (true) { |
|
599 | - if (strpos($str, '_') === false && strpos($str, ' ') === false) { |
|
600 | - break; |
|
601 | - } |
|
602 | - |
|
603 | - $pos = strpos($str, '_'); |
|
604 | - if ($pos === false) { |
|
605 | - $pos = strpos($str, ' '); |
|
606 | - } |
|
607 | - $before = substr($str, 0, $pos); |
|
608 | - $after = substr($str, $pos + 1); |
|
609 | - $str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1); |
|
610 | - } |
|
611 | - |
|
612 | - return $str; |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Tries to put string to the singular form (if it is plural). |
|
617 | - * We assume the table names are in english. |
|
618 | - * |
|
619 | - * @param $str string |
|
620 | - * |
|
621 | - * @return string |
|
622 | - */ |
|
623 | - public static function toSingular($str) |
|
624 | - { |
|
625 | - return Inflector::singularize($str); |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * Put the first letter of the string in lower case. |
|
630 | - * Very useful to transform a class name into a variable name. |
|
631 | - * |
|
632 | - * @param $str string |
|
633 | - * |
|
634 | - * @return string |
|
635 | - */ |
|
636 | - public static function toVariableName($str) |
|
637 | - { |
|
638 | - return strtolower(substr($str, 0, 1)).substr($str, 1); |
|
639 | - } |
|
640 | - |
|
641 | - /** |
|
642 | - * Ensures the file passed in parameter can be written in its directory. |
|
643 | - * |
|
644 | - * @param string $fileName |
|
645 | - * |
|
646 | - * @throws TDBMException |
|
647 | - */ |
|
648 | - private function ensureDirectoryExist($fileName) |
|
649 | - { |
|
650 | - $dirName = dirname($fileName); |
|
651 | - if (!file_exists($dirName)) { |
|
652 | - $old = umask(0); |
|
653 | - $result = mkdir($dirName, 0775, true); |
|
654 | - umask($old); |
|
655 | - if ($result === false) { |
|
656 | - throw new TDBMException("Unable to create directory: '".$dirName."'."); |
|
657 | - } |
|
658 | - } |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * Absolute path to composer json file. |
|
663 | - * |
|
664 | - * @param string $composerFile |
|
665 | - */ |
|
666 | - public function setComposerFile($composerFile) |
|
667 | - { |
|
668 | - $this->rootPath = dirname($composerFile).'/'; |
|
669 | - $this->composerFile = basename($composerFile); |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Transforms a DBAL type into a PHP type (for PHPDoc purpose). |
|
674 | - * |
|
675 | - * @param Type $type The DBAL type |
|
676 | - * |
|
677 | - * @return string The PHP type |
|
678 | - */ |
|
679 | - public static function dbalTypeToPhpType(Type $type) |
|
680 | - { |
|
681 | - $map = [ |
|
682 | - Type::TARRAY => 'array', |
|
683 | - Type::SIMPLE_ARRAY => 'array', |
|
684 | - Type::JSON_ARRAY => 'array', |
|
685 | - Type::BIGINT => 'string', |
|
686 | - Type::BOOLEAN => 'bool', |
|
687 | - Type::DATETIME => '\DateTimeInterface', |
|
688 | - Type::DATETIMETZ => '\DateTimeInterface', |
|
689 | - Type::DATE => '\DateTimeInterface', |
|
690 | - Type::TIME => '\DateTimeInterface', |
|
691 | - Type::DECIMAL => 'float', |
|
692 | - Type::INTEGER => 'int', |
|
693 | - Type::OBJECT => 'string', |
|
694 | - Type::SMALLINT => 'int', |
|
695 | - Type::STRING => 'string', |
|
696 | - Type::TEXT => 'string', |
|
697 | - Type::BINARY => 'string', |
|
698 | - Type::BLOB => 'string', |
|
699 | - Type::FLOAT => 'float', |
|
700 | - Type::GUID => 'string', |
|
701 | - ]; |
|
702 | - |
|
703 | - return isset($map[$type->getName()]) ? $map[$type->getName()] : $type->getName(); |
|
704 | - } |
|
576 | + $possibleFileNames = $classNameMapper->getPossibleFileNames($daoNamespace.'\\Generated\\'.$daoFactoryClassName); |
|
577 | + if (empty($possibleFileNames)) { |
|
578 | + throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daoNamespace.'\\'.$daoFactoryClassName.'" is not autoloadable.'); |
|
579 | + } |
|
580 | + $possibleFileName = $this->rootPath.$possibleFileNames[0]; |
|
581 | + |
|
582 | + $this->ensureDirectoryExist($possibleFileName); |
|
583 | + file_put_contents($possibleFileName, $str); |
|
584 | + @chmod($possibleFileName, 0664); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Transforms a string to camelCase (except the first letter will be uppercase too). |
|
589 | + * Underscores and spaces are removed and the first letter after the underscore is uppercased. |
|
590 | + * |
|
591 | + * @param $str string |
|
592 | + * |
|
593 | + * @return string |
|
594 | + */ |
|
595 | + public static function toCamelCase($str) |
|
596 | + { |
|
597 | + $str = strtoupper(substr($str, 0, 1)).substr($str, 1); |
|
598 | + while (true) { |
|
599 | + if (strpos($str, '_') === false && strpos($str, ' ') === false) { |
|
600 | + break; |
|
601 | + } |
|
602 | + |
|
603 | + $pos = strpos($str, '_'); |
|
604 | + if ($pos === false) { |
|
605 | + $pos = strpos($str, ' '); |
|
606 | + } |
|
607 | + $before = substr($str, 0, $pos); |
|
608 | + $after = substr($str, $pos + 1); |
|
609 | + $str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1); |
|
610 | + } |
|
611 | + |
|
612 | + return $str; |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Tries to put string to the singular form (if it is plural). |
|
617 | + * We assume the table names are in english. |
|
618 | + * |
|
619 | + * @param $str string |
|
620 | + * |
|
621 | + * @return string |
|
622 | + */ |
|
623 | + public static function toSingular($str) |
|
624 | + { |
|
625 | + return Inflector::singularize($str); |
|
626 | + } |
|
627 | + |
|
628 | + /** |
|
629 | + * Put the first letter of the string in lower case. |
|
630 | + * Very useful to transform a class name into a variable name. |
|
631 | + * |
|
632 | + * @param $str string |
|
633 | + * |
|
634 | + * @return string |
|
635 | + */ |
|
636 | + public static function toVariableName($str) |
|
637 | + { |
|
638 | + return strtolower(substr($str, 0, 1)).substr($str, 1); |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * Ensures the file passed in parameter can be written in its directory. |
|
643 | + * |
|
644 | + * @param string $fileName |
|
645 | + * |
|
646 | + * @throws TDBMException |
|
647 | + */ |
|
648 | + private function ensureDirectoryExist($fileName) |
|
649 | + { |
|
650 | + $dirName = dirname($fileName); |
|
651 | + if (!file_exists($dirName)) { |
|
652 | + $old = umask(0); |
|
653 | + $result = mkdir($dirName, 0775, true); |
|
654 | + umask($old); |
|
655 | + if ($result === false) { |
|
656 | + throw new TDBMException("Unable to create directory: '".$dirName."'."); |
|
657 | + } |
|
658 | + } |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * Absolute path to composer json file. |
|
663 | + * |
|
664 | + * @param string $composerFile |
|
665 | + */ |
|
666 | + public function setComposerFile($composerFile) |
|
667 | + { |
|
668 | + $this->rootPath = dirname($composerFile).'/'; |
|
669 | + $this->composerFile = basename($composerFile); |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Transforms a DBAL type into a PHP type (for PHPDoc purpose). |
|
674 | + * |
|
675 | + * @param Type $type The DBAL type |
|
676 | + * |
|
677 | + * @return string The PHP type |
|
678 | + */ |
|
679 | + public static function dbalTypeToPhpType(Type $type) |
|
680 | + { |
|
681 | + $map = [ |
|
682 | + Type::TARRAY => 'array', |
|
683 | + Type::SIMPLE_ARRAY => 'array', |
|
684 | + Type::JSON_ARRAY => 'array', |
|
685 | + Type::BIGINT => 'string', |
|
686 | + Type::BOOLEAN => 'bool', |
|
687 | + Type::DATETIME => '\DateTimeInterface', |
|
688 | + Type::DATETIMETZ => '\DateTimeInterface', |
|
689 | + Type::DATE => '\DateTimeInterface', |
|
690 | + Type::TIME => '\DateTimeInterface', |
|
691 | + Type::DECIMAL => 'float', |
|
692 | + Type::INTEGER => 'int', |
|
693 | + Type::OBJECT => 'string', |
|
694 | + Type::SMALLINT => 'int', |
|
695 | + Type::STRING => 'string', |
|
696 | + Type::TEXT => 'string', |
|
697 | + Type::BINARY => 'string', |
|
698 | + Type::BLOB => 'string', |
|
699 | + Type::FLOAT => 'float', |
|
700 | + Type::GUID => 'string', |
|
701 | + ]; |
|
702 | + |
|
703 | + return isset($map[$type->getName()]) ? $map[$type->getName()] : $type->getName(); |
|
704 | + } |
|
705 | 705 | } |
@@ -11,136 +11,136 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class ScalarBeanPropertyDescriptor extends AbstractBeanPropertyDescriptor |
13 | 13 | { |
14 | - /** |
|
15 | - * @var Column |
|
16 | - */ |
|
17 | - private $column; |
|
18 | - /** |
|
19 | - * @var NamingStrategyInterface |
|
20 | - */ |
|
21 | - private $namingStrategy; |
|
22 | - |
|
23 | - /** |
|
24 | - * ScalarBeanPropertyDescriptor constructor. |
|
25 | - * @param Table $table |
|
26 | - * @param Column $column |
|
27 | - * @param NamingStrategyInterface $namingStrategy |
|
28 | - */ |
|
29 | - public function __construct(Table $table, Column $column, NamingStrategyInterface $namingStrategy) |
|
30 | - { |
|
31 | - parent::__construct($table); |
|
32 | - $this->table = $table; |
|
33 | - $this->column = $column; |
|
34 | - $this->namingStrategy = $namingStrategy; |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Returns the foreign-key the column is part of, if any. null otherwise. |
|
39 | - * |
|
40 | - * @return ForeignKeyConstraint|null |
|
41 | - */ |
|
42 | - public function getForeignKey() |
|
43 | - { |
|
44 | - return false; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Returns the param annotation for this property (useful for constructor). |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function getParamAnnotation() |
|
53 | - { |
|
54 | - $className = $this->getClassName(); |
|
55 | - $paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType()); |
|
56 | - |
|
57 | - $str = ' * @param %s %s'; |
|
58 | - |
|
59 | - return sprintf($str, $paramType, $this->getVariableName()); |
|
60 | - } |
|
61 | - |
|
62 | - public function getUpperCamelCaseName() |
|
63 | - { |
|
64 | - return TDBMDaoGenerator::toCamelCase($this->column->getName()); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Returns the name of the class linked to this property or null if this is not a foreign key. |
|
69 | - * |
|
70 | - * @return null|string |
|
71 | - */ |
|
72 | - public function getClassName() |
|
73 | - { |
|
74 | - return; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
|
79 | - * |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public function isCompulsory() |
|
83 | - { |
|
84 | - return $this->column->getNotnull() && !$this->column->getAutoincrement() && $this->column->getDefault() === null; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Returns true if the property has a default value. |
|
89 | - * |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function hasDefault() |
|
93 | - { |
|
94 | - return $this->column->getDefault() !== null; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Returns the code that assigns a value to its default value. |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function assignToDefaultCode() |
|
103 | - { |
|
104 | - $str = ' $this->%s(%s);'; |
|
105 | - |
|
106 | - $default = $this->column->getDefault(); |
|
107 | - |
|
108 | - if (strtoupper($default) === 'CURRENT_TIMESTAMP') { |
|
109 | - $defaultCode = 'new \DateTimeImmutable()'; |
|
110 | - } else { |
|
111 | - $defaultCode = var_export($this->column->getDefault(), true); |
|
112 | - } |
|
113 | - |
|
114 | - return sprintf($str, $this->getSetterName(), $defaultCode); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Returns true if the property is the primary key. |
|
119 | - * |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function isPrimaryKey() |
|
123 | - { |
|
124 | - return in_array($this->column->getName(), $this->table->getPrimaryKeyColumns()); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Returns the PHP code for getters and setters. |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function getGetterSetterCode() |
|
133 | - { |
|
134 | - $type = $this->column->getType(); |
|
135 | - $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
136 | - |
|
137 | - $columnGetterName = $this->getGetterName(); |
|
138 | - $columnSetterName = $this->getSetterName(); |
|
139 | - |
|
140 | - // A column type can be forced if it is not nullable and not auto-incrementable (for auto-increment columns, we can get "null" as long as the bean is not saved). |
|
141 | - $isNullable = !$this->column->getNotnull() || $this->column->getAutoincrement(); |
|
142 | - |
|
143 | - $getterAndSetterCode = ' /** |
|
14 | + /** |
|
15 | + * @var Column |
|
16 | + */ |
|
17 | + private $column; |
|
18 | + /** |
|
19 | + * @var NamingStrategyInterface |
|
20 | + */ |
|
21 | + private $namingStrategy; |
|
22 | + |
|
23 | + /** |
|
24 | + * ScalarBeanPropertyDescriptor constructor. |
|
25 | + * @param Table $table |
|
26 | + * @param Column $column |
|
27 | + * @param NamingStrategyInterface $namingStrategy |
|
28 | + */ |
|
29 | + public function __construct(Table $table, Column $column, NamingStrategyInterface $namingStrategy) |
|
30 | + { |
|
31 | + parent::__construct($table); |
|
32 | + $this->table = $table; |
|
33 | + $this->column = $column; |
|
34 | + $this->namingStrategy = $namingStrategy; |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Returns the foreign-key the column is part of, if any. null otherwise. |
|
39 | + * |
|
40 | + * @return ForeignKeyConstraint|null |
|
41 | + */ |
|
42 | + public function getForeignKey() |
|
43 | + { |
|
44 | + return false; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Returns the param annotation for this property (useful for constructor). |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function getParamAnnotation() |
|
53 | + { |
|
54 | + $className = $this->getClassName(); |
|
55 | + $paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType()); |
|
56 | + |
|
57 | + $str = ' * @param %s %s'; |
|
58 | + |
|
59 | + return sprintf($str, $paramType, $this->getVariableName()); |
|
60 | + } |
|
61 | + |
|
62 | + public function getUpperCamelCaseName() |
|
63 | + { |
|
64 | + return TDBMDaoGenerator::toCamelCase($this->column->getName()); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Returns the name of the class linked to this property or null if this is not a foreign key. |
|
69 | + * |
|
70 | + * @return null|string |
|
71 | + */ |
|
72 | + public function getClassName() |
|
73 | + { |
|
74 | + return; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
|
79 | + * |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public function isCompulsory() |
|
83 | + { |
|
84 | + return $this->column->getNotnull() && !$this->column->getAutoincrement() && $this->column->getDefault() === null; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Returns true if the property has a default value. |
|
89 | + * |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function hasDefault() |
|
93 | + { |
|
94 | + return $this->column->getDefault() !== null; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Returns the code that assigns a value to its default value. |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function assignToDefaultCode() |
|
103 | + { |
|
104 | + $str = ' $this->%s(%s);'; |
|
105 | + |
|
106 | + $default = $this->column->getDefault(); |
|
107 | + |
|
108 | + if (strtoupper($default) === 'CURRENT_TIMESTAMP') { |
|
109 | + $defaultCode = 'new \DateTimeImmutable()'; |
|
110 | + } else { |
|
111 | + $defaultCode = var_export($this->column->getDefault(), true); |
|
112 | + } |
|
113 | + |
|
114 | + return sprintf($str, $this->getSetterName(), $defaultCode); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Returns true if the property is the primary key. |
|
119 | + * |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function isPrimaryKey() |
|
123 | + { |
|
124 | + return in_array($this->column->getName(), $this->table->getPrimaryKeyColumns()); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Returns the PHP code for getters and setters. |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function getGetterSetterCode() |
|
133 | + { |
|
134 | + $type = $this->column->getType(); |
|
135 | + $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
136 | + |
|
137 | + $columnGetterName = $this->getGetterName(); |
|
138 | + $columnSetterName = $this->getSetterName(); |
|
139 | + |
|
140 | + // A column type can be forced if it is not nullable and not auto-incrementable (for auto-increment columns, we can get "null" as long as the bean is not saved). |
|
141 | + $isNullable = !$this->column->getNotnull() || $this->column->getAutoincrement(); |
|
142 | + |
|
143 | + $getterAndSetterCode = ' /** |
|
144 | 144 | * The getter for the "%s" column. |
145 | 145 | * |
146 | 146 | * @return %s |
@@ -162,54 +162,54 @@ discard block |
||
162 | 162 | |
163 | 163 | '; |
164 | 164 | |
165 | - return sprintf($getterAndSetterCode, |
|
166 | - // Getter |
|
167 | - $this->column->getName(), |
|
168 | - $normalizedType.($isNullable ? '|null' : ''), |
|
169 | - $columnGetterName, |
|
170 | - ($isNullable ? '?' : ''), |
|
171 | - $normalizedType, |
|
172 | - var_export($this->column->getName(), true), |
|
173 | - var_export($this->table->getName(), true), |
|
174 | - // Setter |
|
175 | - $this->column->getName(), |
|
176 | - $normalizedType, |
|
177 | - $this->column->getName(), |
|
178 | - $columnSetterName, |
|
179 | - $this->column->getNotnull() ? '' : '?', |
|
180 | - $normalizedType, |
|
181 | - //$castTo, |
|
182 | - $this->column->getName(), |
|
183 | - var_export($this->column->getName(), true), |
|
184 | - $this->column->getName(), |
|
185 | - var_export($this->table->getName(), true) |
|
186 | - ); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Returns the part of code useful when doing json serialization. |
|
191 | - * |
|
192 | - * @return string |
|
193 | - */ |
|
194 | - public function getJsonSerializeCode() |
|
195 | - { |
|
196 | - $type = $this->column->getType(); |
|
197 | - $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
198 | - |
|
199 | - if ($normalizedType == '\\DateTimeInterface') { |
|
200 | - return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = ($this->'.$this->getGetterName().'() === null) ? null : $this->'.$this->getGetterName()."()->format('c');\n"; |
|
201 | - } else { |
|
202 | - return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."();\n"; |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Returns the column name. |
|
208 | - * |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - public function getColumnName() |
|
212 | - { |
|
213 | - return $this->column->getName(); |
|
214 | - } |
|
165 | + return sprintf($getterAndSetterCode, |
|
166 | + // Getter |
|
167 | + $this->column->getName(), |
|
168 | + $normalizedType.($isNullable ? '|null' : ''), |
|
169 | + $columnGetterName, |
|
170 | + ($isNullable ? '?' : ''), |
|
171 | + $normalizedType, |
|
172 | + var_export($this->column->getName(), true), |
|
173 | + var_export($this->table->getName(), true), |
|
174 | + // Setter |
|
175 | + $this->column->getName(), |
|
176 | + $normalizedType, |
|
177 | + $this->column->getName(), |
|
178 | + $columnSetterName, |
|
179 | + $this->column->getNotnull() ? '' : '?', |
|
180 | + $normalizedType, |
|
181 | + //$castTo, |
|
182 | + $this->column->getName(), |
|
183 | + var_export($this->column->getName(), true), |
|
184 | + $this->column->getName(), |
|
185 | + var_export($this->table->getName(), true) |
|
186 | + ); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Returns the part of code useful when doing json serialization. |
|
191 | + * |
|
192 | + * @return string |
|
193 | + */ |
|
194 | + public function getJsonSerializeCode() |
|
195 | + { |
|
196 | + $type = $this->column->getType(); |
|
197 | + $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
198 | + |
|
199 | + if ($normalizedType == '\\DateTimeInterface') { |
|
200 | + return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = ($this->'.$this->getGetterName().'() === null) ? null : $this->'.$this->getGetterName()."()->format('c');\n"; |
|
201 | + } else { |
|
202 | + return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."();\n"; |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Returns the column name. |
|
208 | + * |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public function getColumnName() |
|
212 | + { |
|
213 | + return $this->column->getName(); |
|
214 | + } |
|
215 | 215 | } |
@@ -7,105 +7,105 @@ discard block |
||
7 | 7 | |
8 | 8 | class PivotTableMethodsDescriptor implements MethodDescriptorInterface |
9 | 9 | { |
10 | - /** |
|
11 | - * @var Table |
|
12 | - */ |
|
13 | - private $pivotTable; |
|
14 | - |
|
15 | - private $useAlternateName = false; |
|
16 | - |
|
17 | - /** |
|
18 | - * @var ForeignKeyConstraint |
|
19 | - */ |
|
20 | - private $localFk; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var ForeignKeyConstraint |
|
24 | - */ |
|
25 | - private $remoteFk; |
|
26 | - /** |
|
27 | - * @var NamingStrategyInterface |
|
28 | - */ |
|
29 | - private $namingStrategy; |
|
30 | - |
|
31 | - /** |
|
32 | - * @param Table $pivotTable The pivot table |
|
33 | - * @param ForeignKeyConstraint $localFk |
|
34 | - * @param ForeignKeyConstraint $remoteFk |
|
35 | - * @param NamingStrategyInterface $namingStrategy |
|
36 | - */ |
|
37 | - public function __construct(Table $pivotTable, ForeignKeyConstraint $localFk, ForeignKeyConstraint $remoteFk, NamingStrategyInterface $namingStrategy) |
|
38 | - { |
|
39 | - $this->pivotTable = $pivotTable; |
|
40 | - $this->localFk = $localFk; |
|
41 | - $this->remoteFk = $remoteFk; |
|
42 | - $this->namingStrategy = $namingStrategy; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Requests the use of an alternative name for this method. |
|
47 | - */ |
|
48 | - public function useAlternativeName() |
|
49 | - { |
|
50 | - $this->useAlternateName = true; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Returns the name of the method to be generated. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function getName() : string |
|
59 | - { |
|
60 | - if (!$this->useAlternateName) { |
|
61 | - return 'get'.TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()); |
|
62 | - } else { |
|
63 | - return 'get'.TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Returns the plural name. |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - private function getPluralName() : string |
|
73 | - { |
|
74 | - if (!$this->useAlternateName) { |
|
75 | - return TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()); |
|
76 | - } else { |
|
77 | - return TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Returns the singular name. |
|
83 | - * |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - private function getSingularName() : string |
|
87 | - { |
|
88 | - if (!$this->useAlternateName) { |
|
89 | - return TDBMDaoGenerator::toCamelCase(TDBMDaoGenerator::toSingular($this->remoteFk->getForeignTableName())); |
|
90 | - } else { |
|
91 | - return TDBMDaoGenerator::toCamelCase(TDBMDaoGenerator::toSingular($this->remoteFk->getForeignTableName())).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Returns the code of the method. |
|
97 | - * |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function getCode() : string |
|
101 | - { |
|
102 | - $singularName = $this->getSingularName(); |
|
103 | - $pluralName = $this->getPluralName(); |
|
104 | - $remoteBeanName = $this->namingStrategy->getBeanClassName($this->remoteFk->getForeignTableName()); |
|
105 | - $variableName = '$'.TDBMDaoGenerator::toVariableName($remoteBeanName); |
|
106 | - $pluralVariableName = $variableName.'s'; |
|
107 | - |
|
108 | - $str = ' /** |
|
10 | + /** |
|
11 | + * @var Table |
|
12 | + */ |
|
13 | + private $pivotTable; |
|
14 | + |
|
15 | + private $useAlternateName = false; |
|
16 | + |
|
17 | + /** |
|
18 | + * @var ForeignKeyConstraint |
|
19 | + */ |
|
20 | + private $localFk; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var ForeignKeyConstraint |
|
24 | + */ |
|
25 | + private $remoteFk; |
|
26 | + /** |
|
27 | + * @var NamingStrategyInterface |
|
28 | + */ |
|
29 | + private $namingStrategy; |
|
30 | + |
|
31 | + /** |
|
32 | + * @param Table $pivotTable The pivot table |
|
33 | + * @param ForeignKeyConstraint $localFk |
|
34 | + * @param ForeignKeyConstraint $remoteFk |
|
35 | + * @param NamingStrategyInterface $namingStrategy |
|
36 | + */ |
|
37 | + public function __construct(Table $pivotTable, ForeignKeyConstraint $localFk, ForeignKeyConstraint $remoteFk, NamingStrategyInterface $namingStrategy) |
|
38 | + { |
|
39 | + $this->pivotTable = $pivotTable; |
|
40 | + $this->localFk = $localFk; |
|
41 | + $this->remoteFk = $remoteFk; |
|
42 | + $this->namingStrategy = $namingStrategy; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Requests the use of an alternative name for this method. |
|
47 | + */ |
|
48 | + public function useAlternativeName() |
|
49 | + { |
|
50 | + $this->useAlternateName = true; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Returns the name of the method to be generated. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function getName() : string |
|
59 | + { |
|
60 | + if (!$this->useAlternateName) { |
|
61 | + return 'get'.TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()); |
|
62 | + } else { |
|
63 | + return 'get'.TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Returns the plural name. |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + private function getPluralName() : string |
|
73 | + { |
|
74 | + if (!$this->useAlternateName) { |
|
75 | + return TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()); |
|
76 | + } else { |
|
77 | + return TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Returns the singular name. |
|
83 | + * |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + private function getSingularName() : string |
|
87 | + { |
|
88 | + if (!$this->useAlternateName) { |
|
89 | + return TDBMDaoGenerator::toCamelCase(TDBMDaoGenerator::toSingular($this->remoteFk->getForeignTableName())); |
|
90 | + } else { |
|
91 | + return TDBMDaoGenerator::toCamelCase(TDBMDaoGenerator::toSingular($this->remoteFk->getForeignTableName())).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Returns the code of the method. |
|
97 | + * |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function getCode() : string |
|
101 | + { |
|
102 | + $singularName = $this->getSingularName(); |
|
103 | + $pluralName = $this->getPluralName(); |
|
104 | + $remoteBeanName = $this->namingStrategy->getBeanClassName($this->remoteFk->getForeignTableName()); |
|
105 | + $variableName = '$'.TDBMDaoGenerator::toVariableName($remoteBeanName); |
|
106 | + $pluralVariableName = $variableName.'s'; |
|
107 | + |
|
108 | + $str = ' /** |
|
109 | 109 | * Returns the list of %s associated to this bean via the %s pivot table. |
110 | 110 | * |
111 | 111 | * @return %s[] |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | } |
117 | 117 | '; |
118 | 118 | |
119 | - $getterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralName, var_export($this->remoteFk->getLocalTableName(), true)); |
|
119 | + $getterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralName, var_export($this->remoteFk->getLocalTableName(), true)); |
|
120 | 120 | |
121 | - $str = ' /** |
|
121 | + $str = ' /** |
|
122 | 122 | * Adds a relationship with %s associated to this bean via the %s pivot table. |
123 | 123 | * |
124 | 124 | * @param %s %s |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | } |
130 | 130 | '; |
131 | 131 | |
132 | - $adderCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
132 | + $adderCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
133 | 133 | |
134 | - $str = ' /** |
|
134 | + $str = ' /** |
|
135 | 135 | * Deletes the relationship with %s associated to this bean via the %s pivot table. |
136 | 136 | * |
137 | 137 | * @param %s %s |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | } |
143 | 143 | '; |
144 | 144 | |
145 | - $removerCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
145 | + $removerCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
146 | 146 | |
147 | - $str = ' /** |
|
147 | + $str = ' /** |
|
148 | 148 | * Returns whether this bean is associated with %s via the %s pivot table. |
149 | 149 | * |
150 | 150 | * @param %s %s |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | } |
157 | 157 | '; |
158 | 158 | |
159 | - $hasCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
159 | + $hasCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
160 | 160 | |
161 | - $str = ' /** |
|
161 | + $str = ' /** |
|
162 | 162 | * Sets all relationships with %s associated to this bean via the %s pivot table. |
163 | 163 | * Exiting relationships will be removed and replaced by the provided relationships. |
164 | 164 | * |
@@ -170,38 +170,38 @@ discard block |
||
170 | 170 | } |
171 | 171 | '; |
172 | 172 | |
173 | - $setterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralVariableName, $pluralName, $pluralVariableName, var_export($this->remoteFk->getLocalTableName(), true), $pluralVariableName); |
|
174 | - |
|
175 | - $code = $getterCode.$adderCode.$removerCode.$hasCode.$setterCode; |
|
176 | - |
|
177 | - return $code; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns an array of classes that needs a "use" for this method. |
|
182 | - * |
|
183 | - * @return string[] |
|
184 | - */ |
|
185 | - public function getUsedClasses() : array |
|
186 | - { |
|
187 | - return [$this->namingStrategy->getBeanClassName($this->remoteFk->getForeignTableName())]; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Returns the code to past in jsonSerialize. |
|
192 | - * |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - public function getJsonSerializeCode() : string |
|
196 | - { |
|
197 | - $remoteBeanName = $this->namingStrategy->getBeanClassName($this->remoteFk->getForeignTableName()); |
|
198 | - $variableName = '$'.TDBMDaoGenerator::toVariableName($remoteBeanName); |
|
199 | - |
|
200 | - return ' if (!$stopRecursion) { |
|
173 | + $setterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralVariableName, $pluralName, $pluralVariableName, var_export($this->remoteFk->getLocalTableName(), true), $pluralVariableName); |
|
174 | + |
|
175 | + $code = $getterCode.$adderCode.$removerCode.$hasCode.$setterCode; |
|
176 | + |
|
177 | + return $code; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns an array of classes that needs a "use" for this method. |
|
182 | + * |
|
183 | + * @return string[] |
|
184 | + */ |
|
185 | + public function getUsedClasses() : array |
|
186 | + { |
|
187 | + return [$this->namingStrategy->getBeanClassName($this->remoteFk->getForeignTableName())]; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Returns the code to past in jsonSerialize. |
|
192 | + * |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + public function getJsonSerializeCode() : string |
|
196 | + { |
|
197 | + $remoteBeanName = $this->namingStrategy->getBeanClassName($this->remoteFk->getForeignTableName()); |
|
198 | + $variableName = '$'.TDBMDaoGenerator::toVariableName($remoteBeanName); |
|
199 | + |
|
200 | + return ' if (!$stopRecursion) { |
|
201 | 201 | $array[\''.lcfirst($this->getPluralName()).'\'] = array_map(function ('.$remoteBeanName.' '.$variableName.') { |
202 | 202 | return '.$variableName.'->jsonSerialize(true); |
203 | 203 | }, $this->'.$this->getName().'()); |
204 | 204 | } |
205 | 205 | '; |
206 | - } |
|
206 | + } |
|
207 | 207 | } |
@@ -7,28 +7,28 @@ |
||
7 | 7 | |
8 | 8 | class GeneratorEventDispatcher implements GeneratorListenerInterface |
9 | 9 | { |
10 | - /** |
|
11 | - * @var GeneratorListenerInterface[] |
|
12 | - */ |
|
13 | - private $listeners; |
|
10 | + /** |
|
11 | + * @var GeneratorListenerInterface[] |
|
12 | + */ |
|
13 | + private $listeners; |
|
14 | 14 | |
15 | - /** |
|
16 | - * GeneratorEventDispatcher constructor. |
|
17 | - * @param GeneratorListenerInterface[] $listeners |
|
18 | - */ |
|
19 | - public function __construct(array $listeners) |
|
20 | - { |
|
21 | - $this->listeners = $listeners; |
|
22 | - } |
|
15 | + /** |
|
16 | + * GeneratorEventDispatcher constructor. |
|
17 | + * @param GeneratorListenerInterface[] $listeners |
|
18 | + */ |
|
19 | + public function __construct(array $listeners) |
|
20 | + { |
|
21 | + $this->listeners = $listeners; |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param ConfigurationInterface $configuration |
|
26 | - * @param BeanDescriptorInterface[] $beanDescriptors |
|
27 | - */ |
|
28 | - public function onGenerate(ConfigurationInterface $configuration, array $beanDescriptors): void |
|
29 | - { |
|
30 | - foreach ($this->listeners as $listener) { |
|
31 | - $listener->onGenerate($configuration, $beanDescriptors); |
|
32 | - } |
|
33 | - } |
|
24 | + /** |
|
25 | + * @param ConfigurationInterface $configuration |
|
26 | + * @param BeanDescriptorInterface[] $beanDescriptors |
|
27 | + */ |
|
28 | + public function onGenerate(ConfigurationInterface $configuration, array $beanDescriptors): void |
|
29 | + { |
|
30 | + foreach ($this->listeners as $listener) { |
|
31 | + $listener->onGenerate($configuration, $beanDescriptors); |
|
32 | + } |
|
33 | + } |
|
34 | 34 | } |
@@ -11,55 +11,55 @@ |
||
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 | - if ($configuration instanceof MoufConfiguration) { |
|
24 | - $daoFactoryInstanceName = $configuration->getDaoFactoryInstanceName(); |
|
25 | - $daoFactoryClassName = $configuration->getDaoNamespace().'\\Generated\\'.$configuration->getNamingStrategy()->getDaoFactoryClassName(); |
|
26 | - $moufManager->declareComponent($daoFactoryInstanceName, $daoFactoryClassName, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS); |
|
27 | - } |
|
23 | + if ($configuration instanceof MoufConfiguration) { |
|
24 | + $daoFactoryInstanceName = $configuration->getDaoFactoryInstanceName(); |
|
25 | + $daoFactoryClassName = $configuration->getDaoNamespace().'\\Generated\\'.$configuration->getNamingStrategy()->getDaoFactoryClassName(); |
|
26 | + $moufManager->declareComponent($daoFactoryInstanceName, $daoFactoryClassName, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS); |
|
27 | + } |
|
28 | 28 | |
29 | - $tdbmServiceInstanceName = $this->getTdbmInstanceName($configuration); |
|
29 | + $tdbmServiceInstanceName = $this->getTdbmInstanceName($configuration); |
|
30 | 30 | |
31 | - foreach ($beanDescriptors as $beanDescriptor) { |
|
32 | - $daoName = $beanDescriptor->getDaoClassName(); |
|
31 | + foreach ($beanDescriptors as $beanDescriptor) { |
|
32 | + $daoName = $beanDescriptor->getDaoClassName(); |
|
33 | 33 | |
34 | - $instanceName = TDBMDaoGenerator::toVariableName($daoName); |
|
35 | - if (!$moufManager->instanceExists($instanceName)) { |
|
36 | - $moufManager->declareComponent($instanceName, $configuration->getDaoNamespace().'\\'.$daoName); |
|
37 | - } |
|
38 | - $moufManager->setParameterViaConstructor($instanceName, 0, $tdbmServiceInstanceName, 'object'); |
|
39 | - $moufManager->bindComponentViaSetter($daoFactoryInstanceName, 'set'.$daoName, $instanceName); |
|
40 | - } |
|
34 | + $instanceName = TDBMDaoGenerator::toVariableName($daoName); |
|
35 | + if (!$moufManager->instanceExists($instanceName)) { |
|
36 | + $moufManager->declareComponent($instanceName, $configuration->getDaoNamespace().'\\'.$daoName); |
|
37 | + } |
|
38 | + $moufManager->setParameterViaConstructor($instanceName, 0, $tdbmServiceInstanceName, 'object'); |
|
39 | + $moufManager->bindComponentViaSetter($daoFactoryInstanceName, 'set'.$daoName, $instanceName); |
|
40 | + } |
|
41 | 41 | |
42 | - $moufManager->rewriteMouf(); |
|
43 | - } |
|
42 | + $moufManager->rewriteMouf(); |
|
43 | + } |
|
44 | 44 | |
45 | - private function getTdbmInstanceName(ConfigurationInterface $configuration) : string |
|
46 | - { |
|
47 | - $moufManager = MoufManager::getMoufManager(); |
|
45 | + private function getTdbmInstanceName(ConfigurationInterface $configuration) : string |
|
46 | + { |
|
47 | + $moufManager = MoufManager::getMoufManager(); |
|
48 | 48 | |
49 | - $configurationInstanceName = $moufManager->findInstanceName($configuration); |
|
50 | - if (!$configurationInstanceName) { |
|
51 | - throw new \TDBMException('Could not find TDBM instance for configuration object.'); |
|
52 | - } |
|
49 | + $configurationInstanceName = $moufManager->findInstanceName($configuration); |
|
50 | + if (!$configurationInstanceName) { |
|
51 | + throw new \TDBMException('Could not find TDBM instance for configuration object.'); |
|
52 | + } |
|
53 | 53 | |
54 | - // Let's find the configuration |
|
55 | - $tdbmServicesNames = $moufManager->findInstances(TDBMService::class); |
|
54 | + // Let's find the configuration |
|
55 | + $tdbmServicesNames = $moufManager->findInstances(TDBMService::class); |
|
56 | 56 | |
57 | - foreach ($tdbmServicesNames as $name) { |
|
58 | - if ($moufManager->getInstanceDescriptor($name)->getConstructorArgumentProperty('configuration')->getValue()->getName() === $configurationInstanceName) { |
|
59 | - return $name; |
|
60 | - } |
|
61 | - } |
|
57 | + foreach ($tdbmServicesNames as $name) { |
|
58 | + if ($moufManager->getInstanceDescriptor($name)->getConstructorArgumentProperty('configuration')->getValue()->getName() === $configurationInstanceName) { |
|
59 | + return $name; |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - throw new \TDBMException('Could not find TDBMService instance.'); |
|
64 | - } |
|
63 | + throw new \TDBMException('Could not find TDBMService instance.'); |
|
64 | + } |
|
65 | 65 | } |
@@ -12,71 +12,71 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class DirectForeignKeyMethodDescriptor implements MethodDescriptorInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * @var ForeignKeyConstraint |
|
17 | - */ |
|
18 | - private $fk; |
|
19 | - |
|
20 | - private $useAlternateName = false; |
|
21 | - /** |
|
22 | - * @var Table |
|
23 | - */ |
|
24 | - private $mainTable; |
|
25 | - /** |
|
26 | - * @var NamingStrategyInterface |
|
27 | - */ |
|
28 | - private $namingStrategy; |
|
29 | - |
|
30 | - /** |
|
31 | - * @param ForeignKeyConstraint $fk The foreign key pointing to our bean |
|
32 | - * @param Table $mainTable The main table that is pointed to |
|
33 | - * @param NamingStrategyInterface $namingStrategy |
|
34 | - */ |
|
35 | - public function __construct(ForeignKeyConstraint $fk, Table $mainTable, NamingStrategyInterface $namingStrategy) |
|
36 | - { |
|
37 | - $this->fk = $fk; |
|
38 | - $this->mainTable = $mainTable; |
|
39 | - $this->namingStrategy = $namingStrategy; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Returns the name of the method to be generated. |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getName() : string |
|
48 | - { |
|
49 | - if (!$this->useAlternateName) { |
|
50 | - return 'get'.TDBMDaoGenerator::toCamelCase($this->fk->getLocalTableName()); |
|
51 | - } else { |
|
52 | - $methodName = 'get'.TDBMDaoGenerator::toCamelCase($this->fk->getLocalTableName()).'By'; |
|
53 | - |
|
54 | - $camelizedColumns = array_map([TDBMDaoGenerator::class, 'toCamelCase'], $this->fk->getLocalColumns()); |
|
55 | - |
|
56 | - $methodName .= implode('And', $camelizedColumns); |
|
57 | - |
|
58 | - return $methodName; |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Requests the use of an alternative name for this method. |
|
64 | - */ |
|
65 | - public function useAlternativeName() |
|
66 | - { |
|
67 | - $this->useAlternateName = true; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns the code of the method. |
|
72 | - * |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function getCode() : string |
|
76 | - { |
|
77 | - $code = ''; |
|
78 | - |
|
79 | - $getterCode = ' /** |
|
15 | + /** |
|
16 | + * @var ForeignKeyConstraint |
|
17 | + */ |
|
18 | + private $fk; |
|
19 | + |
|
20 | + private $useAlternateName = false; |
|
21 | + /** |
|
22 | + * @var Table |
|
23 | + */ |
|
24 | + private $mainTable; |
|
25 | + /** |
|
26 | + * @var NamingStrategyInterface |
|
27 | + */ |
|
28 | + private $namingStrategy; |
|
29 | + |
|
30 | + /** |
|
31 | + * @param ForeignKeyConstraint $fk The foreign key pointing to our bean |
|
32 | + * @param Table $mainTable The main table that is pointed to |
|
33 | + * @param NamingStrategyInterface $namingStrategy |
|
34 | + */ |
|
35 | + public function __construct(ForeignKeyConstraint $fk, Table $mainTable, NamingStrategyInterface $namingStrategy) |
|
36 | + { |
|
37 | + $this->fk = $fk; |
|
38 | + $this->mainTable = $mainTable; |
|
39 | + $this->namingStrategy = $namingStrategy; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Returns the name of the method to be generated. |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getName() : string |
|
48 | + { |
|
49 | + if (!$this->useAlternateName) { |
|
50 | + return 'get'.TDBMDaoGenerator::toCamelCase($this->fk->getLocalTableName()); |
|
51 | + } else { |
|
52 | + $methodName = 'get'.TDBMDaoGenerator::toCamelCase($this->fk->getLocalTableName()).'By'; |
|
53 | + |
|
54 | + $camelizedColumns = array_map([TDBMDaoGenerator::class, 'toCamelCase'], $this->fk->getLocalColumns()); |
|
55 | + |
|
56 | + $methodName .= implode('And', $camelizedColumns); |
|
57 | + |
|
58 | + return $methodName; |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Requests the use of an alternative name for this method. |
|
64 | + */ |
|
65 | + public function useAlternativeName() |
|
66 | + { |
|
67 | + $this->useAlternateName = true; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns the code of the method. |
|
72 | + * |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function getCode() : string |
|
76 | + { |
|
77 | + $code = ''; |
|
78 | + |
|
79 | + $getterCode = ' /** |
|
80 | 80 | * Returns the list of %s pointing to this bean via the %s column. |
81 | 81 | * |
82 | 82 | * @return %s[]|AlterableResultIterator |
@@ -88,55 +88,55 @@ discard block |
||
88 | 88 | |
89 | 89 | '; |
90 | 90 | |
91 | - $beanClass = $this->namingStrategy->getBeanClassName($this->fk->getLocalTableName()); |
|
92 | - $code .= sprintf($getterCode, |
|
93 | - $beanClass, |
|
94 | - implode(', ', $this->fk->getColumns()), |
|
95 | - $beanClass, |
|
96 | - $this->getName(), |
|
97 | - var_export($this->fk->getLocalTableName(), true), |
|
98 | - var_export($this->fk->getName(), true), |
|
99 | - var_export($this->fk->getLocalTableName(), true), |
|
100 | - $this->getFilters($this->fk) |
|
101 | - ); |
|
102 | - |
|
103 | - return $code; |
|
104 | - } |
|
105 | - |
|
106 | - private function getFilters(ForeignKeyConstraint $fk) : string |
|
107 | - { |
|
108 | - $counter = 0; |
|
109 | - $parameters = []; |
|
110 | - |
|
111 | - $pkColumns = $this->mainTable->getPrimaryKeyColumns(); |
|
112 | - |
|
113 | - foreach ($fk->getLocalColumns() as $columnName) { |
|
114 | - $pkColumn = $pkColumns[$counter]; |
|
115 | - $parameters[] = sprintf('%s => $this->get(%s, %s)', var_export($fk->getLocalTableName().'.'.$columnName, true), var_export($pkColumn, true), var_export($this->fk->getForeignTableName(), true)); |
|
116 | - ++$counter; |
|
117 | - } |
|
118 | - $parametersCode = '['.implode(', ', $parameters).']'; |
|
119 | - |
|
120 | - return $parametersCode; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Returns an array of classes that needs a "use" for this method. |
|
125 | - * |
|
126 | - * @return string[] |
|
127 | - */ |
|
128 | - public function getUsedClasses() : array |
|
129 | - { |
|
130 | - return [$this->namingStrategy->getBeanClassName($this->fk->getForeignTableName())]; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the code to past in jsonSerialize. |
|
135 | - * |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public function getJsonSerializeCode() : string |
|
139 | - { |
|
140 | - return ''; |
|
141 | - } |
|
91 | + $beanClass = $this->namingStrategy->getBeanClassName($this->fk->getLocalTableName()); |
|
92 | + $code .= sprintf($getterCode, |
|
93 | + $beanClass, |
|
94 | + implode(', ', $this->fk->getColumns()), |
|
95 | + $beanClass, |
|
96 | + $this->getName(), |
|
97 | + var_export($this->fk->getLocalTableName(), true), |
|
98 | + var_export($this->fk->getName(), true), |
|
99 | + var_export($this->fk->getLocalTableName(), true), |
|
100 | + $this->getFilters($this->fk) |
|
101 | + ); |
|
102 | + |
|
103 | + return $code; |
|
104 | + } |
|
105 | + |
|
106 | + private function getFilters(ForeignKeyConstraint $fk) : string |
|
107 | + { |
|
108 | + $counter = 0; |
|
109 | + $parameters = []; |
|
110 | + |
|
111 | + $pkColumns = $this->mainTable->getPrimaryKeyColumns(); |
|
112 | + |
|
113 | + foreach ($fk->getLocalColumns() as $columnName) { |
|
114 | + $pkColumn = $pkColumns[$counter]; |
|
115 | + $parameters[] = sprintf('%s => $this->get(%s, %s)', var_export($fk->getLocalTableName().'.'.$columnName, true), var_export($pkColumn, true), var_export($this->fk->getForeignTableName(), true)); |
|
116 | + ++$counter; |
|
117 | + } |
|
118 | + $parametersCode = '['.implode(', ', $parameters).']'; |
|
119 | + |
|
120 | + return $parametersCode; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Returns an array of classes that needs a "use" for this method. |
|
125 | + * |
|
126 | + * @return string[] |
|
127 | + */ |
|
128 | + public function getUsedClasses() : array |
|
129 | + { |
|
130 | + return [$this->namingStrategy->getBeanClassName($this->fk->getForeignTableName())]; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the code to past in jsonSerialize. |
|
135 | + * |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public function getJsonSerializeCode() : string |
|
139 | + { |
|
140 | + return ''; |
|
141 | + } |
|
142 | 142 | } |
@@ -11,12 +11,12 @@ |
||
11 | 11 | class VoidListener 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 do nothing. |
|
21 | - } |
|
14 | + /** |
|
15 | + * @param ConfigurationInterface $configuration |
|
16 | + * @param BeanDescriptorInterface[] $beanDescriptors |
|
17 | + */ |
|
18 | + public function onGenerate(ConfigurationInterface $configuration, array $beanDescriptors): void |
|
19 | + { |
|
20 | + // Let's do nothing. |
|
21 | + } |
|
22 | 22 | } |
@@ -12,169 +12,169 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class ObjectBeanPropertyDescriptor extends AbstractBeanPropertyDescriptor |
14 | 14 | { |
15 | - /** |
|
16 | - * @var ForeignKeyConstraint |
|
17 | - */ |
|
18 | - private $foreignKey; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var SchemaAnalyzer |
|
22 | - */ |
|
23 | - private $schemaAnalyzer; |
|
24 | - /** |
|
25 | - * @var NamingStrategyInterface |
|
26 | - */ |
|
27 | - private $namingStrategy; |
|
28 | - |
|
29 | - /** |
|
30 | - * ObjectBeanPropertyDescriptor constructor. |
|
31 | - * @param Table $table |
|
32 | - * @param ForeignKeyConstraint $foreignKey |
|
33 | - * @param SchemaAnalyzer $schemaAnalyzer |
|
34 | - * @param NamingStrategyInterface $namingStrategy |
|
35 | - */ |
|
36 | - public function __construct(Table $table, ForeignKeyConstraint $foreignKey, SchemaAnalyzer $schemaAnalyzer, NamingStrategyInterface $namingStrategy) |
|
37 | - { |
|
38 | - parent::__construct($table); |
|
39 | - $this->foreignKey = $foreignKey; |
|
40 | - $this->schemaAnalyzer = $schemaAnalyzer; |
|
41 | - $this->namingStrategy = $namingStrategy; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Returns the foreignkey the column is part of, if any. null otherwise. |
|
46 | - * |
|
47 | - * @return ForeignKeyConstraint|null |
|
48 | - */ |
|
49 | - public function getForeignKey() |
|
50 | - { |
|
51 | - return $this->foreignKey; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Returns the name of the class linked to this property or null if this is not a foreign key. |
|
56 | - * |
|
57 | - * @return null|string |
|
58 | - */ |
|
59 | - public function getClassName() |
|
60 | - { |
|
61 | - return $this->namingStrategy->getBeanClassName($this->foreignKey->getForeignTableName()); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Returns the param annotation for this property (useful for constructor). |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function getParamAnnotation() |
|
70 | - { |
|
71 | - $str = ' * @param %s %s'; |
|
72 | - |
|
73 | - return sprintf($str, $this->getClassName(), $this->getVariableName()); |
|
74 | - } |
|
75 | - |
|
76 | - public function getUpperCamelCaseName() |
|
77 | - { |
|
78 | - // First, are there many column or only one? |
|
79 | - // If one column, we name the setter after it. Otherwise, we name the setter after the table name |
|
80 | - if (count($this->foreignKey->getLocalColumns()) > 1) { |
|
81 | - $name = TDBMDaoGenerator::toSingular(TDBMDaoGenerator::toCamelCase($this->foreignKey->getForeignTableName())); |
|
82 | - if ($this->alternativeName) { |
|
83 | - $camelizedColumns = array_map(['Mouf\\Database\\TDBM\\Utils\\TDBMDaoGenerator', 'toCamelCase'], $this->foreignKey->getLocalColumns()); |
|
84 | - |
|
85 | - $name .= 'By'.implode('And', $camelizedColumns); |
|
86 | - } |
|
87 | - } else { |
|
88 | - $column = $this->foreignKey->getLocalColumns()[0]; |
|
89 | - // Let's remove any _id or id_. |
|
90 | - if (strpos(strtolower($column), 'id_') === 0) { |
|
91 | - $column = substr($column, 3); |
|
92 | - } |
|
93 | - if (strrpos(strtolower($column), '_id') === strlen($column) - 3) { |
|
94 | - $column = substr($column, 0, strlen($column) - 3); |
|
95 | - } |
|
96 | - $name = TDBMDaoGenerator::toCamelCase($column); |
|
97 | - if ($this->alternativeName) { |
|
98 | - $name .= 'Object'; |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - return $name; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
|
107 | - * |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public function isCompulsory() |
|
111 | - { |
|
112 | - // Are all columns nullable? |
|
113 | - $localColumnNames = $this->foreignKey->getLocalColumns(); |
|
114 | - |
|
115 | - foreach ($localColumnNames as $name) { |
|
116 | - $column = $this->table->getColumn($name); |
|
117 | - if ($column->getNotnull()) { |
|
118 | - return true; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - return false; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns true if the property has a default value. |
|
127 | - * |
|
128 | - * @return bool |
|
129 | - */ |
|
130 | - public function hasDefault() |
|
131 | - { |
|
132 | - return false; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Returns the code that assigns a value to its default value. |
|
137 | - * |
|
138 | - * @return string |
|
139 | - * |
|
140 | - * @throws \TDBMException |
|
141 | - */ |
|
142 | - public function assignToDefaultCode() |
|
143 | - { |
|
144 | - throw new \TDBMException('Foreign key based properties cannot be assigned a default value.'); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Returns true if the property is the primary key. |
|
149 | - * |
|
150 | - * @return bool |
|
151 | - */ |
|
152 | - public function isPrimaryKey() |
|
153 | - { |
|
154 | - $fkColumns = $this->foreignKey->getLocalColumns(); |
|
155 | - sort($fkColumns); |
|
156 | - |
|
157 | - $pkColumns = $this->table->getPrimaryKeyColumns(); |
|
158 | - sort($pkColumns); |
|
159 | - |
|
160 | - return $fkColumns == $pkColumns; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns the PHP code for getters and setters. |
|
165 | - * |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function getGetterSetterCode() |
|
169 | - { |
|
170 | - $tableName = $this->table->getName(); |
|
171 | - $getterName = $this->getGetterName(); |
|
172 | - $setterName = $this->getSetterName(); |
|
173 | - $isNullable = !$this->isCompulsory(); |
|
174 | - |
|
175 | - $referencedBeanName = $this->namingStrategy->getBeanClassName($this->foreignKey->getForeignTableName()); |
|
176 | - |
|
177 | - $str = ' /** |
|
15 | + /** |
|
16 | + * @var ForeignKeyConstraint |
|
17 | + */ |
|
18 | + private $foreignKey; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var SchemaAnalyzer |
|
22 | + */ |
|
23 | + private $schemaAnalyzer; |
|
24 | + /** |
|
25 | + * @var NamingStrategyInterface |
|
26 | + */ |
|
27 | + private $namingStrategy; |
|
28 | + |
|
29 | + /** |
|
30 | + * ObjectBeanPropertyDescriptor constructor. |
|
31 | + * @param Table $table |
|
32 | + * @param ForeignKeyConstraint $foreignKey |
|
33 | + * @param SchemaAnalyzer $schemaAnalyzer |
|
34 | + * @param NamingStrategyInterface $namingStrategy |
|
35 | + */ |
|
36 | + public function __construct(Table $table, ForeignKeyConstraint $foreignKey, SchemaAnalyzer $schemaAnalyzer, NamingStrategyInterface $namingStrategy) |
|
37 | + { |
|
38 | + parent::__construct($table); |
|
39 | + $this->foreignKey = $foreignKey; |
|
40 | + $this->schemaAnalyzer = $schemaAnalyzer; |
|
41 | + $this->namingStrategy = $namingStrategy; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Returns the foreignkey the column is part of, if any. null otherwise. |
|
46 | + * |
|
47 | + * @return ForeignKeyConstraint|null |
|
48 | + */ |
|
49 | + public function getForeignKey() |
|
50 | + { |
|
51 | + return $this->foreignKey; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Returns the name of the class linked to this property or null if this is not a foreign key. |
|
56 | + * |
|
57 | + * @return null|string |
|
58 | + */ |
|
59 | + public function getClassName() |
|
60 | + { |
|
61 | + return $this->namingStrategy->getBeanClassName($this->foreignKey->getForeignTableName()); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Returns the param annotation for this property (useful for constructor). |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function getParamAnnotation() |
|
70 | + { |
|
71 | + $str = ' * @param %s %s'; |
|
72 | + |
|
73 | + return sprintf($str, $this->getClassName(), $this->getVariableName()); |
|
74 | + } |
|
75 | + |
|
76 | + public function getUpperCamelCaseName() |
|
77 | + { |
|
78 | + // First, are there many column or only one? |
|
79 | + // If one column, we name the setter after it. Otherwise, we name the setter after the table name |
|
80 | + if (count($this->foreignKey->getLocalColumns()) > 1) { |
|
81 | + $name = TDBMDaoGenerator::toSingular(TDBMDaoGenerator::toCamelCase($this->foreignKey->getForeignTableName())); |
|
82 | + if ($this->alternativeName) { |
|
83 | + $camelizedColumns = array_map(['Mouf\\Database\\TDBM\\Utils\\TDBMDaoGenerator', 'toCamelCase'], $this->foreignKey->getLocalColumns()); |
|
84 | + |
|
85 | + $name .= 'By'.implode('And', $camelizedColumns); |
|
86 | + } |
|
87 | + } else { |
|
88 | + $column = $this->foreignKey->getLocalColumns()[0]; |
|
89 | + // Let's remove any _id or id_. |
|
90 | + if (strpos(strtolower($column), 'id_') === 0) { |
|
91 | + $column = substr($column, 3); |
|
92 | + } |
|
93 | + if (strrpos(strtolower($column), '_id') === strlen($column) - 3) { |
|
94 | + $column = substr($column, 0, strlen($column) - 3); |
|
95 | + } |
|
96 | + $name = TDBMDaoGenerator::toCamelCase($column); |
|
97 | + if ($this->alternativeName) { |
|
98 | + $name .= 'Object'; |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + return $name; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
|
107 | + * |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public function isCompulsory() |
|
111 | + { |
|
112 | + // Are all columns nullable? |
|
113 | + $localColumnNames = $this->foreignKey->getLocalColumns(); |
|
114 | + |
|
115 | + foreach ($localColumnNames as $name) { |
|
116 | + $column = $this->table->getColumn($name); |
|
117 | + if ($column->getNotnull()) { |
|
118 | + return true; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + return false; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns true if the property has a default value. |
|
127 | + * |
|
128 | + * @return bool |
|
129 | + */ |
|
130 | + public function hasDefault() |
|
131 | + { |
|
132 | + return false; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Returns the code that assigns a value to its default value. |
|
137 | + * |
|
138 | + * @return string |
|
139 | + * |
|
140 | + * @throws \TDBMException |
|
141 | + */ |
|
142 | + public function assignToDefaultCode() |
|
143 | + { |
|
144 | + throw new \TDBMException('Foreign key based properties cannot be assigned a default value.'); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Returns true if the property is the primary key. |
|
149 | + * |
|
150 | + * @return bool |
|
151 | + */ |
|
152 | + public function isPrimaryKey() |
|
153 | + { |
|
154 | + $fkColumns = $this->foreignKey->getLocalColumns(); |
|
155 | + sort($fkColumns); |
|
156 | + |
|
157 | + $pkColumns = $this->table->getPrimaryKeyColumns(); |
|
158 | + sort($pkColumns); |
|
159 | + |
|
160 | + return $fkColumns == $pkColumns; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns the PHP code for getters and setters. |
|
165 | + * |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function getGetterSetterCode() |
|
169 | + { |
|
170 | + $tableName = $this->table->getName(); |
|
171 | + $getterName = $this->getGetterName(); |
|
172 | + $setterName = $this->getSetterName(); |
|
173 | + $isNullable = !$this->isCompulsory(); |
|
174 | + |
|
175 | + $referencedBeanName = $this->namingStrategy->getBeanClassName($this->foreignKey->getForeignTableName()); |
|
176 | + |
|
177 | + $str = ' /** |
|
178 | 178 | * Returns the '.$referencedBeanName.' object bound to this object via the '.implode(' and ', $this->foreignKey->getLocalColumns()).' column. |
179 | 179 | * |
180 | 180 | * @return '.$referencedBeanName.($isNullable?'|null':'').' |
@@ -196,20 +196,20 @@ discard block |
||
196 | 196 | |
197 | 197 | '; |
198 | 198 | |
199 | - return $str; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Returns the part of code useful when doing json serialization. |
|
204 | - * |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public function getJsonSerializeCode() |
|
208 | - { |
|
209 | - return ' if (!$stopRecursion) { |
|
199 | + return $str; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Returns the part of code useful when doing json serialization. |
|
204 | + * |
|
205 | + * @return string |
|
206 | + */ |
|
207 | + public function getJsonSerializeCode() |
|
208 | + { |
|
209 | + return ' if (!$stopRecursion) { |
|
210 | 210 | $object = $this->'.$this->getGetterName().'(); |
211 | 211 | $array['.var_export($this->getLowerCamelCaseName(), true).'] = $object ? $object->jsonSerialize(true) : null; |
212 | 212 | } |
213 | 213 | '; |
214 | - } |
|
214 | + } |
|
215 | 215 | } |