@@ -30,234 +30,234 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class ResultIterator implements Result, \ArrayAccess, \JsonSerializable |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * @var Statement |
|
| 35 | - */ |
|
| 36 | - protected $statement; |
|
| 33 | + /** |
|
| 34 | + * @var Statement |
|
| 35 | + */ |
|
| 36 | + protected $statement; |
|
| 37 | 37 | |
| 38 | - protected $fetchStarted = false; |
|
| 39 | - private $objectStorage; |
|
| 40 | - private $className; |
|
| 38 | + protected $fetchStarted = false; |
|
| 39 | + private $objectStorage; |
|
| 40 | + private $className; |
|
| 41 | 41 | |
| 42 | - private $tdbmService; |
|
| 43 | - private $magicSql; |
|
| 44 | - private $magicSqlCount; |
|
| 45 | - private $parameters; |
|
| 46 | - private $columnDescriptors; |
|
| 47 | - private $magicQuery; |
|
| 42 | + private $tdbmService; |
|
| 43 | + private $magicSql; |
|
| 44 | + private $magicSqlCount; |
|
| 45 | + private $parameters; |
|
| 46 | + private $columnDescriptors; |
|
| 47 | + private $magicQuery; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var InnerResultIterator |
|
| 51 | - */ |
|
| 52 | - private $innerResultIterator; |
|
| 49 | + /** |
|
| 50 | + * @var InnerResultIterator |
|
| 51 | + */ |
|
| 52 | + private $innerResultIterator; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * The key of the current retrieved object. |
|
| 56 | - * |
|
| 57 | - * @var int |
|
| 58 | - */ |
|
| 59 | - protected $key = -1; |
|
| 54 | + /** |
|
| 55 | + * The key of the current retrieved object. |
|
| 56 | + * |
|
| 57 | + * @var int |
|
| 58 | + */ |
|
| 59 | + protected $key = -1; |
|
| 60 | 60 | |
| 61 | - protected $current = null; |
|
| 61 | + protected $current = null; |
|
| 62 | 62 | |
| 63 | - private $databasePlatform; |
|
| 63 | + private $databasePlatform; |
|
| 64 | 64 | |
| 65 | - private $totalCount; |
|
| 65 | + private $totalCount; |
|
| 66 | 66 | |
| 67 | - private $mode; |
|
| 67 | + private $mode; |
|
| 68 | 68 | |
| 69 | - public function __construct($magicSql, $magicSqlCount, array $parameters, array $columnDescriptors, $objectStorage, $className, TDBMService $tdbmService, MagicQuery $magicQuery, $mode) |
|
| 70 | - { |
|
| 71 | - $this->magicSql = $magicSql; |
|
| 72 | - $this->magicSqlCount = $magicSqlCount; |
|
| 73 | - $this->objectStorage = $objectStorage; |
|
| 74 | - $this->className = $className; |
|
| 75 | - $this->tdbmService = $tdbmService; |
|
| 76 | - $this->parameters = $parameters; |
|
| 77 | - $this->columnDescriptors = $columnDescriptors; |
|
| 78 | - $this->magicQuery = $magicQuery; |
|
| 79 | - $this->databasePlatform = $this->tdbmService->getConnection()->getDatabasePlatform(); |
|
| 80 | - $this->mode = $mode; |
|
| 81 | - } |
|
| 69 | + public function __construct($magicSql, $magicSqlCount, array $parameters, array $columnDescriptors, $objectStorage, $className, TDBMService $tdbmService, MagicQuery $magicQuery, $mode) |
|
| 70 | + { |
|
| 71 | + $this->magicSql = $magicSql; |
|
| 72 | + $this->magicSqlCount = $magicSqlCount; |
|
| 73 | + $this->objectStorage = $objectStorage; |
|
| 74 | + $this->className = $className; |
|
| 75 | + $this->tdbmService = $tdbmService; |
|
| 76 | + $this->parameters = $parameters; |
|
| 77 | + $this->columnDescriptors = $columnDescriptors; |
|
| 78 | + $this->magicQuery = $magicQuery; |
|
| 79 | + $this->databasePlatform = $this->tdbmService->getConnection()->getDatabasePlatform(); |
|
| 80 | + $this->mode = $mode; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - protected function executeCountQuery() |
|
| 84 | - { |
|
| 85 | - $sql = $this->magicQuery->build($this->magicSqlCount, $this->parameters); |
|
| 86 | - $this->totalCount = $this->tdbmService->getConnection()->fetchColumn($sql, $this->parameters); |
|
| 87 | - } |
|
| 83 | + protected function executeCountQuery() |
|
| 84 | + { |
|
| 85 | + $sql = $this->magicQuery->build($this->magicSqlCount, $this->parameters); |
|
| 86 | + $this->totalCount = $this->tdbmService->getConnection()->fetchColumn($sql, $this->parameters); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Counts found records (this is the number of records fetched, taking into account the LIMIT and OFFSET settings). |
|
| 91 | - * |
|
| 92 | - * @return int |
|
| 93 | - */ |
|
| 94 | - public function count() |
|
| 95 | - { |
|
| 96 | - if ($this->totalCount === null) { |
|
| 97 | - $this->executeCountQuery(); |
|
| 98 | - } |
|
| 89 | + /** |
|
| 90 | + * Counts found records (this is the number of records fetched, taking into account the LIMIT and OFFSET settings). |
|
| 91 | + * |
|
| 92 | + * @return int |
|
| 93 | + */ |
|
| 94 | + public function count() |
|
| 95 | + { |
|
| 96 | + if ($this->totalCount === null) { |
|
| 97 | + $this->executeCountQuery(); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - return $this->totalCount; |
|
| 101 | - } |
|
| 100 | + return $this->totalCount; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Casts the result set to a PHP array. |
|
| 105 | - * |
|
| 106 | - * @return array |
|
| 107 | - */ |
|
| 108 | - public function toArray() |
|
| 109 | - { |
|
| 110 | - return iterator_to_array($this->getIterator()); |
|
| 111 | - } |
|
| 103 | + /** |
|
| 104 | + * Casts the result set to a PHP array. |
|
| 105 | + * |
|
| 106 | + * @return array |
|
| 107 | + */ |
|
| 108 | + public function toArray() |
|
| 109 | + { |
|
| 110 | + return iterator_to_array($this->getIterator()); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Returns a new iterator mapping any call using the $callable function. |
|
| 115 | - * |
|
| 116 | - * @param callable $callable |
|
| 117 | - * |
|
| 118 | - * @return MapIterator |
|
| 119 | - */ |
|
| 120 | - public function map(callable $callable) |
|
| 121 | - { |
|
| 122 | - return new MapIterator($this->getIterator(), $callable); |
|
| 123 | - } |
|
| 113 | + /** |
|
| 114 | + * Returns a new iterator mapping any call using the $callable function. |
|
| 115 | + * |
|
| 116 | + * @param callable $callable |
|
| 117 | + * |
|
| 118 | + * @return MapIterator |
|
| 119 | + */ |
|
| 120 | + public function map(callable $callable) |
|
| 121 | + { |
|
| 122 | + return new MapIterator($this->getIterator(), $callable); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Retrieve an external iterator. |
|
| 127 | - * |
|
| 128 | - * @link http://php.net/manual/en/iteratoraggregate.getiterator.php |
|
| 129 | - * |
|
| 130 | - * @return InnerResultIterator An instance of an object implementing <b>Iterator</b> or |
|
| 131 | - * <b>Traversable</b> |
|
| 132 | - * |
|
| 133 | - * @since 5.0.0 |
|
| 134 | - */ |
|
| 135 | - public function getIterator() |
|
| 136 | - { |
|
| 137 | - if ($this->innerResultIterator === null) { |
|
| 138 | - if ($this->mode === TDBMService::MODE_CURSOR) { |
|
| 139 | - $this->innerResultIterator = new InnerResultIterator($this->magicSql, $this->parameters, null, null, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery); |
|
| 140 | - } else { |
|
| 141 | - $this->innerResultIterator = new InnerResultArray($this->magicSql, $this->parameters, null, null, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery); |
|
| 142 | - } |
|
| 143 | - } |
|
| 125 | + /** |
|
| 126 | + * Retrieve an external iterator. |
|
| 127 | + * |
|
| 128 | + * @link http://php.net/manual/en/iteratoraggregate.getiterator.php |
|
| 129 | + * |
|
| 130 | + * @return InnerResultIterator An instance of an object implementing <b>Iterator</b> or |
|
| 131 | + * <b>Traversable</b> |
|
| 132 | + * |
|
| 133 | + * @since 5.0.0 |
|
| 134 | + */ |
|
| 135 | + public function getIterator() |
|
| 136 | + { |
|
| 137 | + if ($this->innerResultIterator === null) { |
|
| 138 | + if ($this->mode === TDBMService::MODE_CURSOR) { |
|
| 139 | + $this->innerResultIterator = new InnerResultIterator($this->magicSql, $this->parameters, null, null, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery); |
|
| 140 | + } else { |
|
| 141 | + $this->innerResultIterator = new InnerResultArray($this->magicSql, $this->parameters, null, null, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - return $this->innerResultIterator; |
|
| 146 | - } |
|
| 145 | + return $this->innerResultIterator; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * @param int $offset |
|
| 150 | - * |
|
| 151 | - * @return PageIterator |
|
| 152 | - */ |
|
| 153 | - public function take($offset, $limit) |
|
| 154 | - { |
|
| 155 | - return new PageIterator($this, $this->magicSql, $this->parameters, $limit, $offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->mode); |
|
| 156 | - } |
|
| 148 | + /** |
|
| 149 | + * @param int $offset |
|
| 150 | + * |
|
| 151 | + * @return PageIterator |
|
| 152 | + */ |
|
| 153 | + public function take($offset, $limit) |
|
| 154 | + { |
|
| 155 | + return new PageIterator($this, $this->magicSql, $this->parameters, $limit, $offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->mode); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Whether a offset exists. |
|
| 160 | - * |
|
| 161 | - * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
|
| 162 | - * |
|
| 163 | - * @param mixed $offset <p> |
|
| 164 | - * An offset to check for. |
|
| 165 | - * </p> |
|
| 166 | - * |
|
| 167 | - * @return bool true on success or false on failure. |
|
| 168 | - * </p> |
|
| 169 | - * <p> |
|
| 170 | - * The return value will be casted to boolean if non-boolean was returned. |
|
| 171 | - * |
|
| 172 | - * @since 5.0.0 |
|
| 173 | - */ |
|
| 174 | - public function offsetExists($offset) |
|
| 175 | - { |
|
| 176 | - return $this->getIterator()->offsetExists($offset); |
|
| 177 | - } |
|
| 158 | + /** |
|
| 159 | + * Whether a offset exists. |
|
| 160 | + * |
|
| 161 | + * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
|
| 162 | + * |
|
| 163 | + * @param mixed $offset <p> |
|
| 164 | + * An offset to check for. |
|
| 165 | + * </p> |
|
| 166 | + * |
|
| 167 | + * @return bool true on success or false on failure. |
|
| 168 | + * </p> |
|
| 169 | + * <p> |
|
| 170 | + * The return value will be casted to boolean if non-boolean was returned. |
|
| 171 | + * |
|
| 172 | + * @since 5.0.0 |
|
| 173 | + */ |
|
| 174 | + public function offsetExists($offset) |
|
| 175 | + { |
|
| 176 | + return $this->getIterator()->offsetExists($offset); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * Offset to retrieve. |
|
| 181 | - * |
|
| 182 | - * @link http://php.net/manual/en/arrayaccess.offsetget.php |
|
| 183 | - * |
|
| 184 | - * @param mixed $offset <p> |
|
| 185 | - * The offset to retrieve. |
|
| 186 | - * </p> |
|
| 187 | - * |
|
| 188 | - * @return mixed Can return all value types. |
|
| 189 | - * |
|
| 190 | - * @since 5.0.0 |
|
| 191 | - */ |
|
| 192 | - public function offsetGet($offset) |
|
| 193 | - { |
|
| 194 | - return $this->getIterator()->offsetGet($offset); |
|
| 195 | - } |
|
| 179 | + /** |
|
| 180 | + * Offset to retrieve. |
|
| 181 | + * |
|
| 182 | + * @link http://php.net/manual/en/arrayaccess.offsetget.php |
|
| 183 | + * |
|
| 184 | + * @param mixed $offset <p> |
|
| 185 | + * The offset to retrieve. |
|
| 186 | + * </p> |
|
| 187 | + * |
|
| 188 | + * @return mixed Can return all value types. |
|
| 189 | + * |
|
| 190 | + * @since 5.0.0 |
|
| 191 | + */ |
|
| 192 | + public function offsetGet($offset) |
|
| 193 | + { |
|
| 194 | + return $this->getIterator()->offsetGet($offset); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Offset to set. |
|
| 199 | - * |
|
| 200 | - * @link http://php.net/manual/en/arrayaccess.offsetset.php |
|
| 201 | - * |
|
| 202 | - * @param mixed $offset <p> |
|
| 203 | - * The offset to assign the value to. |
|
| 204 | - * </p> |
|
| 205 | - * @param mixed $value <p> |
|
| 206 | - * The value to set. |
|
| 207 | - * </p> |
|
| 208 | - * |
|
| 209 | - * @since 5.0.0 |
|
| 210 | - */ |
|
| 211 | - public function offsetSet($offset, $value) |
|
| 212 | - { |
|
| 213 | - return $this->getIterator()->offsetSet($offset, $value); |
|
| 214 | - } |
|
| 197 | + /** |
|
| 198 | + * Offset to set. |
|
| 199 | + * |
|
| 200 | + * @link http://php.net/manual/en/arrayaccess.offsetset.php |
|
| 201 | + * |
|
| 202 | + * @param mixed $offset <p> |
|
| 203 | + * The offset to assign the value to. |
|
| 204 | + * </p> |
|
| 205 | + * @param mixed $value <p> |
|
| 206 | + * The value to set. |
|
| 207 | + * </p> |
|
| 208 | + * |
|
| 209 | + * @since 5.0.0 |
|
| 210 | + */ |
|
| 211 | + public function offsetSet($offset, $value) |
|
| 212 | + { |
|
| 213 | + return $this->getIterator()->offsetSet($offset, $value); |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * Offset to unset. |
|
| 218 | - * |
|
| 219 | - * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
|
| 220 | - * |
|
| 221 | - * @param mixed $offset <p> |
|
| 222 | - * The offset to unset. |
|
| 223 | - * </p> |
|
| 224 | - * |
|
| 225 | - * @since 5.0.0 |
|
| 226 | - */ |
|
| 227 | - public function offsetUnset($offset) |
|
| 228 | - { |
|
| 229 | - return $this->getIterator()->offsetUnset($offset); |
|
| 230 | - } |
|
| 216 | + /** |
|
| 217 | + * Offset to unset. |
|
| 218 | + * |
|
| 219 | + * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
|
| 220 | + * |
|
| 221 | + * @param mixed $offset <p> |
|
| 222 | + * The offset to unset. |
|
| 223 | + * </p> |
|
| 224 | + * |
|
| 225 | + * @since 5.0.0 |
|
| 226 | + */ |
|
| 227 | + public function offsetUnset($offset) |
|
| 228 | + { |
|
| 229 | + return $this->getIterator()->offsetUnset($offset); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Specify data which should be serialized to JSON. |
|
| 234 | - * |
|
| 235 | - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
| 236 | - * |
|
| 237 | - * @return mixed data which can be serialized by <b>json_encode</b>, |
|
| 238 | - * which is a value of any type other than a resource. |
|
| 239 | - * |
|
| 240 | - * @since 5.4.0 |
|
| 241 | - */ |
|
| 242 | - public function jsonSerialize() |
|
| 243 | - { |
|
| 244 | - return array_map(function (AbstractTDBMObject $item) { |
|
| 245 | - return $item->jsonSerialize(); |
|
| 246 | - }, $this->toArray()); |
|
| 247 | - } |
|
| 232 | + /** |
|
| 233 | + * Specify data which should be serialized to JSON. |
|
| 234 | + * |
|
| 235 | + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
| 236 | + * |
|
| 237 | + * @return mixed data which can be serialized by <b>json_encode</b>, |
|
| 238 | + * which is a value of any type other than a resource. |
|
| 239 | + * |
|
| 240 | + * @since 5.4.0 |
|
| 241 | + */ |
|
| 242 | + public function jsonSerialize() |
|
| 243 | + { |
|
| 244 | + return array_map(function (AbstractTDBMObject $item) { |
|
| 245 | + return $item->jsonSerialize(); |
|
| 246 | + }, $this->toArray()); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * Returns only one value (the first) of the result set. |
|
| 251 | - * Returns null if no value exists. |
|
| 252 | - * |
|
| 253 | - * @return mixed|null |
|
| 254 | - */ |
|
| 255 | - public function first() |
|
| 256 | - { |
|
| 257 | - $page = $this->take(0, 1); |
|
| 258 | - foreach ($page as $bean) { |
|
| 259 | - return $bean; |
|
| 260 | - } |
|
| 261 | - return null; |
|
| 262 | - } |
|
| 249 | + /** |
|
| 250 | + * Returns only one value (the first) of the result set. |
|
| 251 | + * Returns null if no value exists. |
|
| 252 | + * |
|
| 253 | + * @return mixed|null |
|
| 254 | + */ |
|
| 255 | + public function first() |
|
| 256 | + { |
|
| 257 | + $page = $this->take(0, 1); |
|
| 258 | + foreach ($page as $bean) { |
|
| 259 | + return $bean; |
|
| 260 | + } |
|
| 261 | + return null; |
|
| 262 | + } |
|
| 263 | 263 | } |
@@ -11,98 +11,98 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class ScalarBeanPropertyDescriptor extends AbstractBeanPropertyDescriptor |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var Column |
|
| 16 | - */ |
|
| 17 | - private $column; |
|
| 18 | - |
|
| 19 | - public function __construct(Table $table, Column $column) |
|
| 20 | - { |
|
| 21 | - parent::__construct($table); |
|
| 22 | - $this->table = $table; |
|
| 23 | - $this->column = $column; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Returns the foreign-key the column is part of, if any. null otherwise. |
|
| 28 | - * |
|
| 29 | - * @return ForeignKeyConstraint|null |
|
| 30 | - */ |
|
| 31 | - public function getForeignKey() |
|
| 32 | - { |
|
| 33 | - return false; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Returns the param annotation for this property (useful for constructor). |
|
| 38 | - * |
|
| 39 | - * @return string |
|
| 40 | - */ |
|
| 41 | - public function getParamAnnotation() |
|
| 42 | - { |
|
| 43 | - $className = $this->getClassName(); |
|
| 44 | - $paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType()); |
|
| 45 | - |
|
| 46 | - $str = ' * @param %s %s'; |
|
| 47 | - |
|
| 48 | - return sprintf($str, $paramType, $this->getVariableName()); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function getUpperCamelCaseName() |
|
| 52 | - { |
|
| 53 | - return TDBMDaoGenerator::toCamelCase($this->column->getName()); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Returns the name of the class linked to this property or null if this is not a foreign key. |
|
| 58 | - * |
|
| 59 | - * @return null|string |
|
| 60 | - */ |
|
| 61 | - public function getClassName() |
|
| 62 | - { |
|
| 63 | - return; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
|
| 68 | - * |
|
| 69 | - * @return bool |
|
| 70 | - */ |
|
| 71 | - public function isCompulsory() |
|
| 72 | - { |
|
| 73 | - return $this->column->getNotnull() && !$this->column->getAutoincrement(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Returns true if the property is the primary key. |
|
| 78 | - * |
|
| 79 | - * @return bool |
|
| 80 | - */ |
|
| 81 | - public function isPrimaryKey() |
|
| 82 | - { |
|
| 83 | - return in_array($this->column->getName(), $this->table->getPrimaryKeyColumns()); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Returns the PHP code for getters and setters. |
|
| 88 | - * |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function getGetterSetterCode() |
|
| 92 | - { |
|
| 93 | - $type = $this->column->getType(); |
|
| 94 | - $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
| 95 | - |
|
| 96 | - $columnGetterName = $this->getGetterName(); |
|
| 97 | - $columnSetterName = $this->getSetterName(); |
|
| 98 | - |
|
| 99 | - if ($normalizedType == '\\DateTimeInterface') { |
|
| 100 | - $castTo = '\\DateTimeInterface '; |
|
| 101 | - } else { |
|
| 102 | - $castTo = ''; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $getterAndSetterCode = ' /** |
|
| 14 | + /** |
|
| 15 | + * @var Column |
|
| 16 | + */ |
|
| 17 | + private $column; |
|
| 18 | + |
|
| 19 | + public function __construct(Table $table, Column $column) |
|
| 20 | + { |
|
| 21 | + parent::__construct($table); |
|
| 22 | + $this->table = $table; |
|
| 23 | + $this->column = $column; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Returns the foreign-key the column is part of, if any. null otherwise. |
|
| 28 | + * |
|
| 29 | + * @return ForeignKeyConstraint|null |
|
| 30 | + */ |
|
| 31 | + public function getForeignKey() |
|
| 32 | + { |
|
| 33 | + return false; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Returns the param annotation for this property (useful for constructor). |
|
| 38 | + * |
|
| 39 | + * @return string |
|
| 40 | + */ |
|
| 41 | + public function getParamAnnotation() |
|
| 42 | + { |
|
| 43 | + $className = $this->getClassName(); |
|
| 44 | + $paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType()); |
|
| 45 | + |
|
| 46 | + $str = ' * @param %s %s'; |
|
| 47 | + |
|
| 48 | + return sprintf($str, $paramType, $this->getVariableName()); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function getUpperCamelCaseName() |
|
| 52 | + { |
|
| 53 | + return TDBMDaoGenerator::toCamelCase($this->column->getName()); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Returns the name of the class linked to this property or null if this is not a foreign key. |
|
| 58 | + * |
|
| 59 | + * @return null|string |
|
| 60 | + */ |
|
| 61 | + public function getClassName() |
|
| 62 | + { |
|
| 63 | + return; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
|
| 68 | + * |
|
| 69 | + * @return bool |
|
| 70 | + */ |
|
| 71 | + public function isCompulsory() |
|
| 72 | + { |
|
| 73 | + return $this->column->getNotnull() && !$this->column->getAutoincrement(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Returns true if the property is the primary key. |
|
| 78 | + * |
|
| 79 | + * @return bool |
|
| 80 | + */ |
|
| 81 | + public function isPrimaryKey() |
|
| 82 | + { |
|
| 83 | + return in_array($this->column->getName(), $this->table->getPrimaryKeyColumns()); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Returns the PHP code for getters and setters. |
|
| 88 | + * |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function getGetterSetterCode() |
|
| 92 | + { |
|
| 93 | + $type = $this->column->getType(); |
|
| 94 | + $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
| 95 | + |
|
| 96 | + $columnGetterName = $this->getGetterName(); |
|
| 97 | + $columnSetterName = $this->getSetterName(); |
|
| 98 | + |
|
| 99 | + if ($normalizedType == '\\DateTimeInterface') { |
|
| 100 | + $castTo = '\\DateTimeInterface '; |
|
| 101 | + } else { |
|
| 102 | + $castTo = ''; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $getterAndSetterCode = ' /** |
|
| 106 | 106 | * The getter for the "%s" column. |
| 107 | 107 | * |
| 108 | 108 | * @return %s |
@@ -122,50 +122,50 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | '; |
| 124 | 124 | |
| 125 | - return sprintf($getterAndSetterCode, |
|
| 126 | - // Getter |
|
| 127 | - $this->column->getName(), |
|
| 128 | - $normalizedType, |
|
| 129 | - $columnGetterName, |
|
| 130 | - var_export($this->column->getName(), true), |
|
| 131 | - var_export($this->table->getName(), true), |
|
| 132 | - // Setter |
|
| 133 | - $this->column->getName(), |
|
| 134 | - $normalizedType, |
|
| 135 | - $this->column->getName(), |
|
| 136 | - $columnSetterName, |
|
| 137 | - $castTo, |
|
| 138 | - $this->column->getName(), |
|
| 139 | - var_export($this->column->getName(), true), |
|
| 140 | - $this->column->getName(), |
|
| 141 | - var_export($this->table->getName(), true) |
|
| 142 | - ); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Returns the part of code useful when doing json serialization. |
|
| 147 | - * |
|
| 148 | - * @return string |
|
| 149 | - */ |
|
| 150 | - public function getJsonSerializeCode() |
|
| 151 | - { |
|
| 152 | - $type = $this->column->getType(); |
|
| 153 | - $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
| 154 | - |
|
| 155 | - if ($normalizedType == '\\DateTimeInterface') { |
|
| 156 | - return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = ($this->'.$this->getGetterName().'() === null)?null:$this->'.$this->getGetterName()."()->format('c');\n"; |
|
| 157 | - } else { |
|
| 158 | - return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."();\n"; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Returns the column name. |
|
| 164 | - * |
|
| 165 | - * @return string |
|
| 166 | - */ |
|
| 167 | - public function getColumnName() |
|
| 168 | - { |
|
| 169 | - return $this->column->getName(); |
|
| 170 | - } |
|
| 125 | + return sprintf($getterAndSetterCode, |
|
| 126 | + // Getter |
|
| 127 | + $this->column->getName(), |
|
| 128 | + $normalizedType, |
|
| 129 | + $columnGetterName, |
|
| 130 | + var_export($this->column->getName(), true), |
|
| 131 | + var_export($this->table->getName(), true), |
|
| 132 | + // Setter |
|
| 133 | + $this->column->getName(), |
|
| 134 | + $normalizedType, |
|
| 135 | + $this->column->getName(), |
|
| 136 | + $columnSetterName, |
|
| 137 | + $castTo, |
|
| 138 | + $this->column->getName(), |
|
| 139 | + var_export($this->column->getName(), true), |
|
| 140 | + $this->column->getName(), |
|
| 141 | + var_export($this->table->getName(), true) |
|
| 142 | + ); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Returns the part of code useful when doing json serialization. |
|
| 147 | + * |
|
| 148 | + * @return string |
|
| 149 | + */ |
|
| 150 | + public function getJsonSerializeCode() |
|
| 151 | + { |
|
| 152 | + $type = $this->column->getType(); |
|
| 153 | + $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
| 154 | + |
|
| 155 | + if ($normalizedType == '\\DateTimeInterface') { |
|
| 156 | + return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = ($this->'.$this->getGetterName().'() === null)?null:$this->'.$this->getGetterName()."()->format('c');\n"; |
|
| 157 | + } else { |
|
| 158 | + return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."();\n"; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Returns the column name. |
|
| 164 | + * |
|
| 165 | + * @return string |
|
| 166 | + */ |
|
| 167 | + public function getColumnName() |
|
| 168 | + { |
|
| 169 | + return $this->column->getName(); |
|
| 170 | + } |
|
| 171 | 171 | } |