@@ -4,36 +4,36 @@ |
||
4 | 4 | |
5 | 5 | interface MethodDescriptorInterface |
6 | 6 | { |
7 | - /** |
|
8 | - * Returns the name of the method to be generated. |
|
9 | - * |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - public function getName() : string; |
|
7 | + /** |
|
8 | + * Returns the name of the method to be generated. |
|
9 | + * |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + public function getName() : string; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Requests the use of an alternative name for this method. |
|
16 | - */ |
|
17 | - public function useAlternativeName(); |
|
14 | + /** |
|
15 | + * Requests the use of an alternative name for this method. |
|
16 | + */ |
|
17 | + public function useAlternativeName(); |
|
18 | 18 | |
19 | - /** |
|
20 | - * Returns the code of the method. |
|
21 | - * |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function getCode() : string; |
|
19 | + /** |
|
20 | + * Returns the code of the method. |
|
21 | + * |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function getCode() : string; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns an array of classes that needs a "use" for this method. |
|
28 | - * |
|
29 | - * @return string[] |
|
30 | - */ |
|
31 | - public function getUsedClasses() : array; |
|
26 | + /** |
|
27 | + * Returns an array of classes that needs a "use" for this method. |
|
28 | + * |
|
29 | + * @return string[] |
|
30 | + */ |
|
31 | + public function getUsedClasses() : array; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Returns the code to past in jsonSerialize. |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getJsonSerializeCode() : string; |
|
33 | + /** |
|
34 | + * Returns the code to past in jsonSerialize. |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getJsonSerializeCode() : string; |
|
39 | 39 | } |
@@ -7,98 +7,98 @@ 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 | - /** |
|
28 | - * @param Table $pivotTable The pivot table |
|
29 | - * @param Table $mainBeanTable The main bean table |
|
30 | - */ |
|
31 | - public function __construct(Table $pivotTable, ForeignKeyConstraint $localFk, ForeignKeyConstraint $remoteFk) |
|
32 | - { |
|
33 | - $this->pivotTable = $pivotTable; |
|
34 | - $this->localFk = $localFk; |
|
35 | - $this->remoteFk = $remoteFk; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Requests the use of an alternative name for this method. |
|
40 | - */ |
|
41 | - public function useAlternativeName() |
|
42 | - { |
|
43 | - $this->useAlternateName = true; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Returns the name of the method to be generated. |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function getName() : string |
|
52 | - { |
|
53 | - if (!$this->useAlternateName) { |
|
54 | - return 'get'.TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()); |
|
55 | - } else { |
|
56 | - return 'get'.TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Returns the plural name. |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - private function getPluralName() : string |
|
66 | - { |
|
67 | - if (!$this->useAlternateName) { |
|
68 | - return TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()); |
|
69 | - } else { |
|
70 | - return TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Returns the singular name. |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - private function getSingularName() : string |
|
80 | - { |
|
81 | - if (!$this->useAlternateName) { |
|
82 | - return TDBMDaoGenerator::toCamelCase(TDBMDaoGenerator::toSingular($this->remoteFk->getForeignTableName())); |
|
83 | - } else { |
|
84 | - return TDBMDaoGenerator::toCamelCase(TDBMDaoGenerator::toSingular($this->remoteFk->getForeignTableName())).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Returns the code of the method. |
|
90 | - * |
|
91 | - * @return string |
|
92 | - */ |
|
93 | - public function getCode() : string |
|
94 | - { |
|
95 | - $singularName = $this->getSingularName(); |
|
96 | - $pluralName = $this->getPluralName(); |
|
97 | - $remoteBeanName = TDBMDaoGenerator::getBeanNameFromTableName($this->remoteFk->getForeignTableName()); |
|
98 | - $variableName = '$'.TDBMDaoGenerator::toVariableName($remoteBeanName); |
|
99 | - $pluralVariableName = $variableName.'s'; |
|
100 | - |
|
101 | - $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 | + /** |
|
28 | + * @param Table $pivotTable The pivot table |
|
29 | + * @param Table $mainBeanTable The main bean table |
|
30 | + */ |
|
31 | + public function __construct(Table $pivotTable, ForeignKeyConstraint $localFk, ForeignKeyConstraint $remoteFk) |
|
32 | + { |
|
33 | + $this->pivotTable = $pivotTable; |
|
34 | + $this->localFk = $localFk; |
|
35 | + $this->remoteFk = $remoteFk; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Requests the use of an alternative name for this method. |
|
40 | + */ |
|
41 | + public function useAlternativeName() |
|
42 | + { |
|
43 | + $this->useAlternateName = true; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Returns the name of the method to be generated. |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function getName() : string |
|
52 | + { |
|
53 | + if (!$this->useAlternateName) { |
|
54 | + return 'get'.TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()); |
|
55 | + } else { |
|
56 | + return 'get'.TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Returns the plural name. |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + private function getPluralName() : string |
|
66 | + { |
|
67 | + if (!$this->useAlternateName) { |
|
68 | + return TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()); |
|
69 | + } else { |
|
70 | + return TDBMDaoGenerator::toCamelCase($this->remoteFk->getForeignTableName()).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Returns the singular name. |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + private function getSingularName() : string |
|
80 | + { |
|
81 | + if (!$this->useAlternateName) { |
|
82 | + return TDBMDaoGenerator::toCamelCase(TDBMDaoGenerator::toSingular($this->remoteFk->getForeignTableName())); |
|
83 | + } else { |
|
84 | + return TDBMDaoGenerator::toCamelCase(TDBMDaoGenerator::toSingular($this->remoteFk->getForeignTableName())).'By'.TDBMDaoGenerator::toCamelCase($this->pivotTable->getName()); |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Returns the code of the method. |
|
90 | + * |
|
91 | + * @return string |
|
92 | + */ |
|
93 | + public function getCode() : string |
|
94 | + { |
|
95 | + $singularName = $this->getSingularName(); |
|
96 | + $pluralName = $this->getPluralName(); |
|
97 | + $remoteBeanName = TDBMDaoGenerator::getBeanNameFromTableName($this->remoteFk->getForeignTableName()); |
|
98 | + $variableName = '$'.TDBMDaoGenerator::toVariableName($remoteBeanName); |
|
99 | + $pluralVariableName = $variableName.'s'; |
|
100 | + |
|
101 | + $str = ' /** |
|
102 | 102 | * Returns the list of %s associated to this bean via the %s pivot table. |
103 | 103 | * |
104 | 104 | * @return %s[] |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | } |
110 | 110 | '; |
111 | 111 | |
112 | - $getterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralName, var_export($this->remoteFk->getLocalTableName(), true)); |
|
112 | + $getterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralName, var_export($this->remoteFk->getLocalTableName(), true)); |
|
113 | 113 | |
114 | - $str = ' /** |
|
114 | + $str = ' /** |
|
115 | 115 | * Adds a relationship with %s associated to this bean via the %s pivot table. |
116 | 116 | * |
117 | 117 | * @param %s %s |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | } |
123 | 123 | '; |
124 | 124 | |
125 | - $adderCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
125 | + $adderCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
126 | 126 | |
127 | - $str = ' /** |
|
127 | + $str = ' /** |
|
128 | 128 | * Deletes the relationship with %s associated to this bean via the %s pivot table. |
129 | 129 | * |
130 | 130 | * @param %s %s |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | } |
136 | 136 | '; |
137 | 137 | |
138 | - $removerCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
138 | + $removerCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
139 | 139 | |
140 | - $str = ' /** |
|
140 | + $str = ' /** |
|
141 | 141 | * Returns whether this bean is associated with %s via the %s pivot table. |
142 | 142 | * |
143 | 143 | * @param %s %s |
@@ -149,9 +149,9 @@ discard block |
||
149 | 149 | } |
150 | 150 | '; |
151 | 151 | |
152 | - $hasCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
152 | + $hasCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
|
153 | 153 | |
154 | - $str = ' /** |
|
154 | + $str = ' /** |
|
155 | 155 | * Sets all relationships with %s associated to this bean via the %s pivot table. |
156 | 156 | * Exiting relationships will be removed and replaced by the provided relationships. |
157 | 157 | * |
@@ -163,38 +163,38 @@ discard block |
||
163 | 163 | } |
164 | 164 | '; |
165 | 165 | |
166 | - $setterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralVariableName, $pluralName, $pluralVariableName, var_export($this->remoteFk->getLocalTableName(), true), $pluralVariableName); |
|
167 | - |
|
168 | - $code = $getterCode.$adderCode.$removerCode.$hasCode.$setterCode; |
|
169 | - |
|
170 | - return $code; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Returns an array of classes that needs a "use" for this method. |
|
175 | - * |
|
176 | - * @return string[] |
|
177 | - */ |
|
178 | - public function getUsedClasses() : array |
|
179 | - { |
|
180 | - return [TDBMDaoGenerator::getBeanNameFromTableName($this->remoteFk->getForeignTableName())]; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Returns the code to past in jsonSerialize. |
|
185 | - * |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function getJsonSerializeCode() : string |
|
189 | - { |
|
190 | - $remoteBeanName = TDBMDaoGenerator::getBeanNameFromTableName($this->remoteFk->getForeignTableName()); |
|
191 | - $variableName = '$'.TDBMDaoGenerator::toVariableName($remoteBeanName); |
|
192 | - |
|
193 | - return ' if (!$stopRecursion) { |
|
166 | + $setterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralVariableName, $pluralName, $pluralVariableName, var_export($this->remoteFk->getLocalTableName(), true), $pluralVariableName); |
|
167 | + |
|
168 | + $code = $getterCode.$adderCode.$removerCode.$hasCode.$setterCode; |
|
169 | + |
|
170 | + return $code; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Returns an array of classes that needs a "use" for this method. |
|
175 | + * |
|
176 | + * @return string[] |
|
177 | + */ |
|
178 | + public function getUsedClasses() : array |
|
179 | + { |
|
180 | + return [TDBMDaoGenerator::getBeanNameFromTableName($this->remoteFk->getForeignTableName())]; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Returns the code to past in jsonSerialize. |
|
185 | + * |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function getJsonSerializeCode() : string |
|
189 | + { |
|
190 | + $remoteBeanName = TDBMDaoGenerator::getBeanNameFromTableName($this->remoteFk->getForeignTableName()); |
|
191 | + $variableName = '$'.TDBMDaoGenerator::toVariableName($remoteBeanName); |
|
192 | + |
|
193 | + return ' if (!$stopRecursion) { |
|
194 | 194 | $array[\''.lcfirst($this->getPluralName()).'\'] = array_map(function ('.$remoteBeanName.' '.$variableName.') { |
195 | 195 | return '.$variableName.'->jsonSerialize(true); |
196 | 196 | }, $this->'.$this->getName().'()); |
197 | 197 | } |
198 | 198 | '; |
199 | - } |
|
199 | + } |
|
200 | 200 | } |