@@ -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()."()->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()."()->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 | } |
@@ -9,86 +9,86 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class MapIterator implements Iterator |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var Iterator |
|
| 14 | - */ |
|
| 15 | - protected $iterator; |
|
| 12 | + /** |
|
| 13 | + * @var Iterator |
|
| 14 | + */ |
|
| 15 | + protected $iterator; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var callable Modifies the current item in iterator |
|
| 19 | - */ |
|
| 20 | - protected $callable; |
|
| 17 | + /** |
|
| 18 | + * @var callable Modifies the current item in iterator |
|
| 19 | + */ |
|
| 20 | + protected $callable; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param $iterator Iterator|array |
|
| 24 | - * @param $callable callable This can have two parameters |
|
| 25 | - * |
|
| 26 | - * @throws TDBMException |
|
| 27 | - */ |
|
| 28 | - public function __construct($iterator, callable $callable) |
|
| 29 | - { |
|
| 30 | - if (is_array($iterator)) { |
|
| 31 | - $this->iterator = new \ArrayIterator($iterator); |
|
| 32 | - } elseif (!($iterator instanceof Iterator)) { |
|
| 33 | - throw new TDBMException('$iterator parameter must be an instance of Iterator'); |
|
| 34 | - } else { |
|
| 35 | - $this->iterator = $iterator; |
|
| 36 | - } |
|
| 22 | + /** |
|
| 23 | + * @param $iterator Iterator|array |
|
| 24 | + * @param $callable callable This can have two parameters |
|
| 25 | + * |
|
| 26 | + * @throws TDBMException |
|
| 27 | + */ |
|
| 28 | + public function __construct($iterator, callable $callable) |
|
| 29 | + { |
|
| 30 | + if (is_array($iterator)) { |
|
| 31 | + $this->iterator = new \ArrayIterator($iterator); |
|
| 32 | + } elseif (!($iterator instanceof Iterator)) { |
|
| 33 | + throw new TDBMException('$iterator parameter must be an instance of Iterator'); |
|
| 34 | + } else { |
|
| 35 | + $this->iterator = $iterator; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - if ($callable instanceof \Closure) { |
|
| 39 | - // make sure there's one argument |
|
| 40 | - $reflection = new \ReflectionObject($callable); |
|
| 41 | - if ($reflection->hasMethod('__invoke')) { |
|
| 42 | - $method = $reflection->getMethod('__invoke'); |
|
| 43 | - if ($method->getNumberOfParameters() !== 1) { |
|
| 44 | - throw new TDBMException('$callable must accept one and only one parameter.'); |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 38 | + if ($callable instanceof \Closure) { |
|
| 39 | + // make sure there's one argument |
|
| 40 | + $reflection = new \ReflectionObject($callable); |
|
| 41 | + if ($reflection->hasMethod('__invoke')) { |
|
| 42 | + $method = $reflection->getMethod('__invoke'); |
|
| 43 | + if ($method->getNumberOfParameters() !== 1) { |
|
| 44 | + throw new TDBMException('$callable must accept one and only one parameter.'); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - $this->callable = $callable; |
|
| 50 | - } |
|
| 49 | + $this->callable = $callable; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Alters the current item with $this->callable and returns a new item. |
|
| 54 | - * Be careful with your types as we can't do static type checking here! |
|
| 55 | - * |
|
| 56 | - * @return mixed |
|
| 57 | - */ |
|
| 58 | - public function current() |
|
| 59 | - { |
|
| 60 | - $callable = $this->callable; |
|
| 52 | + /** |
|
| 53 | + * Alters the current item with $this->callable and returns a new item. |
|
| 54 | + * Be careful with your types as we can't do static type checking here! |
|
| 55 | + * |
|
| 56 | + * @return mixed |
|
| 57 | + */ |
|
| 58 | + public function current() |
|
| 59 | + { |
|
| 60 | + $callable = $this->callable; |
|
| 61 | 61 | |
| 62 | - return $callable($this->iterator->current()); |
|
| 63 | - } |
|
| 62 | + return $callable($this->iterator->current()); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function next() |
|
| 66 | - { |
|
| 67 | - $this->iterator->next(); |
|
| 68 | - } |
|
| 65 | + public function next() |
|
| 66 | + { |
|
| 67 | + $this->iterator->next(); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - public function key() |
|
| 71 | - { |
|
| 72 | - return $this->iterator->key(); |
|
| 73 | - } |
|
| 70 | + public function key() |
|
| 71 | + { |
|
| 72 | + return $this->iterator->key(); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - public function valid() |
|
| 76 | - { |
|
| 77 | - return $this->iterator->valid(); |
|
| 78 | - } |
|
| 75 | + public function valid() |
|
| 76 | + { |
|
| 77 | + return $this->iterator->valid(); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - public function rewind() |
|
| 81 | - { |
|
| 82 | - $this->iterator->rewind(); |
|
| 83 | - } |
|
| 80 | + public function rewind() |
|
| 81 | + { |
|
| 82 | + $this->iterator->rewind(); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Casts the iterator to a PHP array. |
|
| 87 | - * |
|
| 88 | - * @return array |
|
| 89 | - */ |
|
| 90 | - public function toArray() |
|
| 91 | - { |
|
| 92 | - return iterator_to_array($this); |
|
| 93 | - } |
|
| 85 | + /** |
|
| 86 | + * Casts the iterator to a PHP array. |
|
| 87 | + * |
|
| 88 | + * @return array |
|
| 89 | + */ |
|
| 90 | + public function toArray() |
|
| 91 | + { |
|
| 92 | + return iterator_to_array($this); |
|
| 93 | + } |
|
| 94 | 94 | } |