@@ -138,9 +138,7 @@ discard block |
||
138 | 138 | * @Action |
139 | 139 | * @param string $daonamespace |
140 | 140 | * @param string $beannamespace |
141 | - * @param int $keepSupport |
|
142 | 141 | * @param int $storeInUtc |
143 | - * @param int $castDatesToDateTime |
|
144 | 142 | * @param string $selfedit |
145 | 143 | * @throws \Mouf\MoufException |
146 | 144 | */ |
@@ -168,6 +166,9 @@ discard block |
||
168 | 166 | |
169 | 167 | protected $errorMsg; |
170 | 168 | |
169 | + /** |
|
170 | + * @param string $msg |
|
171 | + */ |
|
171 | 172 | private function displayErrorMsg($msg) { |
172 | 173 | $this->errorMsg = $msg; |
173 | 174 | $this->content->addFile(dirname(__FILE__)."/../../../../views/installError.php", $this); |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | $this->beanNamespace = $this->moufManager->getVariable("tdbmDefaultBeanNamespace_tdbmService"); |
110 | 110 | |
111 | 111 | if ($this->daoNamespace == null && $this->beanNamespace == null) { |
112 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
112 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
113 | 113 | |
114 | - $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
114 | + $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
115 | 115 | if ($autoloadNamespaces) { |
116 | 116 | $this->autoloadDetected = true; |
117 | - $rootNamespace = $autoloadNamespaces[0]; |
|
117 | + $rootNamespace = $autoloadNamespaces[0]; |
|
118 | 118 | $this->daoNamespace = $rootNamespace."Dao"; |
119 | 119 | $this->beanNamespace = $rootNamespace."Dao\\Bean"; |
120 | 120 | } else { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param string $selfedit |
145 | 145 | * @throws \Mouf\MoufException |
146 | 146 | */ |
147 | - public function generate($daonamespace, $beannamespace, $storeInUtc = 0, $selfedit="false") { |
|
147 | + public function generate($daonamespace, $beannamespace, $storeInUtc = 0, $selfedit="false") { |
|
148 | 148 | $this->selfedit = $selfedit; |
149 | 149 | |
150 | 150 | if ($selfedit == "true") { |
@@ -63,6 +63,9 @@ discard block |
||
63 | 63 | |
64 | 64 | private $innerResultIterator; |
65 | 65 | |
66 | + /** |
|
67 | + * @param integer $offset |
|
68 | + */ |
|
66 | 69 | public function __construct(ResultIterator $parentResult, $magicSql, array $parameters, $limit, $offset, array $columnDescriptors, $objectStorage, $className, TDBMService $tdbmService, MagicQuery $magicQuery, $mode) |
67 | 70 | { |
68 | 71 | $this->parentResult = $parentResult; |
@@ -108,7 +111,7 @@ discard block |
||
108 | 111 | } |
109 | 112 | |
110 | 113 | /** |
111 | - * @return int |
|
114 | + * @return double |
|
112 | 115 | */ |
113 | 116 | public function getCurrentPage() |
114 | 117 | { |
@@ -35,6 +35,9 @@ discard block |
||
35 | 35 | class TDBMObject extends AbstractTDBMObject implements \ArrayAccess, \Iterator |
36 | 36 | { |
37 | 37 | |
38 | + /** |
|
39 | + * @param string $var |
|
40 | + */ |
|
38 | 41 | public function __get($var) |
39 | 42 | { |
40 | 43 | return $this->get($var); |
@@ -51,6 +54,10 @@ discard block |
||
51 | 54 | return $this->has($var); |
52 | 55 | } |
53 | 56 | |
57 | + /** |
|
58 | + * @param string $var |
|
59 | + * @param string|null $value |
|
60 | + */ |
|
54 | 61 | public function __set($var, $value) |
55 | 62 | { |
56 | 63 | $this->set($var, $value); |
@@ -35,117 +35,117 @@ |
||
35 | 35 | class TDBMObject extends AbstractTDBMObject implements \ArrayAccess, \Iterator |
36 | 36 | { |
37 | 37 | |
38 | - public function __get($var) |
|
39 | - { |
|
40 | - return $this->get($var); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Returns true if a column is set, false otherwise. |
|
45 | - * |
|
46 | - * @param string $var |
|
47 | - * @return boolean |
|
48 | - */ |
|
49 | - public function __isset($var) |
|
50 | - { |
|
51 | - return $this->has($var); |
|
52 | - } |
|
53 | - |
|
54 | - public function __set($var, $value) |
|
55 | - { |
|
56 | - $this->set($var, $value); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Implements array behaviour for our object. |
|
61 | - * |
|
62 | - * @param string $offset |
|
63 | - * @param string $value |
|
64 | - */ |
|
65 | - public function offsetSet($offset, $value) |
|
66 | - { |
|
67 | - $this->__set($offset, $value); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Implements array behaviour for our object. |
|
72 | - * |
|
73 | - * @param string $offset |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - public function offsetExists($offset) |
|
77 | - { |
|
78 | - $this->_dbLoadIfNotLoaded(); |
|
79 | - return isset($this->dbRow[$offset]); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Implements array behaviour for our object. |
|
84 | - * |
|
85 | - * @param string $offset |
|
86 | - */ |
|
87 | - public function offsetUnset($offset) |
|
88 | - { |
|
89 | - $this->__set($offset, null); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Implements array behaviour for our object. |
|
94 | - * |
|
95 | - * @param string $offset |
|
96 | - * @return mixed|null |
|
97 | - */ |
|
98 | - public function offsetGet($offset) |
|
99 | - { |
|
100 | - return $this->__get($offset); |
|
101 | - } |
|
102 | - |
|
103 | - private $_validIterator = false; |
|
104 | - |
|
105 | - /** |
|
106 | - * Implements iterator behaviour for our object (so we can each column). |
|
107 | - */ |
|
108 | - public function rewind() |
|
109 | - { |
|
110 | - $this->_dbLoadIfNotLoaded(); |
|
111 | - if (count($this->dbRow) > 0) { |
|
112 | - $this->_validIterator = true; |
|
113 | - } else { |
|
114 | - $this->_validIterator = false; |
|
115 | - } |
|
116 | - reset($this->dbRow); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Implements iterator behaviour for our object (so we can each column). |
|
121 | - */ |
|
122 | - public function next() |
|
123 | - { |
|
124 | - $val = next($this->dbRow); |
|
125 | - $this->_validIterator = !($val === false); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Implements iterator behaviour for our object (so we can each column). |
|
130 | - */ |
|
131 | - public function key() |
|
132 | - { |
|
133 | - return key($this->dbRow); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Implements iterator behaviour for our object (so we can each column). |
|
138 | - */ |
|
139 | - public function current() |
|
140 | - { |
|
141 | - return current($this->dbRow); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Implements iterator behaviour for our object (so we can each column). |
|
146 | - */ |
|
147 | - public function valid() |
|
148 | - { |
|
149 | - return $this->_validIterator; |
|
150 | - } |
|
38 | + public function __get($var) |
|
39 | + { |
|
40 | + return $this->get($var); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Returns true if a column is set, false otherwise. |
|
45 | + * |
|
46 | + * @param string $var |
|
47 | + * @return boolean |
|
48 | + */ |
|
49 | + public function __isset($var) |
|
50 | + { |
|
51 | + return $this->has($var); |
|
52 | + } |
|
53 | + |
|
54 | + public function __set($var, $value) |
|
55 | + { |
|
56 | + $this->set($var, $value); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Implements array behaviour for our object. |
|
61 | + * |
|
62 | + * @param string $offset |
|
63 | + * @param string $value |
|
64 | + */ |
|
65 | + public function offsetSet($offset, $value) |
|
66 | + { |
|
67 | + $this->__set($offset, $value); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Implements array behaviour for our object. |
|
72 | + * |
|
73 | + * @param string $offset |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + public function offsetExists($offset) |
|
77 | + { |
|
78 | + $this->_dbLoadIfNotLoaded(); |
|
79 | + return isset($this->dbRow[$offset]); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Implements array behaviour for our object. |
|
84 | + * |
|
85 | + * @param string $offset |
|
86 | + */ |
|
87 | + public function offsetUnset($offset) |
|
88 | + { |
|
89 | + $this->__set($offset, null); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Implements array behaviour for our object. |
|
94 | + * |
|
95 | + * @param string $offset |
|
96 | + * @return mixed|null |
|
97 | + */ |
|
98 | + public function offsetGet($offset) |
|
99 | + { |
|
100 | + return $this->__get($offset); |
|
101 | + } |
|
102 | + |
|
103 | + private $_validIterator = false; |
|
104 | + |
|
105 | + /** |
|
106 | + * Implements iterator behaviour for our object (so we can each column). |
|
107 | + */ |
|
108 | + public function rewind() |
|
109 | + { |
|
110 | + $this->_dbLoadIfNotLoaded(); |
|
111 | + if (count($this->dbRow) > 0) { |
|
112 | + $this->_validIterator = true; |
|
113 | + } else { |
|
114 | + $this->_validIterator = false; |
|
115 | + } |
|
116 | + reset($this->dbRow); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Implements iterator behaviour for our object (so we can each column). |
|
121 | + */ |
|
122 | + public function next() |
|
123 | + { |
|
124 | + $val = next($this->dbRow); |
|
125 | + $this->_validIterator = !($val === false); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Implements iterator behaviour for our object (so we can each column). |
|
130 | + */ |
|
131 | + public function key() |
|
132 | + { |
|
133 | + return key($this->dbRow); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Implements iterator behaviour for our object (so we can each column). |
|
138 | + */ |
|
139 | + public function current() |
|
140 | + { |
|
141 | + return current($this->dbRow); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Implements iterator behaviour for our object (so we can each column). |
|
146 | + */ |
|
147 | + public function valid() |
|
148 | + { |
|
149 | + return $this->_validIterator; |
|
150 | + } |
|
151 | 151 | } |
152 | 152 | \ No newline at end of file |
@@ -27,8 +27,7 @@ |
||
27 | 27 | /** |
28 | 28 | * Returns the foreignkey the column is part of, if any. null otherwise. |
29 | 29 | * |
30 | - * @param Column $column |
|
31 | - * @return ForeignKeyConstraint|null |
|
30 | + * @return boolean |
|
32 | 31 | */ |
33 | 32 | public function getForeignKey() { |
34 | 33 | return false; |
@@ -12,88 +12,88 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class ScalarBeanPropertyDescriptor extends AbstractBeanPropertyDescriptor |
14 | 14 | { |
15 | - /** |
|
16 | - * @var Column |
|
17 | - */ |
|
18 | - private $column; |
|
19 | - |
|
20 | - |
|
21 | - public function __construct(Table $table, Column $column) { |
|
22 | - parent::__construct($table); |
|
23 | - $this->table = $table; |
|
24 | - $this->column = $column; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Returns the foreignkey the column is part of, if any. null otherwise. |
|
29 | - * |
|
30 | - * @param Column $column |
|
31 | - * @return ForeignKeyConstraint|null |
|
32 | - */ |
|
33 | - public function getForeignKey() { |
|
34 | - return false; |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Returns the param annotation for this property (useful for constructor). |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getParamAnnotation() { |
|
43 | - $className = $this->getClassName(); |
|
44 | - $paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType()); |
|
45 | - |
|
46 | - $str = " * @param %s %s"; |
|
47 | - return sprintf($str, $paramType, $this->getVariableName()); |
|
48 | - } |
|
49 | - |
|
50 | - public function getUpperCamelCaseName() { |
|
51 | - return TDBMDaoGenerator::toCamelCase($this->column->getName()); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Returns the name of the class linked to this property or null if this is not a foreign key |
|
56 | - * @return null|string |
|
57 | - */ |
|
58 | - public function getClassName() { |
|
59 | - return null; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function isCompulsory() { |
|
67 | - return $this->column->getNotnull() && !$this->column->getAutoincrement(); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns true if the property is the primary key |
|
72 | - * @return bool |
|
73 | - */ |
|
74 | - public function isPrimaryKey() { |
|
75 | - return in_array($this->column->getName(), $this->table->getPrimaryKeyColumns()); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Returns the PHP code for getters and setters |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function getGetterSetterCode() { |
|
83 | - |
|
84 | - $type = $this->column->getType(); |
|
85 | - $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
86 | - |
|
87 | - $columnGetterName = $this->getGetterName(); |
|
88 | - $columnSetterName = $this->getSetterName(); |
|
89 | - |
|
90 | - if ($normalizedType == "\\DateTimeInterface") { |
|
91 | - $castTo = "\\DateTimeInterface "; |
|
92 | - } else { |
|
93 | - $castTo = ""; |
|
94 | - } |
|
95 | - |
|
96 | - $getterAndSetterCode = ' /** |
|
15 | + /** |
|
16 | + * @var Column |
|
17 | + */ |
|
18 | + private $column; |
|
19 | + |
|
20 | + |
|
21 | + public function __construct(Table $table, Column $column) { |
|
22 | + parent::__construct($table); |
|
23 | + $this->table = $table; |
|
24 | + $this->column = $column; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Returns the foreignkey the column is part of, if any. null otherwise. |
|
29 | + * |
|
30 | + * @param Column $column |
|
31 | + * @return ForeignKeyConstraint|null |
|
32 | + */ |
|
33 | + public function getForeignKey() { |
|
34 | + return false; |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Returns the param annotation for this property (useful for constructor). |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getParamAnnotation() { |
|
43 | + $className = $this->getClassName(); |
|
44 | + $paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType()); |
|
45 | + |
|
46 | + $str = " * @param %s %s"; |
|
47 | + return sprintf($str, $paramType, $this->getVariableName()); |
|
48 | + } |
|
49 | + |
|
50 | + public function getUpperCamelCaseName() { |
|
51 | + return TDBMDaoGenerator::toCamelCase($this->column->getName()); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Returns the name of the class linked to this property or null if this is not a foreign key |
|
56 | + * @return null|string |
|
57 | + */ |
|
58 | + public function getClassName() { |
|
59 | + return null; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function isCompulsory() { |
|
67 | + return $this->column->getNotnull() && !$this->column->getAutoincrement(); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns true if the property is the primary key |
|
72 | + * @return bool |
|
73 | + */ |
|
74 | + public function isPrimaryKey() { |
|
75 | + return in_array($this->column->getName(), $this->table->getPrimaryKeyColumns()); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Returns the PHP code for getters and setters |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function getGetterSetterCode() { |
|
83 | + |
|
84 | + $type = $this->column->getType(); |
|
85 | + $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
86 | + |
|
87 | + $columnGetterName = $this->getGetterName(); |
|
88 | + $columnSetterName = $this->getSetterName(); |
|
89 | + |
|
90 | + if ($normalizedType == "\\DateTimeInterface") { |
|
91 | + $castTo = "\\DateTimeInterface "; |
|
92 | + } else { |
|
93 | + $castTo = ""; |
|
94 | + } |
|
95 | + |
|
96 | + $getterAndSetterCode = ' /** |
|
97 | 97 | * The getter for the "%s" column. |
98 | 98 | * |
99 | 99 | * @return %s |
@@ -112,40 +112,40 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | '; |
115 | - return sprintf($getterAndSetterCode, |
|
116 | - // Getter |
|
117 | - $this->column->getName(), |
|
118 | - $normalizedType, |
|
119 | - $columnGetterName, |
|
120 | - var_export($this->column->getName(), true), |
|
121 | - var_export($this->table->getName(), true), |
|
122 | - // Setter |
|
123 | - $this->column->getName(), |
|
124 | - $normalizedType, |
|
125 | - $this->column->getName(), |
|
126 | - $columnSetterName, |
|
127 | - $castTo, |
|
128 | - $this->column->getName(), |
|
129 | - var_export($this->column->getName(), true), |
|
130 | - $this->column->getName(), |
|
131 | - var_export($this->table->getName(), true) |
|
132 | - ); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Returns the part of code useful when doing json serialization. |
|
137 | - * |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function getJsonSerializeCode() |
|
141 | - { |
|
142 | - $type = $this->column->getType(); |
|
143 | - $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
144 | - |
|
145 | - if ($normalizedType == "\\DateTimeInterface") { |
|
146 | - return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."()->format('c');\n"; |
|
147 | - } else { |
|
148 | - return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."();\n"; |
|
149 | - } |
|
150 | - } |
|
115 | + return sprintf($getterAndSetterCode, |
|
116 | + // Getter |
|
117 | + $this->column->getName(), |
|
118 | + $normalizedType, |
|
119 | + $columnGetterName, |
|
120 | + var_export($this->column->getName(), true), |
|
121 | + var_export($this->table->getName(), true), |
|
122 | + // Setter |
|
123 | + $this->column->getName(), |
|
124 | + $normalizedType, |
|
125 | + $this->column->getName(), |
|
126 | + $columnSetterName, |
|
127 | + $castTo, |
|
128 | + $this->column->getName(), |
|
129 | + var_export($this->column->getName(), true), |
|
130 | + $this->column->getName(), |
|
131 | + var_export($this->table->getName(), true) |
|
132 | + ); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Returns the part of code useful when doing json serialization. |
|
137 | + * |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function getJsonSerializeCode() |
|
141 | + { |
|
142 | + $type = $this->column->getType(); |
|
143 | + $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
|
144 | + |
|
145 | + if ($normalizedType == "\\DateTimeInterface") { |
|
146 | + return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."()->format('c');\n"; |
|
147 | + } else { |
|
148 | + return ' $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."();\n"; |
|
149 | + } |
|
150 | + } |
|
151 | 151 | } |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | } |
60 | 60 | |
61 | 61 | if ($this->daoNamespace == null && $this->beanNamespace == null) { |
62 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
62 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
63 | 63 | |
64 | 64 | $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
65 | - if ($autoloadNamespaces) { |
|
65 | + if ($autoloadNamespaces) { |
|
66 | 66 | $this->autoloadDetected = true; |
67 | 67 | $rootNamespace = $autoloadNamespaces[0]; |
68 | 68 | $this->daoNamespace = $rootNamespace."Dao"; |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | |
139 | 139 | $tdbmService = new InstanceProxy($name); |
140 | 140 | /* @var $tdbmService TDBMService */ |
141 | - $tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $storeInUtc); |
|
141 | + $tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $storeInUtc); |
|
142 | 142 | |
143 | 143 | |
144 | 144 | $moufManager->declareComponent($daofactoryinstancename, $daonamespace."\\".$daofactoryclassname, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS); |
@@ -25,10 +25,10 @@ |
||
25 | 25 | * @author David Negrier |
26 | 26 | */ |
27 | 27 | final class TDBMObjectStateEnum extends AbstractTDBMObject { |
28 | - const STATE_DETACHED = "detached"; |
|
29 | - const STATE_NEW = "new"; |
|
30 | - const STATE_NOT_LOADED = "not loaded"; |
|
31 | - const STATE_LOADED = "loaded"; |
|
32 | - const STATE_DIRTY = "dirty"; |
|
33 | - const STATE_DELETED = "deleted"; |
|
28 | + const STATE_DETACHED = "detached"; |
|
29 | + const STATE_NEW = "new"; |
|
30 | + const STATE_NOT_LOADED = "not loaded"; |
|
31 | + const STATE_LOADED = "loaded"; |
|
32 | + const STATE_DIRTY = "dirty"; |
|
33 | + const STATE_DELETED = "deleted"; |
|
34 | 34 | } |
@@ -70,6 +70,13 @@ discard block |
||
70 | 70 | |
71 | 71 | private $mode; |
72 | 72 | |
73 | + /** |
|
74 | + * @param string $magicSql |
|
75 | + * @param string $magicSqlCount |
|
76 | + * @param WeakrefObjectStorage $objectStorage |
|
77 | + * @param string|null $className |
|
78 | + * @param integer $mode |
|
79 | + */ |
|
73 | 80 | public function __construct($magicSql, $magicSqlCount, array $parameters, array $columnDescriptors, $objectStorage, $className, TDBMService $tdbmService, MagicQuery $magicQuery, $mode) |
74 | 81 | { |
75 | 82 | $this->magicSql = $magicSql; |
@@ -166,6 +173,7 @@ discard block |
||
166 | 173 | |
167 | 174 | /** |
168 | 175 | * @param int $offset |
176 | + * @param integer $limit |
|
169 | 177 | * @return PageIterator |
170 | 178 | */ |
171 | 179 | public function take($offset, $limit) |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | * This is used internally by TDBM to add an object to the list of objects that have been |
986 | 986 | * created/updated but not saved yet. |
987 | 987 | * |
988 | - * @param AbstractTDBMObject $myObject |
|
988 | + * @param DbRow $myObject |
|
989 | 989 | */ |
990 | 990 | public function _addToToSaveObjectList(DbRow $myObject) { |
991 | 991 | $this->toSaveObjects[] = $myObject; |
@@ -1621,7 +1621,7 @@ discard block |
||
1621 | 1621 | } |
1622 | 1622 | |
1623 | 1623 | /** |
1624 | - * @param $table |
|
1624 | + * @param string $table |
|
1625 | 1625 | * @param array $primaryKeys |
1626 | 1626 | * @param array $additionalTablesFetch |
1627 | 1627 | * @param bool $lazy Whether to perform lazy loading on this object or not. |
@@ -1778,7 +1778,7 @@ discard block |
||
1778 | 1778 | /** |
1779 | 1779 | * @param $pivotTableName |
1780 | 1780 | * @param AbstractTDBMObject $bean |
1781 | - * @return AbstractTDBMObject[] |
|
1781 | + * @return ResultIterator |
|
1782 | 1782 | */ |
1783 | 1783 | public function _getRelatedBeans($pivotTableName, AbstractTDBMObject $bean) { |
1784 | 1784 |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | case TDBMObjectStateEnum::STATE_DETACHED: |
361 | 361 | throw new TDBMInvalidOperationException('Cannot delete a detached object'); |
362 | 362 | case TDBMObjectStateEnum::STATE_NEW: |
363 | - $this->deleteManyToManyRelationships($object); |
|
363 | + $this->deleteManyToManyRelationships($object); |
|
364 | 364 | foreach ($object->_getDbRows() as $dbRow) { |
365 | 365 | $this->removeFromToSaveObjectList($dbRow); |
366 | 366 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | } |
372 | 372 | case TDBMObjectStateEnum::STATE_NOT_LOADED: |
373 | 373 | case TDBMObjectStateEnum::STATE_LOADED: |
374 | - $this->deleteManyToManyRelationships($object); |
|
374 | + $this->deleteManyToManyRelationships($object); |
|
375 | 375 | // Let's delete db rows, in reverse order. |
376 | 376 | foreach (array_reverse($object->_getDbRows()) as $dbRow) { |
377 | 377 | $tableName = $dbRow->_getDbTableName(); |
@@ -389,44 +389,44 @@ discard block |
||
389 | 389 | $object->_setStatus(TDBMObjectStateEnum::STATE_DELETED); |
390 | 390 | } |
391 | 391 | |
392 | - /** |
|
393 | - * Removes all many to many relationships for this object. |
|
394 | - * @param AbstractTDBMObject $object |
|
395 | - */ |
|
396 | - private function deleteManyToManyRelationships(AbstractTDBMObject $object) { |
|
397 | - foreach ($object->_getDbRows() as $tableName => $dbRow) { |
|
398 | - $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable($tableName); |
|
399 | - foreach ($pivotTables as $pivotTable) { |
|
400 | - $remoteBeans = $object->_getRelationships($pivotTable); |
|
401 | - foreach ($remoteBeans as $remoteBean) { |
|
402 | - $object->_removeRelationship($pivotTable, $remoteBean); |
|
403 | - } |
|
404 | - } |
|
405 | - } |
|
406 | - $this->persistManyToManyRelationships($object); |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * This function removes the given object from the database. It will also remove all objects relied to the one given |
|
412 | - * by parameter before all. |
|
413 | - * |
|
414 | - * Notice: if the object has a multiple primary key, the function will not work. |
|
415 | - * |
|
416 | - * @param AbstractTDBMObject $objToDelete |
|
417 | - */ |
|
418 | - public function deleteCascade(AbstractTDBMObject $objToDelete) { |
|
419 | - $this->deleteAllConstraintWithThisObject($objToDelete); |
|
420 | - $this->delete($objToDelete); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * This function is used only in TDBMService (private function) |
|
425 | - * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter |
|
426 | - * |
|
427 | - * @param AbstractTDBMObject $obj |
|
428 | - */ |
|
429 | - private function deleteAllConstraintWithThisObject(AbstractTDBMObject $obj) { |
|
392 | + /** |
|
393 | + * Removes all many to many relationships for this object. |
|
394 | + * @param AbstractTDBMObject $object |
|
395 | + */ |
|
396 | + private function deleteManyToManyRelationships(AbstractTDBMObject $object) { |
|
397 | + foreach ($object->_getDbRows() as $tableName => $dbRow) { |
|
398 | + $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable($tableName); |
|
399 | + foreach ($pivotTables as $pivotTable) { |
|
400 | + $remoteBeans = $object->_getRelationships($pivotTable); |
|
401 | + foreach ($remoteBeans as $remoteBean) { |
|
402 | + $object->_removeRelationship($pivotTable, $remoteBean); |
|
403 | + } |
|
404 | + } |
|
405 | + } |
|
406 | + $this->persistManyToManyRelationships($object); |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * This function removes the given object from the database. It will also remove all objects relied to the one given |
|
412 | + * by parameter before all. |
|
413 | + * |
|
414 | + * Notice: if the object has a multiple primary key, the function will not work. |
|
415 | + * |
|
416 | + * @param AbstractTDBMObject $objToDelete |
|
417 | + */ |
|
418 | + public function deleteCascade(AbstractTDBMObject $objToDelete) { |
|
419 | + $this->deleteAllConstraintWithThisObject($objToDelete); |
|
420 | + $this->delete($objToDelete); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * This function is used only in TDBMService (private function) |
|
425 | + * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter |
|
426 | + * |
|
427 | + * @param AbstractTDBMObject $obj |
|
428 | + */ |
|
429 | + private function deleteAllConstraintWithThisObject(AbstractTDBMObject $obj) { |
|
430 | 430 | $dbRows = $obj->_getDbRows(); |
431 | 431 | foreach ($dbRows as $dbRow) { |
432 | 432 | $tableName = $dbRow->_getDbTableName(); |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | } |
446 | 446 | } |
447 | 447 | } |
448 | - } |
|
448 | + } |
|
449 | 449 | |
450 | 450 | /** |
451 | 451 | * This function performs a save() of all the objects that have been modified. |
@@ -774,8 +774,8 @@ discard block |
||
774 | 774 | } |
775 | 775 | |
776 | 776 | /** |
777 | - * @param array<string, string> $tableToBeanMap |
|
778 | - */ |
|
777 | + * @param array<string, string> $tableToBeanMap |
|
778 | + */ |
|
779 | 779 | public function setTableToBeanMap(array $tableToBeanMap) { |
780 | 780 | $this->tableToBeanMap = $tableToBeanMap; |
781 | 781 | } |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | |
822 | 822 | // Let's save all references in NEW or DETACHED state (we need their primary key) |
823 | 823 | foreach ($references as $fkName => $reference) { |
824 | - $refStatus = $reference->_getStatus(); |
|
824 | + $refStatus = $reference->_getStatus(); |
|
825 | 825 | if ($refStatus === TDBMObjectStateEnum::STATE_NEW || $refStatus === TDBMObjectStateEnum::STATE_DETACHED) { |
826 | 826 | $this->save($reference); |
827 | 827 | } |
@@ -980,94 +980,94 @@ discard block |
||
980 | 980 | throw new TDBMInvalidOperationException("This object has been deleted. It cannot be saved."); |
981 | 981 | } |
982 | 982 | |
983 | - // Finally, let's save all the many to many relationships to this bean. |
|
984 | - $this->persistManyToManyRelationships($object); |
|
983 | + // Finally, let's save all the many to many relationships to this bean. |
|
984 | + $this->persistManyToManyRelationships($object); |
|
985 | 985 | } |
986 | 986 | |
987 | - private function persistManyToManyRelationships(AbstractTDBMObject $object) { |
|
988 | - foreach ($object->_getCachedRelationships() as $pivotTableName => $storage) { |
|
989 | - $tableDescriptor = $this->tdbmSchemaAnalyzer->getSchema()->getTable($pivotTableName); |
|
990 | - list($localFk, $remoteFk) = $this->getPivotTableForeignKeys($pivotTableName, $object); |
|
991 | - |
|
992 | - foreach ($storage as $remoteBean) { |
|
993 | - /* @var $remoteBean AbstractTDBMObject */ |
|
994 | - $statusArr = $storage[$remoteBean]; |
|
995 | - $status = $statusArr['status']; |
|
996 | - $reverse = $statusArr['reverse']; |
|
997 | - if ($reverse) { |
|
998 | - continue; |
|
999 | - } |
|
1000 | - |
|
1001 | - if ($status === 'new') { |
|
1002 | - $remoteBeanStatus = $remoteBean->_getStatus(); |
|
1003 | - if ($remoteBeanStatus === TDBMObjectStateEnum::STATE_NEW || $remoteBeanStatus === TDBMObjectStateEnum::STATE_DETACHED) { |
|
1004 | - // Let's save remote bean if needed. |
|
1005 | - $this->save($remoteBean); |
|
1006 | - } |
|
987 | + private function persistManyToManyRelationships(AbstractTDBMObject $object) { |
|
988 | + foreach ($object->_getCachedRelationships() as $pivotTableName => $storage) { |
|
989 | + $tableDescriptor = $this->tdbmSchemaAnalyzer->getSchema()->getTable($pivotTableName); |
|
990 | + list($localFk, $remoteFk) = $this->getPivotTableForeignKeys($pivotTableName, $object); |
|
991 | + |
|
992 | + foreach ($storage as $remoteBean) { |
|
993 | + /* @var $remoteBean AbstractTDBMObject */ |
|
994 | + $statusArr = $storage[$remoteBean]; |
|
995 | + $status = $statusArr['status']; |
|
996 | + $reverse = $statusArr['reverse']; |
|
997 | + if ($reverse) { |
|
998 | + continue; |
|
999 | + } |
|
1007 | 1000 | |
1008 | - $filters = $this->getPivotFilters($object, $remoteBean, $localFk, $remoteFk); |
|
1001 | + if ($status === 'new') { |
|
1002 | + $remoteBeanStatus = $remoteBean->_getStatus(); |
|
1003 | + if ($remoteBeanStatus === TDBMObjectStateEnum::STATE_NEW || $remoteBeanStatus === TDBMObjectStateEnum::STATE_DETACHED) { |
|
1004 | + // Let's save remote bean if needed. |
|
1005 | + $this->save($remoteBean); |
|
1006 | + } |
|
1009 | 1007 | |
1010 | - $types = []; |
|
1008 | + $filters = $this->getPivotFilters($object, $remoteBean, $localFk, $remoteFk); |
|
1011 | 1009 | |
1012 | - foreach ($filters as $columnName => $value) { |
|
1013 | - $columnDescriptor = $tableDescriptor->getColumn($columnName); |
|
1014 | - $types[] = $columnDescriptor->getType(); |
|
1015 | - } |
|
1010 | + $types = []; |
|
1016 | 1011 | |
1017 | - $this->connection->insert($pivotTableName, $filters, $types); |
|
1012 | + foreach ($filters as $columnName => $value) { |
|
1013 | + $columnDescriptor = $tableDescriptor->getColumn($columnName); |
|
1014 | + $types[] = $columnDescriptor->getType(); |
|
1015 | + } |
|
1018 | 1016 | |
1019 | - // Finally, let's mark relationships as saved. |
|
1020 | - $statusArr['status'] = 'loaded'; |
|
1021 | - $storage[$remoteBean] = $statusArr; |
|
1022 | - $remoteStorage = $remoteBean->_getCachedRelationships()[$pivotTableName]; |
|
1023 | - $remoteStatusArr = $remoteStorage[$object]; |
|
1024 | - $remoteStatusArr['status'] = 'loaded'; |
|
1025 | - $remoteStorage[$object] = $remoteStatusArr; |
|
1017 | + $this->connection->insert($pivotTableName, $filters, $types); |
|
1026 | 1018 | |
1027 | - } elseif ($status === 'delete') { |
|
1028 | - $filters = $this->getPivotFilters($object, $remoteBean, $localFk, $remoteFk); |
|
1019 | + // Finally, let's mark relationships as saved. |
|
1020 | + $statusArr['status'] = 'loaded'; |
|
1021 | + $storage[$remoteBean] = $statusArr; |
|
1022 | + $remoteStorage = $remoteBean->_getCachedRelationships()[$pivotTableName]; |
|
1023 | + $remoteStatusArr = $remoteStorage[$object]; |
|
1024 | + $remoteStatusArr['status'] = 'loaded'; |
|
1025 | + $remoteStorage[$object] = $remoteStatusArr; |
|
1029 | 1026 | |
1030 | - $types = []; |
|
1027 | + } elseif ($status === 'delete') { |
|
1028 | + $filters = $this->getPivotFilters($object, $remoteBean, $localFk, $remoteFk); |
|
1031 | 1029 | |
1032 | - foreach ($filters as $columnName => $value) { |
|
1033 | - $columnDescriptor = $tableDescriptor->getColumn($columnName); |
|
1034 | - $types[] = $columnDescriptor->getType(); |
|
1035 | - } |
|
1030 | + $types = []; |
|
1036 | 1031 | |
1037 | - $this->connection->delete($pivotTableName, $filters, $types); |
|
1038 | - |
|
1039 | - // Finally, let's remove relationships completely from bean. |
|
1040 | - $storage->detach($remoteBean); |
|
1041 | - $remoteBean->_getCachedRelationships()[$pivotTableName]->detach($object); |
|
1042 | - } |
|
1043 | - } |
|
1044 | - } |
|
1045 | - } |
|
1046 | - |
|
1047 | - private function getPivotFilters(AbstractTDBMObject $localBean, AbstractTDBMObject $remoteBean, ForeignKeyConstraint $localFk, ForeignKeyConstraint $remoteFk) { |
|
1048 | - $localBeanPk = $this->getPrimaryKeyValues($localBean); |
|
1049 | - $remoteBeanPk = $this->getPrimaryKeyValues($remoteBean); |
|
1050 | - $localColumns = $localFk->getLocalColumns(); |
|
1051 | - $remoteColumns = $remoteFk->getLocalColumns(); |
|
1052 | - |
|
1053 | - $localFilters = array_combine($localColumns, $localBeanPk); |
|
1054 | - $remoteFilters = array_combine($remoteColumns, $remoteBeanPk); |
|
1055 | - |
|
1056 | - return array_merge($localFilters, $remoteFilters); |
|
1057 | - } |
|
1058 | - |
|
1059 | - /** |
|
1060 | - * Returns the "values" of the primary key. |
|
1061 | - * This returns the primary key from the $primaryKey attribute, not the one stored in the columns. |
|
1062 | - * |
|
1063 | - * @param AbstractTDBMObject $bean |
|
1064 | - * @return array numerically indexed array of values. |
|
1065 | - */ |
|
1066 | - private function getPrimaryKeyValues(AbstractTDBMObject $bean) { |
|
1067 | - $dbRows = $bean->_getDbRows(); |
|
1068 | - $dbRow = reset($dbRows); |
|
1069 | - return array_values($dbRow->_getPrimaryKeys()); |
|
1070 | - } |
|
1032 | + foreach ($filters as $columnName => $value) { |
|
1033 | + $columnDescriptor = $tableDescriptor->getColumn($columnName); |
|
1034 | + $types[] = $columnDescriptor->getType(); |
|
1035 | + } |
|
1036 | + |
|
1037 | + $this->connection->delete($pivotTableName, $filters, $types); |
|
1038 | + |
|
1039 | + // Finally, let's remove relationships completely from bean. |
|
1040 | + $storage->detach($remoteBean); |
|
1041 | + $remoteBean->_getCachedRelationships()[$pivotTableName]->detach($object); |
|
1042 | + } |
|
1043 | + } |
|
1044 | + } |
|
1045 | + } |
|
1046 | + |
|
1047 | + private function getPivotFilters(AbstractTDBMObject $localBean, AbstractTDBMObject $remoteBean, ForeignKeyConstraint $localFk, ForeignKeyConstraint $remoteFk) { |
|
1048 | + $localBeanPk = $this->getPrimaryKeyValues($localBean); |
|
1049 | + $remoteBeanPk = $this->getPrimaryKeyValues($remoteBean); |
|
1050 | + $localColumns = $localFk->getLocalColumns(); |
|
1051 | + $remoteColumns = $remoteFk->getLocalColumns(); |
|
1052 | + |
|
1053 | + $localFilters = array_combine($localColumns, $localBeanPk); |
|
1054 | + $remoteFilters = array_combine($remoteColumns, $remoteBeanPk); |
|
1055 | + |
|
1056 | + return array_merge($localFilters, $remoteFilters); |
|
1057 | + } |
|
1058 | + |
|
1059 | + /** |
|
1060 | + * Returns the "values" of the primary key. |
|
1061 | + * This returns the primary key from the $primaryKey attribute, not the one stored in the columns. |
|
1062 | + * |
|
1063 | + * @param AbstractTDBMObject $bean |
|
1064 | + * @return array numerically indexed array of values. |
|
1065 | + */ |
|
1066 | + private function getPrimaryKeyValues(AbstractTDBMObject $bean) { |
|
1067 | + $dbRows = $bean->_getDbRows(); |
|
1068 | + $dbRow = reset($dbRows); |
|
1069 | + return array_values($dbRow->_getPrimaryKeys()); |
|
1070 | + } |
|
1071 | 1071 | |
1072 | 1072 | /** |
1073 | 1073 | * Returns a unique hash used to store the object based on its primary key. |
@@ -1549,41 +1549,41 @@ discard block |
||
1549 | 1549 | */ |
1550 | 1550 | public function _getRelatedBeans($pivotTableName, AbstractTDBMObject $bean) { |
1551 | 1551 | |
1552 | - list($localFk, $remoteFk) = $this->getPivotTableForeignKeys($pivotTableName, $bean); |
|
1553 | - /* @var $localFk ForeignKeyConstraint */ |
|
1554 | - /* @var $remoteFk ForeignKeyConstraint */ |
|
1555 | - $remoteTable = $remoteFk->getForeignTableName(); |
|
1552 | + list($localFk, $remoteFk) = $this->getPivotTableForeignKeys($pivotTableName, $bean); |
|
1553 | + /* @var $localFk ForeignKeyConstraint */ |
|
1554 | + /* @var $remoteFk ForeignKeyConstraint */ |
|
1555 | + $remoteTable = $remoteFk->getForeignTableName(); |
|
1556 | 1556 | |
1557 | 1557 | |
1558 | - $primaryKeys = $this->getPrimaryKeyValues($bean); |
|
1559 | - $columnNames = array_map(function($name) use ($pivotTableName) { return $pivotTableName.'.'.$name; }, $localFk->getLocalColumns()); |
|
1558 | + $primaryKeys = $this->getPrimaryKeyValues($bean); |
|
1559 | + $columnNames = array_map(function($name) use ($pivotTableName) { return $pivotTableName.'.'.$name; }, $localFk->getLocalColumns()); |
|
1560 | 1560 | |
1561 | - $filter = array_combine($columnNames, $primaryKeys); |
|
1561 | + $filter = array_combine($columnNames, $primaryKeys); |
|
1562 | 1562 | |
1563 | - return $this->findObjects($remoteTable, $filter); |
|
1563 | + return $this->findObjects($remoteTable, $filter); |
|
1564 | 1564 | } |
1565 | 1565 | |
1566 | - /** |
|
1567 | - * @param $pivotTableName |
|
1568 | - * @param AbstractTDBMObject $bean The LOCAL bean |
|
1569 | - * @return ForeignKeyConstraint[] First item: the LOCAL bean, second item: the REMOTE bean. |
|
1570 | - * @throws TDBMException |
|
1571 | - */ |
|
1572 | - private function getPivotTableForeignKeys($pivotTableName, AbstractTDBMObject $bean) { |
|
1573 | - $fks = array_values($this->tdbmSchemaAnalyzer->getSchema()->getTable($pivotTableName)->getForeignKeys()); |
|
1574 | - $table1 = $fks[0]->getForeignTableName(); |
|
1575 | - $table2 = $fks[1]->getForeignTableName(); |
|
1576 | - |
|
1577 | - $beanTables = array_map(function(DbRow $dbRow) { return $dbRow->_getDbTableName(); }, $bean->_getDbRows()); |
|
1578 | - |
|
1579 | - if (in_array($table1, $beanTables)) { |
|
1580 | - return [$fks[0], $fks[1]]; |
|
1581 | - } elseif (in_array($table2, $beanTables)) { |
|
1582 | - return [$fks[1], $fks[0]]; |
|
1583 | - } else { |
|
1584 | - throw new TDBMException("Unexpected bean type in getPivotTableForeignKeys. Awaiting beans from table {$table1} and {$table2} for pivot table {$pivotTableName}"); |
|
1585 | - } |
|
1586 | - } |
|
1566 | + /** |
|
1567 | + * @param $pivotTableName |
|
1568 | + * @param AbstractTDBMObject $bean The LOCAL bean |
|
1569 | + * @return ForeignKeyConstraint[] First item: the LOCAL bean, second item: the REMOTE bean. |
|
1570 | + * @throws TDBMException |
|
1571 | + */ |
|
1572 | + private function getPivotTableForeignKeys($pivotTableName, AbstractTDBMObject $bean) { |
|
1573 | + $fks = array_values($this->tdbmSchemaAnalyzer->getSchema()->getTable($pivotTableName)->getForeignKeys()); |
|
1574 | + $table1 = $fks[0]->getForeignTableName(); |
|
1575 | + $table2 = $fks[1]->getForeignTableName(); |
|
1576 | + |
|
1577 | + $beanTables = array_map(function(DbRow $dbRow) { return $dbRow->_getDbTableName(); }, $bean->_getDbRows()); |
|
1578 | + |
|
1579 | + if (in_array($table1, $beanTables)) { |
|
1580 | + return [$fks[0], $fks[1]]; |
|
1581 | + } elseif (in_array($table2, $beanTables)) { |
|
1582 | + return [$fks[1], $fks[0]]; |
|
1583 | + } else { |
|
1584 | + throw new TDBMException("Unexpected bean type in getPivotTableForeignKeys. Awaiting beans from table {$table1} and {$table2} for pivot table {$pivotTableName}"); |
|
1585 | + } |
|
1586 | + } |
|
1587 | 1587 | |
1588 | 1588 | /** |
1589 | 1589 | * Returns a list of pivot tables linked to $bean. |
@@ -9,85 +9,85 @@ |
||
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 | - * @throws TDBMException |
|
26 | - */ |
|
27 | - public function __construct($iterator, callable $callable) { |
|
28 | - if (is_array($iterator)) { |
|
29 | - $this->iterator = new \ArrayIterator($iterator); |
|
30 | - } |
|
31 | - elseif (!($iterator instanceof Iterator)) |
|
32 | - { |
|
33 | - throw new TDBMException("\$iterator parameter must be an instance of Iterator"); |
|
34 | - } |
|
35 | - else |
|
36 | - { |
|
37 | - $this->iterator = $iterator; |
|
38 | - } |
|
22 | + /** |
|
23 | + * @param $iterator Iterator|array |
|
24 | + * @param $callable callable This can have two parameters |
|
25 | + * @throws TDBMException |
|
26 | + */ |
|
27 | + public function __construct($iterator, callable $callable) { |
|
28 | + if (is_array($iterator)) { |
|
29 | + $this->iterator = new \ArrayIterator($iterator); |
|
30 | + } |
|
31 | + elseif (!($iterator instanceof Iterator)) |
|
32 | + { |
|
33 | + throw new TDBMException("\$iterator parameter must be an instance of Iterator"); |
|
34 | + } |
|
35 | + else |
|
36 | + { |
|
37 | + $this->iterator = $iterator; |
|
38 | + } |
|
39 | 39 | |
40 | - if ($callable instanceof \Closure) { |
|
41 | - // make sure there's one argument |
|
42 | - $reflection = new \ReflectionObject($callable); |
|
43 | - if ($reflection->hasMethod('__invoke')) { |
|
44 | - $method = $reflection->getMethod('__invoke'); |
|
45 | - if ($method->getNumberOfParameters() !== 1) { |
|
46 | - throw new TDBMException("\$callable must accept one and only one parameter."); |
|
47 | - } |
|
48 | - } |
|
49 | - } |
|
40 | + if ($callable instanceof \Closure) { |
|
41 | + // make sure there's one argument |
|
42 | + $reflection = new \ReflectionObject($callable); |
|
43 | + if ($reflection->hasMethod('__invoke')) { |
|
44 | + $method = $reflection->getMethod('__invoke'); |
|
45 | + if ($method->getNumberOfParameters() !== 1) { |
|
46 | + throw new TDBMException("\$callable must accept one and only one parameter."); |
|
47 | + } |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - $this->callable = $callable; |
|
52 | - } |
|
51 | + $this->callable = $callable; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Alters the current item with $this->callable and returns a new item. |
|
56 | - * Be careful with your types as we can't do static type checking here! |
|
57 | - * @return mixed |
|
58 | - */ |
|
59 | - public function current() |
|
60 | - { |
|
61 | - $callable = $this->callable; |
|
62 | - return $callable($this->iterator->current()); |
|
63 | - } |
|
54 | + /** |
|
55 | + * Alters the current item with $this->callable and returns a new item. |
|
56 | + * Be careful with your types as we can't do static type checking here! |
|
57 | + * @return mixed |
|
58 | + */ |
|
59 | + public function current() |
|
60 | + { |
|
61 | + $callable = $this->callable; |
|
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 | - return iterator_to_array($this); |
|
92 | - } |
|
85 | + /** |
|
86 | + * Casts the iterator to a PHP array. |
|
87 | + * |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + public function toArray() { |
|
91 | + return iterator_to_array($this); |
|
92 | + } |
|
93 | 93 | } |