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