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