@@ -57,24 +57,24 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function add($parent, $node, $object = '') |
59 | 59 | { |
60 | - if(isset($this->_entries[$parent]) && ($this->_entries[$parent] !== null) |
|
60 | + if (isset($this->_entries[$parent]) && ($this->_entries[$parent] !== null) |
|
61 | 61 | && isset($this->_entries[$node]) && ($this->_entries[$node] !== null)) |
62 | 62 | { |
63 | 63 | $this->_entries[$node] = $object; |
64 | 64 | return; |
65 | 65 | } |
66 | 66 | $this->_entries[$node] = $object; |
67 | - if(empty($parent)) |
|
67 | + if (empty($parent)) |
|
68 | 68 | { |
69 | - if(isset($this->_entries[$node])) |
|
69 | + if (isset($this->_entries[$node])) |
|
70 | 70 | return; |
71 | 71 | $this->_tree[$node] = []; |
72 | 72 | } |
73 | 73 | $found = $this->addNode($this->_tree, $parent, $node); |
74 | - if(!$found && !empty($parent)) |
|
74 | + if (!$found && !empty($parent)) |
|
75 | 75 | { |
76 | 76 | $this->_tree[$parent] = []; |
77 | - if(!isset($this->_entries[$parent]) || $object !== '') |
|
77 | + if (!isset($this->_entries[$parent]) || $object !== '') |
|
78 | 78 | $this->_entries[$parent] = $object; |
79 | 79 | $this->addNode($this->_tree, $parent, $node); |
80 | 80 | } |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | { |
92 | 92 | $found = false; |
93 | 93 | reset($childs); |
94 | - for($i = 0, $k = count($childs); $i < $k; $i++) |
|
94 | + for ($i = 0, $k = count($childs); $i < $k; $i++) |
|
95 | 95 | { |
96 | 96 | $key = key($childs); |
97 | 97 | next($childs); |
98 | - if($key == $parent) |
|
98 | + if ($key == $parent) |
|
99 | 99 | { |
100 | 100 | $found = true; |
101 | 101 | $childs[$key][$node] = []; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function collect() |
115 | 115 | { |
116 | - while(count($this->_tree) > 0) |
|
116 | + while (count($this->_tree) > 0) |
|
117 | 117 | $this->collectChildren(null, $this->_tree); |
118 | 118 | return $this->getCollection(); |
119 | 119 | } |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | protected function hasChildren(&$nodes) |
126 | 126 | { |
127 | 127 | $hasChildren = false; |
128 | - foreach($nodes as $node) |
|
129 | - if(count($node) != 0) |
|
128 | + foreach ($nodes as $node) |
|
129 | + if (count($node) != 0) |
|
130 | 130 | return true; |
131 | 131 | return $hasChildren; |
132 | 132 | } |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | { |
141 | 141 | $noChildren = !$this->hasChildren($nodes); |
142 | 142 | $childs = []; |
143 | - for(reset($nodes); $key = key($nodes);) |
|
143 | + for (reset($nodes); $key = key($nodes);) |
|
144 | 144 | { |
145 | 145 | next($nodes); |
146 | - if($noChildren) |
|
146 | + if ($noChildren) |
|
147 | 147 | { |
148 | 148 | $childs[] = $key; |
149 | 149 | unset($nodes[$key]); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | else |
152 | 152 | $this->collectChildren($key, $nodes[$key]); |
153 | 153 | } |
154 | - if(count($childs) > 0) |
|
154 | + if (count($childs) > 0) |
|
155 | 155 | $this->onChildNodesVisited($parent, $childs); |
156 | 156 | } |
157 | 157 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | protected function onChildNodesVisited($parent, $nodes) |
164 | 164 | { |
165 | - if(empty($parent) || empty($this->_entries[$parent])) |
|
165 | + if (empty($parent) || empty($this->_entries[$parent])) |
|
166 | 166 | return; |
167 | 167 | |
168 | 168 | $parentObject = $this->_entries[$parent]['object']; |
@@ -170,21 +170,21 @@ discard block |
||
170 | 170 | |
171 | 171 | $list = TPropertyAccess::get($parentObject, $property); |
172 | 172 | |
173 | - foreach($nodes as $node) |
|
173 | + foreach ($nodes as $node) |
|
174 | 174 | { |
175 | - if($list instanceof TList) |
|
175 | + if ($list instanceof TList) |
|
176 | 176 | $parentObject->{$property}[] = $this->_entries[$node]['object']; |
177 | - elseif(is_array($list)) |
|
177 | + elseif (is_array($list)) |
|
178 | 178 | $list[] = $this->_entries[$node]['object']; |
179 | 179 | else |
180 | 180 | throw new TSqlMapExecutionException( |
181 | 181 | 'sqlmap_property_must_be_list'); |
182 | 182 | } |
183 | 183 | |
184 | - if(is_array($list)) |
|
184 | + if (is_array($list)) |
|
185 | 185 | TPropertyAccess::set($parentObject, $property, $list); |
186 | 186 | |
187 | - if($this->_entries[$parent]['property'] === null) |
|
187 | + if ($this->_entries[$parent]['property'] === null) |
|
188 | 188 | $this->_list[] = $parentObject; |
189 | 189 | } |
190 | 190 |
@@ -66,16 +66,18 @@ discard block |
||
66 | 66 | $this->_entries[$node] = $object; |
67 | 67 | if(empty($parent)) |
68 | 68 | { |
69 | - if(isset($this->_entries[$node])) |
|
70 | - return; |
|
69 | + if(isset($this->_entries[$node])) { |
|
70 | + return; |
|
71 | + } |
|
71 | 72 | $this->_tree[$node] = []; |
72 | 73 | } |
73 | 74 | $found = $this->addNode($this->_tree, $parent, $node); |
74 | 75 | if(!$found && !empty($parent)) |
75 | 76 | { |
76 | 77 | $this->_tree[$parent] = []; |
77 | - if(!isset($this->_entries[$parent]) || $object !== '') |
|
78 | - $this->_entries[$parent] = $object; |
|
78 | + if(!isset($this->_entries[$parent]) || $object !== '') { |
|
79 | + $this->_entries[$parent] = $object; |
|
80 | + } |
|
79 | 81 | $this->addNode($this->_tree, $parent, $node); |
80 | 82 | } |
81 | 83 | } |
@@ -99,8 +101,7 @@ discard block |
||
99 | 101 | { |
100 | 102 | $found = true; |
101 | 103 | $childs[$key][$node] = []; |
102 | - } |
|
103 | - else |
|
104 | + } else |
|
104 | 105 | { |
105 | 106 | $found = $found || $this->addNode($childs[$key], $parent, $node); |
106 | 107 | } |
@@ -113,8 +114,9 @@ discard block |
||
113 | 114 | */ |
114 | 115 | public function collect() |
115 | 116 | { |
116 | - while(count($this->_tree) > 0) |
|
117 | - $this->collectChildren(null, $this->_tree); |
|
117 | + while(count($this->_tree) > 0) { |
|
118 | + $this->collectChildren(null, $this->_tree); |
|
119 | + } |
|
118 | 120 | return $this->getCollection(); |
119 | 121 | } |
120 | 122 | |
@@ -125,9 +127,10 @@ discard block |
||
125 | 127 | protected function hasChildren(&$nodes) |
126 | 128 | { |
127 | 129 | $hasChildren = false; |
128 | - foreach($nodes as $node) |
|
129 | - if(count($node) != 0) |
|
130 | + foreach($nodes as $node) { |
|
131 | + if(count($node) != 0) |
|
130 | 132 | return true; |
133 | + } |
|
131 | 134 | return $hasChildren; |
132 | 135 | } |
133 | 136 | |
@@ -147,12 +150,13 @@ discard block |
||
147 | 150 | { |
148 | 151 | $childs[] = $key; |
149 | 152 | unset($nodes[$key]); |
153 | + } else { |
|
154 | + $this->collectChildren($key, $nodes[$key]); |
|
150 | 155 | } |
151 | - else |
|
152 | - $this->collectChildren($key, $nodes[$key]); |
|
153 | 156 | } |
154 | - if(count($childs) > 0) |
|
155 | - $this->onChildNodesVisited($parent, $childs); |
|
157 | + if(count($childs) > 0) { |
|
158 | + $this->onChildNodesVisited($parent, $childs); |
|
159 | + } |
|
156 | 160 | } |
157 | 161 | |
158 | 162 | /** |
@@ -162,8 +166,9 @@ discard block |
||
162 | 166 | */ |
163 | 167 | protected function onChildNodesVisited($parent, $nodes) |
164 | 168 | { |
165 | - if(empty($parent) || empty($this->_entries[$parent])) |
|
166 | - return; |
|
169 | + if(empty($parent) || empty($this->_entries[$parent])) { |
|
170 | + return; |
|
171 | + } |
|
167 | 172 | |
168 | 173 | $parentObject = $this->_entries[$parent]['object']; |
169 | 174 | $property = $this->_entries[$nodes[0]]['property']; |
@@ -172,20 +177,23 @@ discard block |
||
172 | 177 | |
173 | 178 | foreach($nodes as $node) |
174 | 179 | { |
175 | - if($list instanceof TList) |
|
176 | - $parentObject->{$property}[] = $this->_entries[$node]['object']; |
|
177 | - elseif(is_array($list)) |
|
178 | - $list[] = $this->_entries[$node]['object']; |
|
179 | - else |
|
180 | - throw new TSqlMapExecutionException( |
|
180 | + if($list instanceof TList) { |
|
181 | + $parentObject->{$property}[] = $this->_entries[$node]['object']; |
|
182 | + } elseif(is_array($list)) { |
|
183 | + $list[] = $this->_entries[$node]['object']; |
|
184 | + } else { |
|
185 | + throw new TSqlMapExecutionException( |
|
181 | 186 | 'sqlmap_property_must_be_list'); |
187 | + } |
|
182 | 188 | } |
183 | 189 | |
184 | - if(is_array($list)) |
|
185 | - TPropertyAccess::set($parentObject, $property, $list); |
|
190 | + if(is_array($list)) { |
|
191 | + TPropertyAccess::set($parentObject, $property, $list); |
|
192 | + } |
|
186 | 193 | |
187 | - if($this->_entries[$parent]['property'] === null) |
|
188 | - $this->_list[] = $parentObject; |
|
194 | + if($this->_entries[$parent]['property'] === null) { |
|
195 | + $this->_list[] = $parentObject; |
|
196 | + } |
|
189 | 197 | } |
190 | 198 | |
191 | 199 | /** |
@@ -199,9 +207,15 @@ discard block |
||
199 | 207 | public function __sleep() |
200 | 208 | { |
201 | 209 | $exprops = []; $cn = __CLASS__; |
202 | - if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree"; |
|
203 | - if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries"; |
|
204 | - if (!count($this->_list)) $exprops[] = "\0$cn\0_list"; |
|
210 | + if (!count($this->_tree)) { |
|
211 | + $exprops[] = "\0$cn\0_tree"; |
|
212 | + } |
|
213 | + if (!count($this->_entries)) { |
|
214 | + $exprops[] = "\0$cn\0_entries"; |
|
215 | + } |
|
216 | + if (!count($this->_list)) { |
|
217 | + $exprops[] = "\0$cn\0_list"; |
|
218 | + } |
|
205 | 219 | return array_diff(parent::__sleep(), $exprops); |
206 | 220 | } |
207 | 221 | } |
208 | 222 | \ No newline at end of file |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty = null, $skip = -1, $max = -1, $delegate = null) |
48 | 48 | { |
49 | 49 | $sql = $this->createCommand($connection, $parameter, $skip, $max); |
50 | - $key = $this->getCacheKey([clone($sql), $keyProperty, $valueProperty,$skip, $max]); |
|
50 | + $key = $this->getCacheKey([clone($sql), $keyProperty, $valueProperty, $skip, $max]); |
|
51 | 51 | $map = $this->getStatement()->getCache()->get($key); |
52 | - if($map === null) |
|
52 | + if ($map === null) |
|
53 | 53 | { |
54 | 54 | $map = $this->_mappedStatement->runQueryForMap( |
55 | 55 | $connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $sql = $this->createCommand($connection, $parameter, $skip, $max); |
74 | 74 | $key = $this->getCacheKey([clone($sql), $parameter, $skip, $max]); |
75 | 75 | $list = $this->getStatement()->getCache()->get($key); |
76 | - if($list === null) |
|
76 | + if ($list === null) |
|
77 | 77 | { |
78 | 78 | $list = $this->_mappedStatement->runQueryForList( |
79 | 79 | $connection, $parameter, $sql, $result, $delegate); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $sql = $this->createCommand($connection, $parameter); |
88 | 88 | $key = $this->getCacheKey([clone($sql), $parameter]); |
89 | 89 | $object = $this->getStatement()->getCache()->get($key); |
90 | - if($object === null) |
|
90 | + if ($object === null) |
|
91 | 91 | { |
92 | 92 | $object = $this->_mappedStatement->runQueryForObject($connection, $sql, $result); |
93 | 93 | $this->getStatement()->getCache()->set($key, $object); |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | private $_parameterNames; |
28 | 28 | private $_parameterValues; |
29 | 29 | |
30 | - public function getPreparedSql(){ return $this->_sqlString; } |
|
31 | - public function setPreparedSql($value){ $this->_sqlString = $value; } |
|
30 | + public function getPreparedSql() { return $this->_sqlString; } |
|
31 | + public function setPreparedSql($value) { $this->_sqlString = $value; } |
|
32 | 32 | |
33 | 33 | public function getParameterNames($needed = true) |
34 | 34 | { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | return $this->_parameterNames; |
38 | 38 | } |
39 | 39 | |
40 | - public function setParameterNames($value){ $this->_parameterNames = $value; } |
|
40 | + public function setParameterNames($value) { $this->_parameterNames = $value; } |
|
41 | 41 | |
42 | 42 | public function getParameterValues($needed = true) |
43 | 43 | { |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | return $this->_parameterValues; |
47 | 47 | } |
48 | 48 | |
49 | - public function setParameterValues($value){ $this->_parameterValues = $value; } |
|
49 | + public function setParameterValues($value) { $this->_parameterValues = $value; } |
|
50 | 50 | |
51 | 51 | public function __sleep() |
52 | 52 | { |
@@ -32,8 +32,9 @@ discard block |
||
32 | 32 | |
33 | 33 | public function getParameterNames($needed = true) |
34 | 34 | { |
35 | - if (!$this->_parameterNames and $needed) |
|
36 | - $this->_parameterNames = new TList; |
|
35 | + if (!$this->_parameterNames and $needed) { |
|
36 | + $this->_parameterNames = new TList; |
|
37 | + } |
|
37 | 38 | return $this->_parameterNames; |
38 | 39 | } |
39 | 40 | |
@@ -41,8 +42,9 @@ discard block |
||
41 | 42 | |
42 | 43 | public function getParameterValues($needed = true) |
43 | 44 | { |
44 | - if (!$this->_parameterValues and $needed) |
|
45 | - $this->_parameterValues = new TMap; |
|
45 | + if (!$this->_parameterValues and $needed) { |
|
46 | + $this->_parameterValues = new TMap; |
|
47 | + } |
|
46 | 48 | return $this->_parameterValues; |
47 | 49 | } |
48 | 50 | |
@@ -51,8 +53,12 @@ discard block |
||
51 | 53 | public function __sleep() |
52 | 54 | { |
53 | 55 | $exprops = []; $cn = __CLASS__; |
54 | - if (!$this->_parameterNames or !$this->_parameterNames->getCount()) $exprops[] = "\0$cn\0_parameterNames"; |
|
55 | - if (!$this->_parameterValues or !$this->_parameterValues->getCount()) $exprops[] = "\0$cn\0_parameterValues"; |
|
56 | + if (!$this->_parameterNames or !$this->_parameterNames->getCount()) { |
|
57 | + $exprops[] = "\0$cn\0_parameterNames"; |
|
58 | + } |
|
59 | + if (!$this->_parameterValues or !$this->_parameterValues->getCount()) { |
|
60 | + $exprops[] = "\0$cn\0_parameterValues"; |
|
61 | + } |
|
56 | 62 | return array_diff(parent::__sleep(), $exprops); |
57 | 63 | } |
58 | 64 | } |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | $connection->setActive(true); |
35 | 35 | $sql = $prepared->getPreparedSql(); |
36 | 36 | |
37 | - if($sqlText instanceof TSimpleDynamicSql) |
|
37 | + if ($sqlText instanceof TSimpleDynamicSql) |
|
38 | 38 | $sql = $sqlText->replaceDynamicParameter($sql, $parameterObject); |
39 | 39 | |
40 | - if($max !== null || $skip !== null) |
|
40 | + if ($max !== null || $skip !== null) |
|
41 | 41 | { |
42 | 42 | $builder = TDbMetaData::getInstance($connection)->createCommandBuilder(); |
43 | 43 | $sql = $builder->applyLimitOffset($sql, $max, $skip); |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | //$parameters = $prepared->getParameterValues(); |
55 | 55 | $registry = $manager->getTypeHandlers(); |
56 | 56 | if ($properties) |
57 | - for($i = 0, $k = $properties->getCount(); $i < $k; $i++) |
|
57 | + for ($i = 0, $k = $properties->getCount(); $i < $k; $i++) |
|
58 | 58 | { |
59 | 59 | $property = $statement->parameterMap()->getProperty($i); |
60 | 60 | $value = $statement->parameterMap()->getPropertyValue($registry, $property, $parameterObject); |
61 | 61 | $dbType = $property->getDbType(); |
62 | - if($dbType == '') //relies on PHP lax comparison |
|
62 | + if ($dbType == '') //relies on PHP lax comparison |
|
63 | 63 | $command->bindValue($i + 1, $value, TDbCommandBuilder::getPdoType($value)); |
64 | - elseif(strpos($dbType, 'PDO::') === 0) |
|
64 | + elseif (strpos($dbType, 'PDO::') === 0) |
|
65 | 65 | $command->bindValue($i + 1, $value, constant($property->getDbType())); //assumes PDO types, e.g. PDO::PARAM_INT |
66 | 66 | else |
67 | 67 | $command->bindValue($i + 1, $value); |
@@ -34,8 +34,9 @@ discard block |
||
34 | 34 | $connection->setActive(true); |
35 | 35 | $sql = $prepared->getPreparedSql(); |
36 | 36 | |
37 | - if($sqlText instanceof TSimpleDynamicSql) |
|
38 | - $sql = $sqlText->replaceDynamicParameter($sql, $parameterObject); |
|
37 | + if($sqlText instanceof TSimpleDynamicSql) { |
|
38 | + $sql = $sqlText->replaceDynamicParameter($sql, $parameterObject); |
|
39 | + } |
|
39 | 40 | |
40 | 41 | if($max !== null || $skip !== null) |
41 | 42 | { |
@@ -53,18 +54,24 @@ discard block |
||
53 | 54 | $properties = $prepared->getParameterNames(false); |
54 | 55 | //$parameters = $prepared->getParameterValues(); |
55 | 56 | $registry = $manager->getTypeHandlers(); |
56 | - if ($properties) |
|
57 | - for($i = 0, $k = $properties->getCount(); $i < $k; $i++) |
|
57 | + if ($properties) { |
|
58 | + for($i = 0, $k = $properties->getCount(); |
|
59 | + } |
|
60 | + $i < $k; $i++) |
|
58 | 61 | { |
59 | 62 | $property = $statement->parameterMap()->getProperty($i); |
60 | 63 | $value = $statement->parameterMap()->getPropertyValue($registry, $property, $parameterObject); |
61 | 64 | $dbType = $property->getDbType(); |
62 | - if($dbType == '') //relies on PHP lax comparison |
|
65 | + if($dbType == '') { |
|
66 | + //relies on PHP lax comparison |
|
63 | 67 | $command->bindValue($i + 1, $value, TDbCommandBuilder::getPdoType($value)); |
64 | - elseif(strpos($dbType, 'PDO::') === 0) |
|
65 | - $command->bindValue($i + 1, $value, constant($property->getDbType())); //assumes PDO types, e.g. PDO::PARAM_INT |
|
66 | - else |
|
67 | - $command->bindValue($i + 1, $value); |
|
68 | + } elseif(strpos($dbType, 'PDO::') === 0) { |
|
69 | + $command->bindValue($i + 1, $value, constant($property->getDbType())); |
|
70 | + } |
|
71 | + //assumes PDO types, e.g. PDO::PARAM_INT |
|
72 | + else { |
|
73 | + $command->bindValue($i + 1, $value); |
|
74 | + } |
|
68 | 75 | } |
69 | 76 | } |
70 | 77 | } |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | */ |
175 | 175 | protected function executeSQLQueryLimit($connection, $command, $max, $skip) |
176 | 176 | { |
177 | - if($max > -1 || $skip > -1) |
|
177 | + if ($max > -1 || $skip > -1) |
|
178 | 178 | { |
179 | - $maxStr = $max > 0?' LIMIT ' . $max:''; |
|
180 | - $skipStr = $skip > 0?' OFFSET ' . $skip:''; |
|
181 | - $command->setText($command->getText() . $maxStr . $skipStr); |
|
179 | + $maxStr = $max > 0 ? ' LIMIT '.$max : ''; |
|
180 | + $skipStr = $skip > 0 ? ' OFFSET '.$skip : ''; |
|
181 | + $command->setText($command->getText().$maxStr.$skipStr); |
|
182 | 182 | } |
183 | 183 | $connection->setActive(true); |
184 | 184 | return $command->query(); |
@@ -237,14 +237,13 @@ discard block |
||
237 | 237 | public function runQueryForList($connection, $parameter, $sql, $result, $delegate = null) |
238 | 238 | { |
239 | 239 | $registry = $this->getManager()->getTypeHandlers(); |
240 | - $list = $result instanceof \ArrayAccess ? $result : |
|
241 | - $this->_statement->createInstanceOfListClass($registry); |
|
240 | + $list = $result instanceof \ArrayAccess ? $result : $this->_statement->createInstanceOfListClass($registry); |
|
242 | 241 | $connection->setActive(true); |
243 | 242 | $reader = $sql->query(); |
244 | 243 | //$reader = $this->executeSQLQueryLimit($connection, $sql, $max, $skip); |
245 | - if($delegate !== null) |
|
244 | + if ($delegate !== null) |
|
246 | 245 | { |
247 | - foreach($reader as $row) |
|
246 | + foreach ($reader as $row) |
|
248 | 247 | { |
249 | 248 | $obj = $this->applyResultMap($row); |
250 | 249 | $param = new TResultSetListItemParameter($obj, $parameter, $list); |
@@ -254,14 +253,14 @@ discard block |
||
254 | 253 | else |
255 | 254 | { |
256 | 255 | //var_dump($sql,$parameter); |
257 | - foreach($reader as $row) |
|
256 | + foreach ($reader as $row) |
|
258 | 257 | { |
259 | 258 | // var_dump($row); |
260 | 259 | $list[] = $this->applyResultMap($row); |
261 | 260 | } |
262 | 261 | } |
263 | 262 | |
264 | - if(!$this->_groupBy->isEmpty()) |
|
263 | + if (!$this->_groupBy->isEmpty()) |
|
265 | 264 | { |
266 | 265 | $list = $this->_groupBy->collect(); |
267 | 266 | $this->initialGroupByResults(); |
@@ -315,15 +314,14 @@ discard block |
||
315 | 314 | //$recordSet = $this->executeSQLQuery($connection, $sql); |
316 | 315 | $connection->setActive(true); |
317 | 316 | $reader = $command->query(); |
318 | - if($delegate !== null) |
|
317 | + if ($delegate !== null) |
|
319 | 318 | { |
320 | 319 | //while($row = $recordSet->fetchRow()) |
321 | - foreach($reader as $row) |
|
320 | + foreach ($reader as $row) |
|
322 | 321 | { |
323 | 322 | $obj = $this->applyResultMap($row); |
324 | 323 | $key = TPropertyAccess::get($obj, $keyProperty); |
325 | - $value = ($valueProperty === null) ? $obj : |
|
326 | - TPropertyAccess::get($obj, $valueProperty); |
|
324 | + $value = ($valueProperty === null) ? $obj : TPropertyAccess::get($obj, $valueProperty); |
|
327 | 325 | $param = new TResultSetMapItemParameter($key, $value, $parameter, $map); |
328 | 326 | $this->raiseRowDelegate($delegate, $param); |
329 | 327 | } |
@@ -331,12 +329,11 @@ discard block |
||
331 | 329 | else |
332 | 330 | { |
333 | 331 | //while($row = $recordSet->fetchRow()) |
334 | - foreach($reader as $row) |
|
332 | + foreach ($reader as $row) |
|
335 | 333 | { |
336 | 334 | $obj = $this->applyResultMap($row); |
337 | 335 | $key = TPropertyAccess::get($obj, $keyProperty); |
338 | - $map[$key] = ($valueProperty === null) ? $obj : |
|
339 | - TPropertyAccess::get($obj, $valueProperty); |
|
336 | + $map[$key] = ($valueProperty === null) ? $obj : TPropertyAccess::get($obj, $valueProperty); |
|
340 | 337 | } |
341 | 338 | } |
342 | 339 | $this->onExecuteQuery($command); |
@@ -351,19 +348,19 @@ discard block |
||
351 | 348 | */ |
352 | 349 | protected function raiseRowDelegate($handler, $param) |
353 | 350 | { |
354 | - if(is_string($handler)) |
|
351 | + if (is_string($handler)) |
|
355 | 352 | { |
356 | 353 | call_user_func($handler, $this, $param); |
357 | 354 | } |
358 | - elseif(is_callable($handler, true)) |
|
355 | + elseif (is_callable($handler, true)) |
|
359 | 356 | { |
360 | 357 | // an array: 0 - object, 1 - method name/path |
361 | 358 | list($object, $method) = $handler; |
362 | - if(is_string($object)) // static method call |
|
359 | + if (is_string($object)) // static method call |
|
363 | 360 | call_user_func($handler, $this, $param); |
364 | 361 | else |
365 | 362 | { |
366 | - if(($pos = strrpos($method, '.')) !== false) |
|
363 | + if (($pos = strrpos($method, '.')) !== false) |
|
367 | 364 | { |
368 | 365 | $object = $this->getSubProperty(substr($method, 0, $pos)); |
369 | 366 | $method = substr($method, $pos + 1); |
@@ -406,10 +403,10 @@ discard block |
||
406 | 403 | { |
407 | 404 | $object = null; |
408 | 405 | $connection->setActive(true); |
409 | - foreach($command->query() as $row) |
|
406 | + foreach ($command->query() as $row) |
|
410 | 407 | $object = $this->applyResultMap($row, $result); |
411 | 408 | |
412 | - if(!$this->_groupBy->isEmpty()) |
|
409 | + if (!$this->_groupBy->isEmpty()) |
|
413 | 410 | { |
414 | 411 | $list = $this->_groupBy->collect(); |
415 | 412 | $this->initialGroupByResults(); |
@@ -437,7 +434,7 @@ discard block |
||
437 | 434 | // var_dump($command,$parameter); |
438 | 435 | $result = $command->execute(); |
439 | 436 | |
440 | - if($generatedKey === null) |
|
437 | + if ($generatedKey === null) |
|
441 | 438 | $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter); |
442 | 439 | |
443 | 440 | $this->executePostSelect($connection); |
@@ -453,10 +450,10 @@ discard block |
||
453 | 450 | */ |
454 | 451 | protected function getPreGeneratedSelectKey($connection, $parameter) |
455 | 452 | { |
456 | - if($this->_statement instanceof TSqlMapInsert) |
|
453 | + if ($this->_statement instanceof TSqlMapInsert) |
|
457 | 454 | { |
458 | 455 | $selectKey = $this->_statement->getSelectKey(); |
459 | - if(($selectKey !== null) && !$selectKey->getIsAfter()) |
|
456 | + if (($selectKey !== null) && !$selectKey->getIsAfter()) |
|
460 | 457 | return $this->executeSelectKey($connection, $parameter, $selectKey); |
461 | 458 | } |
462 | 459 | } |
@@ -469,10 +466,10 @@ discard block |
||
469 | 466 | */ |
470 | 467 | protected function getPostGeneratedSelectKey($connection, $parameter) |
471 | 468 | { |
472 | - if($this->_statement instanceof TSqlMapInsert) |
|
469 | + if ($this->_statement instanceof TSqlMapInsert) |
|
473 | 470 | { |
474 | 471 | $selectKey = $this->_statement->getSelectKey(); |
475 | - if(($selectKey !== null) && $selectKey->getIsAfter()) |
|
472 | + if (($selectKey !== null) && $selectKey->getIsAfter()) |
|
476 | 473 | return $this->executeSelectKey($connection, $parameter, $selectKey); |
477 | 474 | } |
478 | 475 | } |
@@ -489,7 +486,7 @@ discard block |
||
489 | 486 | $mappedStatement = $this->getManager()->getMappedStatement($selectKey->getID()); |
490 | 487 | $generatedKey = $mappedStatement->executeQueryForObject( |
491 | 488 | $connection, $parameter, null); |
492 | - if(strlen($prop = $selectKey->getProperty()) > 0) |
|
489 | + if (strlen($prop = $selectKey->getProperty()) > 0) |
|
493 | 490 | TPropertyAccess::set($parameter, $prop, $generatedKey); |
494 | 491 | return $generatedKey; |
495 | 492 | } |
@@ -517,7 +514,7 @@ discard block |
||
517 | 514 | */ |
518 | 515 | protected function executePostSelect($connection) |
519 | 516 | { |
520 | - while(count($this->_selectQueue)) |
|
517 | + while (count($this->_selectQueue)) |
|
521 | 518 | { |
522 | 519 | $postSelect = array_shift($this->_selectQueue); |
523 | 520 | $method = $postSelect->getMethod(); |
@@ -526,15 +523,15 @@ discard block |
||
526 | 523 | $keys = $postSelect->getKeys(); |
527 | 524 | $resultObject = $postSelect->getResultObject(); |
528 | 525 | |
529 | - if($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY) |
|
526 | + if ($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY) |
|
530 | 527 | { |
531 | 528 | $values = $statement->executeQueryForList($connection, $keys, null); |
532 | 529 | |
533 | - if($method == self::QUERY_FOR_ARRAY) |
|
530 | + if ($method == self::QUERY_FOR_ARRAY) |
|
534 | 531 | $values = $values->toArray(); |
535 | 532 | TPropertyAccess::set($resultObject, $property, $values); |
536 | 533 | } |
537 | - elseif($method == self::QUERY_FOR_OBJECT) |
|
534 | + elseif ($method == self::QUERY_FOR_OBJECT) |
|
538 | 535 | { |
539 | 536 | $value = $statement->executeQueryForObject($connection, $keys, null); |
540 | 537 | TPropertyAccess::set($resultObject, $property, $value); |
@@ -559,19 +556,19 @@ discard block |
||
559 | 556 | */ |
560 | 557 | protected function applyResultMap($row, &$resultObject = null) |
561 | 558 | { |
562 | - if($row === false) return null; |
|
559 | + if ($row === false) return null; |
|
563 | 560 | |
564 | 561 | $resultMapName = $this->_statement->getResultMap(); |
565 | 562 | $resultClass = $this->_statement->getResultClass(); |
566 | 563 | |
567 | 564 | $obj = null; |
568 | - if($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
565 | + if ($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
569 | 566 | $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject); |
570 | - elseif(strlen($resultClass) > 0) |
|
567 | + elseif (strlen($resultClass) > 0) |
|
571 | 568 | $obj = $this->fillResultClass($resultClass, $row, $resultObject); |
572 | 569 | else |
573 | 570 | $obj = $this->fillDefaultResultMap(null, $row, $resultObject); |
574 | - if(class_exists('TActiveRecord', false) && $obj instanceof TActiveRecord) |
|
571 | + if (class_exists('TActiveRecord', false) && $obj instanceof TActiveRecord) |
|
575 | 572 | //Create a new clean active record. |
576 | 573 | $obj = TActiveRecord::createRecord(get_class($obj), $obj); |
577 | 574 | return $obj; |
@@ -586,15 +583,15 @@ discard block |
||
586 | 583 | */ |
587 | 584 | protected function fillResultClass($resultClass, $row, $resultObject) |
588 | 585 | { |
589 | - if($resultObject === null) |
|
586 | + if ($resultObject === null) |
|
590 | 587 | { |
591 | 588 | $registry = $this->getManager()->getTypeHandlers(); |
592 | 589 | $resultObject = $this->_statement->createInstanceOfResultClass($registry, $row); |
593 | 590 | } |
594 | 591 | |
595 | - if($resultObject instanceof \ArrayAccess) |
|
592 | + if ($resultObject instanceof \ArrayAccess) |
|
596 | 593 | return $this->fillResultArrayList($row, $resultObject); |
597 | - elseif(is_object($resultObject)) |
|
594 | + elseif (is_object($resultObject)) |
|
598 | 595 | return $this->fillResultObjectProperty($row, $resultObject); |
599 | 596 | else |
600 | 597 | return $this->fillDefaultResultMap(null, $row, $resultObject); |
@@ -608,11 +605,11 @@ discard block |
||
608 | 605 | */ |
609 | 606 | protected function fillResultArrayList($row, $resultObject) |
610 | 607 | { |
611 | - if($resultObject instanceof TList) |
|
612 | - foreach($row as $v) |
|
608 | + if ($resultObject instanceof TList) |
|
609 | + foreach ($row as $v) |
|
613 | 610 | $resultObject[] = $v; |
614 | 611 | else |
615 | - foreach($row as $k => $v) |
|
612 | + foreach ($row as $k => $v) |
|
616 | 613 | $resultObject[$k] = $v; |
617 | 614 | return $resultObject; |
618 | 615 | } |
@@ -627,10 +624,10 @@ discard block |
||
627 | 624 | { |
628 | 625 | $index = 0; |
629 | 626 | $registry = $this->getManager()->getTypeHandlers(); |
630 | - foreach($row as $k => $v) |
|
627 | + foreach ($row as $k => $v) |
|
631 | 628 | { |
632 | 629 | $property = new TResultProperty; |
633 | - if(is_string($k) && strlen($k) > 0) |
|
630 | + if (is_string($k) && strlen($k) > 0) |
|
634 | 631 | $property->setColumn($k); |
635 | 632 | $property->setColumnIndex(++$index); |
636 | 633 | $type = gettype(TPropertyAccess::get($resultObject, $k)); |
@@ -654,15 +651,15 @@ discard block |
||
654 | 651 | $registry = $this->getManager()->getTypeHandlers(); |
655 | 652 | $resultMap = $resultMap->resolveSubMap($registry, $row); |
656 | 653 | |
657 | - if($resultObject === null) |
|
654 | + if ($resultObject === null) |
|
658 | 655 | $resultObject = $resultMap->createInstanceOfResult($registry); |
659 | 656 | |
660 | - if(is_object($resultObject)) |
|
657 | + if (is_object($resultObject)) |
|
661 | 658 | { |
662 | - if(strlen($resultMap->getGroupBy()) > 0) |
|
659 | + if (strlen($resultMap->getGroupBy()) > 0) |
|
663 | 660 | return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
664 | 661 | else |
665 | - foreach($resultMap->getColumns() as $property) |
|
662 | + foreach ($resultMap->getColumns() as $property) |
|
666 | 663 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
667 | 664 | } |
668 | 665 | else |
@@ -684,26 +681,26 @@ discard block |
||
684 | 681 | { |
685 | 682 | $group = $this->getResultMapGroupKey($resultMap, $row); |
686 | 683 | |
687 | - if(empty($parent)) |
|
684 | + if (empty($parent)) |
|
688 | 685 | { |
689 | 686 | $rootObject = ['object' => $resultObject, 'property' => null]; |
690 | 687 | $this->_groupBy->add(null, $group, $rootObject); |
691 | 688 | } |
692 | 689 | |
693 | - foreach($resultMap->getColumns() as $property) |
|
690 | + foreach ($resultMap->getColumns() as $property) |
|
694 | 691 | { |
695 | 692 | //set properties. |
696 | 693 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
697 | 694 | $nested = $property->getResultMapping(); |
698 | 695 | |
699 | 696 | //nested property |
700 | - if($this->getManager()->getResultMaps()->contains($nested)) |
|
697 | + if ($this->getManager()->getResultMaps()->contains($nested)) |
|
701 | 698 | { |
702 | 699 | $nestedMap = $this->getManager()->getResultMap($nested); |
703 | 700 | $groupKey = $this->getResultMapGroupKey($nestedMap, $row); |
704 | 701 | |
705 | 702 | //add the node reference first |
706 | - if(empty($parent)) |
|
703 | + if (empty($parent)) |
|
707 | 704 | $this->_groupBy->add($group, $groupKey, ''); |
708 | 705 | |
709 | 706 | //get the nested result mapping value |
@@ -711,7 +708,7 @@ discard block |
||
711 | 708 | |
712 | 709 | //add it to the object tree graph |
713 | 710 | $groupObject = ['object' => $value, 'property' => $property->getProperty()]; |
714 | - if(empty($parent)) |
|
711 | + if (empty($parent)) |
|
715 | 712 | $this->_groupBy->add($group, $groupKey, $groupObject); |
716 | 713 | else |
717 | 714 | $this->_groupBy->add($parent, $groupKey, $groupObject); |
@@ -729,10 +726,10 @@ discard block |
||
729 | 726 | protected function getResultMapGroupKey($resultMap, $row) |
730 | 727 | { |
731 | 728 | $groupBy = $resultMap->getGroupBy(); |
732 | - if(isset($row[$groupBy])) |
|
733 | - return $resultMap->getID() . $row[$groupBy]; |
|
729 | + if (isset($row[$groupBy])) |
|
730 | + return $resultMap->getID().$row[$groupBy]; |
|
734 | 731 | else |
735 | - return $resultMap->getID() . crc32(serialize($row)); |
|
732 | + return $resultMap->getID().crc32(serialize($row)); |
|
736 | 733 | } |
737 | 734 | |
738 | 735 | /** |
@@ -745,16 +742,16 @@ discard block |
||
745 | 742 | */ |
746 | 743 | protected function fillDefaultResultMap($resultMap, $row, $resultObject) |
747 | 744 | { |
748 | - if($resultObject === null) |
|
745 | + if ($resultObject === null) |
|
749 | 746 | $resultObject = ''; |
750 | 747 | |
751 | - if($resultMap !== null) |
|
748 | + if ($resultMap !== null) |
|
752 | 749 | $result = $this->fillArrayResultMap($resultMap, $row, $resultObject); |
753 | 750 | else |
754 | 751 | $result = $row; |
755 | 752 | |
756 | 753 | //if scalar result types |
757 | - if(count($result) == 1 && ($type = gettype($resultObject)) != 'array') |
|
754 | + if (count($result) == 1 && ($type = gettype($resultObject)) != 'array') |
|
758 | 755 | return $this->getScalarResult($result, $type); |
759 | 756 | else |
760 | 757 | return $result; |
@@ -771,9 +768,9 @@ discard block |
||
771 | 768 | { |
772 | 769 | $result = []; |
773 | 770 | $registry = $this->getManager()->getTypeHandlers(); |
774 | - foreach($resultMap->getColumns() as $column) |
|
771 | + foreach ($resultMap->getColumns() as $column) |
|
775 | 772 | { |
776 | - if(($column->getType() === null) |
|
773 | + if (($column->getType() === null) |
|
777 | 774 | && ($resultObject !== null) && !is_object($resultObject)) |
778 | 775 | $column->setType(gettype($resultObject)); |
779 | 776 | $result[$column->getProperty()] = $column->getPropertyValue($registry, $row); |
@@ -807,25 +804,25 @@ discard block |
||
807 | 804 | $key = $property->getProperty(); |
808 | 805 | $nested = $property->getNestedResultMap(); |
809 | 806 | $registry = $this->getManager()->getTypeHandlers(); |
810 | - if($key === '') |
|
807 | + if ($key === '') |
|
811 | 808 | { |
812 | 809 | $resultObject = $property->getPropertyValue($registry, $row); |
813 | 810 | } |
814 | - elseif(strlen($select) == 0 && ($nested === null)) |
|
811 | + elseif (strlen($select) == 0 && ($nested === null)) |
|
815 | 812 | { |
816 | 813 | $value = $property->getPropertyValue($registry, $row); |
817 | 814 | |
818 | 815 | $this->_IsRowDataFound = $this->_IsRowDataFound || ($value != null); |
819 | - if(is_array($resultObject) || is_object($resultObject)) |
|
816 | + if (is_array($resultObject) || is_object($resultObject)) |
|
820 | 817 | TPropertyAccess::set($resultObject, $key, $value); |
821 | 818 | else |
822 | 819 | $resultObject = $value; |
823 | 820 | } |
824 | - elseif($nested !== null) |
|
821 | + elseif ($nested !== null) |
|
825 | 822 | { |
826 | - if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
|
823 | + if ($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
|
827 | 824 | { |
828 | - if(strlen($resultMap->getGroupBy()) <= 0) |
|
825 | + if (strlen($resultMap->getGroupBy()) <= 0) |
|
829 | 826 | throw new TSqlMapExecutionException( |
830 | 827 | 'sqlmap_non_groupby_array_list_type', $resultMap->getID(), |
831 | 828 | get_class($resultObject), $key); |
@@ -833,7 +830,7 @@ discard block |
||
833 | 830 | else |
834 | 831 | { |
835 | 832 | $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers()); |
836 | - if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
833 | + if ($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
837 | 834 | $obj = null; |
838 | 835 | TPropertyAccess::set($resultObject, $key, $obj); |
839 | 836 | } |
@@ -862,10 +859,10 @@ discard block |
||
862 | 859 | $postSelect->setResultProperty($property); |
863 | 860 | $postSelect->setKeys($key); |
864 | 861 | |
865 | - if($property->instanceOfListType($resultObject)) |
|
862 | + if ($property->instanceOfListType($resultObject)) |
|
866 | 863 | { |
867 | 864 | $values = null; |
868 | - if($property->getLazyLoad()) |
|
865 | + if ($property->getLazyLoad()) |
|
869 | 866 | { |
870 | 867 | $values = TLazyLoadList::newInstance($statement, $key, |
871 | 868 | $resultObject, $property->getProperty()); |
@@ -874,12 +871,12 @@ discard block |
||
874 | 871 | else |
875 | 872 | $postSelect->setMethod(self::QUERY_FOR_LIST); |
876 | 873 | } |
877 | - elseif($property->instanceOfArrayType($resultObject)) |
|
874 | + elseif ($property->instanceOfArrayType($resultObject)) |
|
878 | 875 | $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
879 | 876 | else |
880 | 877 | $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
881 | 878 | |
882 | - if(!$property->getLazyLoad()) |
|
879 | + if (!$property->getLazyLoad()) |
|
883 | 880 | $this->_selectQueue[] = $postSelect; |
884 | 881 | } |
885 | 882 | |
@@ -893,10 +890,10 @@ discard block |
||
893 | 890 | protected function getPostSelectKeys($resultMap, $property, $row) |
894 | 891 | { |
895 | 892 | $value = $property->getColumn(); |
896 | - if(is_int(strpos($value . ',', 0)) || is_int(strpos($value, '=', 0))) |
|
893 | + if (is_int(strpos($value.',', 0)) || is_int(strpos($value, '=', 0))) |
|
897 | 894 | { |
898 | 895 | $keys = []; |
899 | - foreach(explode(',', $value) as $entry) |
|
896 | + foreach (explode(',', $value) as $entry) |
|
900 | 897 | { |
901 | 898 | $pair = explode('=', $entry); |
902 | 899 | $keys[trim($pair[0])] = $row[trim($pair[1])]; |
@@ -920,7 +917,7 @@ discard block |
||
920 | 917 | protected function fillPropertyWithResultMap($resultMap, $row, &$resultObject) |
921 | 918 | { |
922 | 919 | $dataFound = false; |
923 | - foreach($resultMap->getColumns() as $property) |
|
920 | + foreach ($resultMap->getColumns() as $property) |
|
924 | 921 | { |
925 | 922 | $this->_IsRowDataFound = false; |
926 | 923 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
@@ -250,8 +250,7 @@ discard block |
||
250 | 250 | $param = new TResultSetListItemParameter($obj, $parameter, $list); |
251 | 251 | $this->raiseRowDelegate($delegate, $param); |
252 | 252 | } |
253 | - } |
|
254 | - else |
|
253 | + } else |
|
255 | 254 | { |
256 | 255 | //var_dump($sql,$parameter); |
257 | 256 | foreach($reader as $row) |
@@ -327,8 +326,7 @@ discard block |
||
327 | 326 | $param = new TResultSetMapItemParameter($key, $value, $parameter, $map); |
328 | 327 | $this->raiseRowDelegate($delegate, $param); |
329 | 328 | } |
330 | - } |
|
331 | - else |
|
329 | + } else |
|
332 | 330 | { |
333 | 331 | //while($row = $recordSet->fetchRow()) |
334 | 332 | foreach($reader as $row) |
@@ -354,14 +352,14 @@ discard block |
||
354 | 352 | if(is_string($handler)) |
355 | 353 | { |
356 | 354 | call_user_func($handler, $this, $param); |
357 | - } |
|
358 | - elseif(is_callable($handler, true)) |
|
355 | + } elseif(is_callable($handler, true)) |
|
359 | 356 | { |
360 | 357 | // an array: 0 - object, 1 - method name/path |
361 | 358 | list($object, $method) = $handler; |
362 | - if(is_string($object)) // static method call |
|
359 | + if(is_string($object)) { |
|
360 | + // static method call |
|
363 | 361 | call_user_func($handler, $this, $param); |
364 | - else |
|
362 | + } else |
|
365 | 363 | { |
366 | 364 | if(($pos = strrpos($method, '.')) !== false) |
367 | 365 | { |
@@ -370,9 +368,9 @@ discard block |
||
370 | 368 | } |
371 | 369 | $object->$method($this, $param); |
372 | 370 | } |
371 | + } else { |
|
372 | + throw new TInvalidDataValueException('sqlmap_invalid_delegate', $this->getID(), $handler); |
|
373 | 373 | } |
374 | - else |
|
375 | - throw new TInvalidDataValueException('sqlmap_invalid_delegate', $this->getID(), $handler); |
|
376 | 374 | } |
377 | 375 | |
378 | 376 | /** |
@@ -406,8 +404,9 @@ discard block |
||
406 | 404 | { |
407 | 405 | $object = null; |
408 | 406 | $connection->setActive(true); |
409 | - foreach($command->query() as $row) |
|
410 | - $object = $this->applyResultMap($row, $result); |
|
407 | + foreach($command->query() as $row) { |
|
408 | + $object = $this->applyResultMap($row, $result); |
|
409 | + } |
|
411 | 410 | |
412 | 411 | if(!$this->_groupBy->isEmpty()) |
413 | 412 | { |
@@ -437,8 +436,9 @@ discard block |
||
437 | 436 | // var_dump($command,$parameter); |
438 | 437 | $result = $command->execute(); |
439 | 438 | |
440 | - if($generatedKey === null) |
|
441 | - $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter); |
|
439 | + if($generatedKey === null) { |
|
440 | + $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter); |
|
441 | + } |
|
442 | 442 | |
443 | 443 | $this->executePostSelect($connection); |
444 | 444 | $this->onExecuteQuery($command); |
@@ -456,8 +456,9 @@ discard block |
||
456 | 456 | if($this->_statement instanceof TSqlMapInsert) |
457 | 457 | { |
458 | 458 | $selectKey = $this->_statement->getSelectKey(); |
459 | - if(($selectKey !== null) && !$selectKey->getIsAfter()) |
|
460 | - return $this->executeSelectKey($connection, $parameter, $selectKey); |
|
459 | + if(($selectKey !== null) && !$selectKey->getIsAfter()) { |
|
460 | + return $this->executeSelectKey($connection, $parameter, $selectKey); |
|
461 | + } |
|
461 | 462 | } |
462 | 463 | } |
463 | 464 | |
@@ -472,8 +473,9 @@ discard block |
||
472 | 473 | if($this->_statement instanceof TSqlMapInsert) |
473 | 474 | { |
474 | 475 | $selectKey = $this->_statement->getSelectKey(); |
475 | - if(($selectKey !== null) && $selectKey->getIsAfter()) |
|
476 | - return $this->executeSelectKey($connection, $parameter, $selectKey); |
|
476 | + if(($selectKey !== null) && $selectKey->getIsAfter()) { |
|
477 | + return $this->executeSelectKey($connection, $parameter, $selectKey); |
|
478 | + } |
|
477 | 479 | } |
478 | 480 | } |
479 | 481 | |
@@ -489,8 +491,9 @@ discard block |
||
489 | 491 | $mappedStatement = $this->getManager()->getMappedStatement($selectKey->getID()); |
490 | 492 | $generatedKey = $mappedStatement->executeQueryForObject( |
491 | 493 | $connection, $parameter, null); |
492 | - if(strlen($prop = $selectKey->getProperty()) > 0) |
|
493 | - TPropertyAccess::set($parameter, $prop, $generatedKey); |
|
494 | + if(strlen($prop = $selectKey->getProperty()) > 0) { |
|
495 | + TPropertyAccess::set($parameter, $prop, $generatedKey); |
|
496 | + } |
|
494 | 497 | return $generatedKey; |
495 | 498 | } |
496 | 499 | |
@@ -530,11 +533,11 @@ discard block |
||
530 | 533 | { |
531 | 534 | $values = $statement->executeQueryForList($connection, $keys, null); |
532 | 535 | |
533 | - if($method == self::QUERY_FOR_ARRAY) |
|
534 | - $values = $values->toArray(); |
|
536 | + if($method == self::QUERY_FOR_ARRAY) { |
|
537 | + $values = $values->toArray(); |
|
538 | + } |
|
535 | 539 | TPropertyAccess::set($resultObject, $property, $values); |
536 | - } |
|
537 | - elseif($method == self::QUERY_FOR_OBJECT) |
|
540 | + } elseif($method == self::QUERY_FOR_OBJECT) |
|
538 | 541 | { |
539 | 542 | $value = $statement->executeQueryForObject($connection, $keys, null); |
540 | 543 | TPropertyAccess::set($resultObject, $property, $value); |
@@ -559,21 +562,25 @@ discard block |
||
559 | 562 | */ |
560 | 563 | protected function applyResultMap($row, &$resultObject = null) |
561 | 564 | { |
562 | - if($row === false) return null; |
|
565 | + if($row === false) { |
|
566 | + return null; |
|
567 | + } |
|
563 | 568 | |
564 | 569 | $resultMapName = $this->_statement->getResultMap(); |
565 | 570 | $resultClass = $this->_statement->getResultClass(); |
566 | 571 | |
567 | 572 | $obj = null; |
568 | - if($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
569 | - $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject); |
|
570 | - elseif(strlen($resultClass) > 0) |
|
571 | - $obj = $this->fillResultClass($resultClass, $row, $resultObject); |
|
572 | - else |
|
573 | - $obj = $this->fillDefaultResultMap(null, $row, $resultObject); |
|
574 | - if(class_exists('TActiveRecord', false) && $obj instanceof TActiveRecord) |
|
575 | - //Create a new clean active record. |
|
573 | + if($this->getManager()->getResultMaps()->contains($resultMapName)) { |
|
574 | + $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject); |
|
575 | + } elseif(strlen($resultClass) > 0) { |
|
576 | + $obj = $this->fillResultClass($resultClass, $row, $resultObject); |
|
577 | + } else { |
|
578 | + $obj = $this->fillDefaultResultMap(null, $row, $resultObject); |
|
579 | + } |
|
580 | + if(class_exists('TActiveRecord', false) && $obj instanceof TActiveRecord) { |
|
581 | + //Create a new clean active record. |
|
576 | 582 | $obj = TActiveRecord::createRecord(get_class($obj), $obj); |
583 | + } |
|
577 | 584 | return $obj; |
578 | 585 | } |
579 | 586 | |
@@ -592,12 +599,13 @@ discard block |
||
592 | 599 | $resultObject = $this->_statement->createInstanceOfResultClass($registry, $row); |
593 | 600 | } |
594 | 601 | |
595 | - if($resultObject instanceof \ArrayAccess) |
|
596 | - return $this->fillResultArrayList($row, $resultObject); |
|
597 | - elseif(is_object($resultObject)) |
|
598 | - return $this->fillResultObjectProperty($row, $resultObject); |
|
599 | - else |
|
600 | - return $this->fillDefaultResultMap(null, $row, $resultObject); |
|
602 | + if($resultObject instanceof \ArrayAccess) { |
|
603 | + return $this->fillResultArrayList($row, $resultObject); |
|
604 | + } elseif(is_object($resultObject)) { |
|
605 | + return $this->fillResultObjectProperty($row, $resultObject); |
|
606 | + } else { |
|
607 | + return $this->fillDefaultResultMap(null, $row, $resultObject); |
|
608 | + } |
|
601 | 609 | } |
602 | 610 | |
603 | 611 | /** |
@@ -608,12 +616,13 @@ discard block |
||
608 | 616 | */ |
609 | 617 | protected function fillResultArrayList($row, $resultObject) |
610 | 618 | { |
611 | - if($resultObject instanceof TList) |
|
612 | - foreach($row as $v) |
|
619 | + if($resultObject instanceof TList) { |
|
620 | + foreach($row as $v) |
|
613 | 621 | $resultObject[] = $v; |
614 | - else |
|
615 | - foreach($row as $k => $v) |
|
622 | + } else { |
|
623 | + foreach($row as $k => $v) |
|
616 | 624 | $resultObject[$k] = $v; |
625 | + } |
|
617 | 626 | return $resultObject; |
618 | 627 | } |
619 | 628 | |
@@ -630,8 +639,9 @@ discard block |
||
630 | 639 | foreach($row as $k => $v) |
631 | 640 | { |
632 | 641 | $property = new TResultProperty; |
633 | - if(is_string($k) && strlen($k) > 0) |
|
634 | - $property->setColumn($k); |
|
642 | + if(is_string($k) && strlen($k) > 0) { |
|
643 | + $property->setColumn($k); |
|
644 | + } |
|
635 | 645 | $property->setColumnIndex(++$index); |
636 | 646 | $type = gettype(TPropertyAccess::get($resultObject, $k)); |
637 | 647 | $property->setType($type); |
@@ -654,18 +664,19 @@ discard block |
||
654 | 664 | $registry = $this->getManager()->getTypeHandlers(); |
655 | 665 | $resultMap = $resultMap->resolveSubMap($registry, $row); |
656 | 666 | |
657 | - if($resultObject === null) |
|
658 | - $resultObject = $resultMap->createInstanceOfResult($registry); |
|
667 | + if($resultObject === null) { |
|
668 | + $resultObject = $resultMap->createInstanceOfResult($registry); |
|
669 | + } |
|
659 | 670 | |
660 | 671 | if(is_object($resultObject)) |
661 | 672 | { |
662 | - if(strlen($resultMap->getGroupBy()) > 0) |
|
663 | - return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
|
664 | - else |
|
665 | - foreach($resultMap->getColumns() as $property) |
|
673 | + if(strlen($resultMap->getGroupBy()) > 0) { |
|
674 | + return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
|
675 | + } else { |
|
676 | + foreach($resultMap->getColumns() as $property) |
|
666 | 677 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
667 | - } |
|
668 | - else |
|
678 | + } |
|
679 | + } else |
|
669 | 680 | { |
670 | 681 | $resultObject = $this->fillDefaultResultMap($resultMap, $row, $resultObject); |
671 | 682 | } |
@@ -703,18 +714,20 @@ discard block |
||
703 | 714 | $groupKey = $this->getResultMapGroupKey($nestedMap, $row); |
704 | 715 | |
705 | 716 | //add the node reference first |
706 | - if(empty($parent)) |
|
707 | - $this->_groupBy->add($group, $groupKey, ''); |
|
717 | + if(empty($parent)) { |
|
718 | + $this->_groupBy->add($group, $groupKey, ''); |
|
719 | + } |
|
708 | 720 | |
709 | 721 | //get the nested result mapping value |
710 | 722 | $value = $this->fillResultMap($nested, $row, $groupKey); |
711 | 723 | |
712 | 724 | //add it to the object tree graph |
713 | 725 | $groupObject = ['object' => $value, 'property' => $property->getProperty()]; |
714 | - if(empty($parent)) |
|
715 | - $this->_groupBy->add($group, $groupKey, $groupObject); |
|
716 | - else |
|
717 | - $this->_groupBy->add($parent, $groupKey, $groupObject); |
|
726 | + if(empty($parent)) { |
|
727 | + $this->_groupBy->add($group, $groupKey, $groupObject); |
|
728 | + } else { |
|
729 | + $this->_groupBy->add($parent, $groupKey, $groupObject); |
|
730 | + } |
|
718 | 731 | } |
719 | 732 | } |
720 | 733 | return $resultObject; |
@@ -729,10 +742,11 @@ discard block |
||
729 | 742 | protected function getResultMapGroupKey($resultMap, $row) |
730 | 743 | { |
731 | 744 | $groupBy = $resultMap->getGroupBy(); |
732 | - if(isset($row[$groupBy])) |
|
733 | - return $resultMap->getID() . $row[$groupBy]; |
|
734 | - else |
|
735 | - return $resultMap->getID() . crc32(serialize($row)); |
|
745 | + if(isset($row[$groupBy])) { |
|
746 | + return $resultMap->getID() . $row[$groupBy]; |
|
747 | + } else { |
|
748 | + return $resultMap->getID() . crc32(serialize($row)); |
|
749 | + } |
|
736 | 750 | } |
737 | 751 | |
738 | 752 | /** |
@@ -745,19 +759,22 @@ discard block |
||
745 | 759 | */ |
746 | 760 | protected function fillDefaultResultMap($resultMap, $row, $resultObject) |
747 | 761 | { |
748 | - if($resultObject === null) |
|
749 | - $resultObject = ''; |
|
762 | + if($resultObject === null) { |
|
763 | + $resultObject = ''; |
|
764 | + } |
|
750 | 765 | |
751 | - if($resultMap !== null) |
|
752 | - $result = $this->fillArrayResultMap($resultMap, $row, $resultObject); |
|
753 | - else |
|
754 | - $result = $row; |
|
766 | + if($resultMap !== null) { |
|
767 | + $result = $this->fillArrayResultMap($resultMap, $row, $resultObject); |
|
768 | + } else { |
|
769 | + $result = $row; |
|
770 | + } |
|
755 | 771 | |
756 | 772 | //if scalar result types |
757 | - if(count($result) == 1 && ($type = gettype($resultObject)) != 'array') |
|
758 | - return $this->getScalarResult($result, $type); |
|
759 | - else |
|
760 | - return $result; |
|
773 | + if(count($result) == 1 && ($type = gettype($resultObject)) != 'array') { |
|
774 | + return $this->getScalarResult($result, $type); |
|
775 | + } else { |
|
776 | + return $result; |
|
777 | + } |
|
761 | 778 | } |
762 | 779 | |
763 | 780 | /** |
@@ -774,8 +791,9 @@ discard block |
||
774 | 791 | foreach($resultMap->getColumns() as $column) |
775 | 792 | { |
776 | 793 | if(($column->getType() === null) |
777 | - && ($resultObject !== null) && !is_object($resultObject)) |
|
778 | - $column->setType(gettype($resultObject)); |
|
794 | + && ($resultObject !== null) && !is_object($resultObject)) { |
|
795 | + $column->setType(gettype($resultObject)); |
|
796 | + } |
|
779 | 797 | $result[$column->getProperty()] = $column->getPropertyValue($registry, $row); |
780 | 798 | } |
781 | 799 | return $result; |
@@ -810,35 +828,34 @@ discard block |
||
810 | 828 | if($key === '') |
811 | 829 | { |
812 | 830 | $resultObject = $property->getPropertyValue($registry, $row); |
813 | - } |
|
814 | - elseif(strlen($select) == 0 && ($nested === null)) |
|
831 | + } elseif(strlen($select) == 0 && ($nested === null)) |
|
815 | 832 | { |
816 | 833 | $value = $property->getPropertyValue($registry, $row); |
817 | 834 | |
818 | 835 | $this->_IsRowDataFound = $this->_IsRowDataFound || ($value != null); |
819 | - if(is_array($resultObject) || is_object($resultObject)) |
|
820 | - TPropertyAccess::set($resultObject, $key, $value); |
|
821 | - else |
|
822 | - $resultObject = $value; |
|
823 | - } |
|
824 | - elseif($nested !== null) |
|
836 | + if(is_array($resultObject) || is_object($resultObject)) { |
|
837 | + TPropertyAccess::set($resultObject, $key, $value); |
|
838 | + } else { |
|
839 | + $resultObject = $value; |
|
840 | + } |
|
841 | + } elseif($nested !== null) |
|
825 | 842 | { |
826 | 843 | if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
827 | 844 | { |
828 | - if(strlen($resultMap->getGroupBy()) <= 0) |
|
829 | - throw new TSqlMapExecutionException( |
|
845 | + if(strlen($resultMap->getGroupBy()) <= 0) { |
|
846 | + throw new TSqlMapExecutionException( |
|
830 | 847 | 'sqlmap_non_groupby_array_list_type', $resultMap->getID(), |
831 | 848 | get_class($resultObject), $key); |
832 | - } |
|
833 | - else |
|
849 | + } |
|
850 | + } else |
|
834 | 851 | { |
835 | 852 | $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers()); |
836 | - if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
837 | - $obj = null; |
|
853 | + if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) { |
|
854 | + $obj = null; |
|
855 | + } |
|
838 | 856 | TPropertyAccess::set($resultObject, $key, $obj); |
839 | 857 | } |
840 | - } |
|
841 | - else //'select' ResultProperty |
|
858 | + } else //'select' ResultProperty |
|
842 | 859 | { |
843 | 860 | $this->enquequePostSelect($select, $resultMap, $property, $row, $resultObject); |
844 | 861 | } |
@@ -870,17 +887,18 @@ discard block |
||
870 | 887 | $values = TLazyLoadList::newInstance($statement, $key, |
871 | 888 | $resultObject, $property->getProperty()); |
872 | 889 | TPropertyAccess::set($resultObject, $property->getProperty(), $values); |
890 | + } else { |
|
891 | + $postSelect->setMethod(self::QUERY_FOR_LIST); |
|
873 | 892 | } |
874 | - else |
|
875 | - $postSelect->setMethod(self::QUERY_FOR_LIST); |
|
893 | + } elseif($property->instanceOfArrayType($resultObject)) { |
|
894 | + $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
|
895 | + } else { |
|
896 | + $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
|
876 | 897 | } |
877 | - elseif($property->instanceOfArrayType($resultObject)) |
|
878 | - $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
|
879 | - else |
|
880 | - $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
|
881 | 898 | |
882 | - if(!$property->getLazyLoad()) |
|
883 | - $this->_selectQueue[] = $postSelect; |
|
899 | + if(!$property->getLazyLoad()) { |
|
900 | + $this->_selectQueue[] = $postSelect; |
|
901 | + } |
|
884 | 902 | } |
885 | 903 | |
886 | 904 | /** |
@@ -902,8 +920,7 @@ discard block |
||
902 | 920 | $keys[trim($pair[0])] = $row[trim($pair[1])]; |
903 | 921 | } |
904 | 922 | return $keys; |
905 | - } |
|
906 | - else |
|
923 | + } else |
|
907 | 924 | { |
908 | 925 | $registry = $this->getManager()->getTypeHandlers(); |
909 | 926 | return $property->getPropertyValue($registry, $row); |
@@ -932,15 +949,23 @@ discard block |
||
932 | 949 | |
933 | 950 | public function __wakeup() |
934 | 951 | { |
935 | - if (null === $this->_selectQueue) $this->_selectQueue = []; |
|
952 | + if (null === $this->_selectQueue) { |
|
953 | + $this->_selectQueue = []; |
|
954 | + } |
|
936 | 955 | } |
937 | 956 | |
938 | 957 | public function __sleep() |
939 | 958 | { |
940 | 959 | $exprops = []; $cn = __CLASS__; |
941 | - if (!count($this->_selectQueue)) $exprops[] = "\0$cn\0_selectQueue"; |
|
942 | - if (null === $this->_groupBy) $exprops[] = "\0$cn\0_groupBy"; |
|
943 | - if (!$this->_IsRowDataFound) $exprops[] = "\0$cn\0_IsRowDataFound"; |
|
960 | + if (!count($this->_selectQueue)) { |
|
961 | + $exprops[] = "\0$cn\0_selectQueue"; |
|
962 | + } |
|
963 | + if (null === $this->_groupBy) { |
|
964 | + $exprops[] = "\0$cn\0_groupBy"; |
|
965 | + } |
|
966 | + if (!$this->_IsRowDataFound) { |
|
967 | + $exprops[] = "\0$cn\0_IsRowDataFound"; |
|
968 | + } |
|
944 | 969 | return array_diff(parent::__sleep(), $exprops); |
945 | 970 | } |
946 | 971 | } |
947 | 972 | \ No newline at end of file |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getTypeHandlers() |
95 | 95 | { |
96 | - if($this->_typeHandlers === null) |
|
96 | + if ($this->_typeHandlers === null) |
|
97 | 97 | $this->_typeHandlers = new TSqlMapTypeHandlerRegistry(); |
98 | 98 | return $this->_typeHandlers; |
99 | 99 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getSqlmapGateway() |
105 | 105 | { |
106 | - if($this->_gateway === null) |
|
106 | + if ($this->_gateway === null) |
|
107 | 107 | $this->_gateway = $this->createSqlMapGateway(); |
108 | 108 | return $this->_gateway; |
109 | 109 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function getCacheDependencies() |
126 | 126 | { |
127 | - if($this->_cacheDependencies === null) |
|
127 | + if ($this->_cacheDependencies === null) |
|
128 | 128 | $this->_cacheDependencies = new TChainedCacheDependency(); |
129 | 129 | |
130 | 130 | return $this->_cacheDependencies; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function getMappedStatement($name) |
158 | 158 | { |
159 | - if($this->_mappedStatements->contains($name) == false) |
|
159 | + if ($this->_mappedStatements->contains($name) == false) |
|
160 | 160 | throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name); |
161 | 161 | return $this->_mappedStatements[$name]; |
162 | 162 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | public function addMappedStatement(IMappedStatement $statement) |
171 | 171 | { |
172 | 172 | $key = $statement->getID(); |
173 | - if($this->_mappedStatements->contains($key) == true) |
|
173 | + if ($this->_mappedStatements->contains($key) == true) |
|
174 | 174 | throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key); |
175 | 175 | $this->_mappedStatements->add($key, $statement); |
176 | 176 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function getResultMap($name) |
193 | 193 | { |
194 | - if($this->_resultMaps->contains($name) == false) |
|
194 | + if ($this->_resultMaps->contains($name) == false) |
|
195 | 195 | throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name); |
196 | 196 | return $this->_resultMaps[$name]; |
197 | 197 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | public function addResultMap(TResultMap $result) |
204 | 204 | { |
205 | 205 | $key = $result->getID(); |
206 | - if($this->_resultMaps->contains($key) == true) |
|
206 | + if ($this->_resultMaps->contains($key) == true) |
|
207 | 207 | throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key); |
208 | 208 | $this->_resultMaps->add($key, $result); |
209 | 209 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function getParameterMap($name) |
225 | 225 | { |
226 | - if($this->_parameterMaps->contains($name) == false) |
|
226 | + if ($this->_parameterMaps->contains($name) == false) |
|
227 | 227 | throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name); |
228 | 228 | return $this->_parameterMaps[$name]; |
229 | 229 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | public function addParameterMap(TParameterMap $parameter) |
236 | 236 | { |
237 | 237 | $key = $parameter->getID(); |
238 | - if($this->_parameterMaps->contains($key) == true) |
|
238 | + if ($this->_parameterMaps->contains($key) == true) |
|
239 | 239 | throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key); |
240 | 240 | $this->_parameterMaps->add($key, $parameter); |
241 | 241 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function addCacheModel(TSqlMapCacheModel $cacheModel) |
249 | 249 | { |
250 | - if($this->_cacheModels->contains($cacheModel->getID())) |
|
250 | + if ($this->_cacheModels->contains($cacheModel->getID())) |
|
251 | 251 | throw new TSqlMapConfigurationException('sqlmap_cache_model_already_exists', $cacheModel->getID()); |
252 | 252 | else |
253 | 253 | $this->_cacheModels->add($cacheModel->getID(), $cacheModel); |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function getCacheModel($name) |
263 | 263 | { |
264 | - if(!$this->_cacheModels->contains($name)) |
|
264 | + if (!$this->_cacheModels->contains($name)) |
|
265 | 265 | throw new TSqlMapConfigurationException('sqlmap_unable_to_find_cache_model', $name); |
266 | 266 | return $this->_cacheModels[$name]; |
267 | 267 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function flushCacheModels() |
273 | 273 | { |
274 | - foreach($this->_cacheModels as $cache) |
|
274 | + foreach ($this->_cacheModels as $cache) |
|
275 | 275 | $cache->flush(); |
276 | 276 | } |
277 | 277 | } |
@@ -93,8 +93,9 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getTypeHandlers() |
95 | 95 | { |
96 | - if($this->_typeHandlers === null) |
|
97 | - $this->_typeHandlers = new TSqlMapTypeHandlerRegistry(); |
|
96 | + if($this->_typeHandlers === null) { |
|
97 | + $this->_typeHandlers = new TSqlMapTypeHandlerRegistry(); |
|
98 | + } |
|
98 | 99 | return $this->_typeHandlers; |
99 | 100 | } |
100 | 101 | |
@@ -103,8 +104,9 @@ discard block |
||
103 | 104 | */ |
104 | 105 | public function getSqlmapGateway() |
105 | 106 | { |
106 | - if($this->_gateway === null) |
|
107 | - $this->_gateway = $this->createSqlMapGateway(); |
|
107 | + if($this->_gateway === null) { |
|
108 | + $this->_gateway = $this->createSqlMapGateway(); |
|
109 | + } |
|
108 | 110 | return $this->_gateway; |
109 | 111 | } |
110 | 112 | |
@@ -124,8 +126,9 @@ discard block |
||
124 | 126 | */ |
125 | 127 | public function getCacheDependencies() |
126 | 128 | { |
127 | - if($this->_cacheDependencies === null) |
|
128 | - $this->_cacheDependencies = new TChainedCacheDependency(); |
|
129 | + if($this->_cacheDependencies === null) { |
|
130 | + $this->_cacheDependencies = new TChainedCacheDependency(); |
|
131 | + } |
|
129 | 132 | |
130 | 133 | return $this->_cacheDependencies; |
131 | 134 | } |
@@ -156,8 +159,9 @@ discard block |
||
156 | 159 | */ |
157 | 160 | public function getMappedStatement($name) |
158 | 161 | { |
159 | - if($this->_mappedStatements->contains($name) == false) |
|
160 | - throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name); |
|
162 | + if($this->_mappedStatements->contains($name) == false) { |
|
163 | + throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name); |
|
164 | + } |
|
161 | 165 | return $this->_mappedStatements[$name]; |
162 | 166 | } |
163 | 167 | |
@@ -170,8 +174,9 @@ discard block |
||
170 | 174 | public function addMappedStatement(IMappedStatement $statement) |
171 | 175 | { |
172 | 176 | $key = $statement->getID(); |
173 | - if($this->_mappedStatements->contains($key) == true) |
|
174 | - throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key); |
|
177 | + if($this->_mappedStatements->contains($key) == true) { |
|
178 | + throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key); |
|
179 | + } |
|
175 | 180 | $this->_mappedStatements->add($key, $statement); |
176 | 181 | } |
177 | 182 | |
@@ -191,8 +196,9 @@ discard block |
||
191 | 196 | */ |
192 | 197 | public function getResultMap($name) |
193 | 198 | { |
194 | - if($this->_resultMaps->contains($name) == false) |
|
195 | - throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name); |
|
199 | + if($this->_resultMaps->contains($name) == false) { |
|
200 | + throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name); |
|
201 | + } |
|
196 | 202 | return $this->_resultMaps[$name]; |
197 | 203 | } |
198 | 204 | |
@@ -203,8 +209,9 @@ discard block |
||
203 | 209 | public function addResultMap(TResultMap $result) |
204 | 210 | { |
205 | 211 | $key = $result->getID(); |
206 | - if($this->_resultMaps->contains($key) == true) |
|
207 | - throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key); |
|
212 | + if($this->_resultMaps->contains($key) == true) { |
|
213 | + throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key); |
|
214 | + } |
|
208 | 215 | $this->_resultMaps->add($key, $result); |
209 | 216 | } |
210 | 217 | |
@@ -223,8 +230,9 @@ discard block |
||
223 | 230 | */ |
224 | 231 | public function getParameterMap($name) |
225 | 232 | { |
226 | - if($this->_parameterMaps->contains($name) == false) |
|
227 | - throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name); |
|
233 | + if($this->_parameterMaps->contains($name) == false) { |
|
234 | + throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name); |
|
235 | + } |
|
228 | 236 | return $this->_parameterMaps[$name]; |
229 | 237 | } |
230 | 238 | |
@@ -235,8 +243,9 @@ discard block |
||
235 | 243 | public function addParameterMap(TParameterMap $parameter) |
236 | 244 | { |
237 | 245 | $key = $parameter->getID(); |
238 | - if($this->_parameterMaps->contains($key) == true) |
|
239 | - throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key); |
|
246 | + if($this->_parameterMaps->contains($key) == true) { |
|
247 | + throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key); |
|
248 | + } |
|
240 | 249 | $this->_parameterMaps->add($key, $parameter); |
241 | 250 | } |
242 | 251 | |
@@ -247,10 +256,11 @@ discard block |
||
247 | 256 | */ |
248 | 257 | public function addCacheModel(TSqlMapCacheModel $cacheModel) |
249 | 258 | { |
250 | - if($this->_cacheModels->contains($cacheModel->getID())) |
|
251 | - throw new TSqlMapConfigurationException('sqlmap_cache_model_already_exists', $cacheModel->getID()); |
|
252 | - else |
|
253 | - $this->_cacheModels->add($cacheModel->getID(), $cacheModel); |
|
259 | + if($this->_cacheModels->contains($cacheModel->getID())) { |
|
260 | + throw new TSqlMapConfigurationException('sqlmap_cache_model_already_exists', $cacheModel->getID()); |
|
261 | + } else { |
|
262 | + $this->_cacheModels->add($cacheModel->getID(), $cacheModel); |
|
263 | + } |
|
254 | 264 | } |
255 | 265 | |
256 | 266 | /** |
@@ -261,8 +271,9 @@ discard block |
||
261 | 271 | */ |
262 | 272 | public function getCacheModel($name) |
263 | 273 | { |
264 | - if(!$this->_cacheModels->contains($name)) |
|
265 | - throw new TSqlMapConfigurationException('sqlmap_unable_to_find_cache_model', $name); |
|
274 | + if(!$this->_cacheModels->contains($name)) { |
|
275 | + throw new TSqlMapConfigurationException('sqlmap_unable_to_find_cache_model', $name); |
|
276 | + } |
|
266 | 277 | return $this->_cacheModels[$name]; |
267 | 278 | } |
268 | 279 | |
@@ -271,8 +282,9 @@ discard block |
||
271 | 282 | */ |
272 | 283 | public function flushCacheModels() |
273 | 284 | { |
274 | - foreach($this->_cacheModels as $cache) |
|
275 | - $cache->flush(); |
|
285 | + foreach($this->_cacheModels as $cache) { |
|
286 | + $cache->flush(); |
|
287 | + } |
|
276 | 288 | } |
277 | 289 | } |
278 | 290 |
@@ -78,17 +78,17 @@ discard block |
||
78 | 78 | { |
79 | 79 | static $stack = []; |
80 | 80 | |
81 | - $results = call_user_func_array([$this->getSourceRecord(),$method], $args); |
|
81 | + $results = call_user_func_array([$this->getSourceRecord(), $method], $args); |
|
82 | 82 | $validArray = is_array($results) && count($results) > 0; |
83 | - if($validArray || $results instanceof \ArrayAccess || $results instanceof TActiveRecord) |
|
83 | + if ($validArray || $results instanceof \ArrayAccess || $results instanceof TActiveRecord) |
|
84 | 84 | { |
85 | 85 | $this->collectForeignObjects($results); |
86 | - while($obj = array_pop($stack)) |
|
86 | + while ($obj = array_pop($stack)) |
|
87 | 87 | $obj->collectForeignObjects($results); |
88 | 88 | } |
89 | - elseif($results instanceof TActiveRecordRelation) |
|
89 | + elseif ($results instanceof TActiveRecordRelation) |
|
90 | 90 | $stack[] = $this; //call it later |
91 | - elseif($results === null || !$validArray) |
|
91 | + elseif ($results === null || !$validArray) |
|
92 | 92 | $stack = []; |
93 | 93 | return $results; |
94 | 94 | } |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | $matchingTableName = strtolower($recordTableInfo->getTableName()); |
119 | 119 | $matchingFullTableName = strtolower($recordTableInfo->getTableFullName()); |
120 | 120 | $tableInfo = $from; |
121 | - if($from instanceof TActiveRecord) |
|
121 | + if ($from instanceof TActiveRecord) |
|
122 | 122 | $tableInfo = $gateway->getRecordTableInfo($from); |
123 | 123 | //find first non-empty FK |
124 | - foreach($tableInfo->getForeignKeys() as $fkeys) |
|
124 | + foreach ($tableInfo->getForeignKeys() as $fkeys) |
|
125 | 125 | { |
126 | 126 | $fkTable = strtolower($fkeys['table']); |
127 | - if($fkTable === $matchingTableName || $fkTable === $matchingFullTableName) |
|
127 | + if ($fkTable === $matchingTableName || $fkTable === $matchingFullTableName) |
|
128 | 128 | { |
129 | 129 | $hasFkField = !$loose && $this->getContext()->hasFkField(); |
130 | 130 | $key = $hasFkField ? $this->getFkFields($fkeys['keys']) : $fkeys['keys']; |
131 | - if(!empty($key)) |
|
131 | + if (!empty($key)) |
|
132 | 132 | return $key; |
133 | 133 | } |
134 | 134 | } |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | $matching = []; |
156 | 156 | preg_match_all('/\s*(\S+\.)?([\w-]+)\s*/', $this->getContext()->getFkField(), $matching); |
157 | 157 | $fields = []; |
158 | - foreach($fkeys as $fkName => $field) |
|
158 | + foreach ($fkeys as $fkName => $field) |
|
159 | 159 | { |
160 | - if(in_array($fkName, $matching[2])) |
|
160 | + if (in_array($fkName, $matching[2])) |
|
161 | 161 | $fields[$fkName] = $field; |
162 | 162 | } |
163 | 163 | return $fields; |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | protected function getObjectHash($obj, $properties) |
172 | 172 | { |
173 | 173 | $ids = []; |
174 | - foreach($properties as $property) |
|
175 | - $ids[] = is_object($obj) ? (string)$obj->getColumnValue($property) : (string)$obj[$property]; |
|
174 | + foreach ($properties as $property) |
|
175 | + $ids[] = is_object($obj) ? (string) $obj->getColumnValue($property) : (string) $obj[$property]; |
|
176 | 176 | return serialize($ids); |
177 | 177 | } |
178 | 178 | |
@@ -196,13 +196,13 @@ discard block |
||
196 | 196 | */ |
197 | 197 | protected function getIndexValues($keys, $results) |
198 | 198 | { |
199 | - if(!is_array($results) && !$results instanceof \ArrayAccess) |
|
199 | + if (!is_array($results) && !$results instanceof \ArrayAccess) |
|
200 | 200 | $results = [$results]; |
201 | 201 | $values = []; |
202 | - foreach($results as $result) |
|
202 | + foreach ($results as $result) |
|
203 | 203 | { |
204 | 204 | $value = []; |
205 | - foreach($keys as $name) |
|
205 | + foreach ($keys as $name) |
|
206 | 206 | $value[] = $result->getColumnValue($name); |
207 | 207 | $values[] = $value; |
208 | 208 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | protected function populateResult(&$results, $properties, &$fkObjects, $fields) |
220 | 220 | { |
221 | 221 | $collections = []; |
222 | - foreach($fkObjects as $fkObject) |
|
222 | + foreach ($fkObjects as $fkObject) |
|
223 | 223 | $collections[$this->getObjectHash($fkObject, $fields)][] = $fkObject; |
224 | 224 | $this->setResultCollection($results, $collections, $properties); |
225 | 225 | } |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | */ |
233 | 233 | protected function setResultCollection(&$results, &$collections, $properties) |
234 | 234 | { |
235 | - if(is_array($results) || $results instanceof \ArrayAccess) |
|
235 | + if (is_array($results) || $results instanceof \ArrayAccess) |
|
236 | 236 | { |
237 | - for($i = 0,$k = count($results);$i < $k;$i++) |
|
237 | + for ($i = 0, $k = count($results); $i < $k; $i++) |
|
238 | 238 | $this->setObjectProperty($results[$i], $properties, $collections); |
239 | 239 | } |
240 | 240 | else |
@@ -83,13 +83,16 @@ discard block |
||
83 | 83 | if($validArray || $results instanceof \ArrayAccess || $results instanceof TActiveRecord) |
84 | 84 | { |
85 | 85 | $this->collectForeignObjects($results); |
86 | - while($obj = array_pop($stack)) |
|
87 | - $obj->collectForeignObjects($results); |
|
86 | + while($obj = array_pop($stack)) { |
|
87 | + $obj->collectForeignObjects($results); |
|
88 | + } |
|
89 | + } elseif($results instanceof TActiveRecordRelation) { |
|
90 | + $stack[] = $this; |
|
91 | + } |
|
92 | + //call it later |
|
93 | + elseif($results === null || !$validArray) { |
|
94 | + $stack = []; |
|
88 | 95 | } |
89 | - elseif($results instanceof TActiveRecordRelation) |
|
90 | - $stack[] = $this; //call it later |
|
91 | - elseif($results === null || !$validArray) |
|
92 | - $stack = []; |
|
93 | 96 | return $results; |
94 | 97 | } |
95 | 98 | |
@@ -118,8 +121,9 @@ discard block |
||
118 | 121 | $matchingTableName = strtolower($recordTableInfo->getTableName()); |
119 | 122 | $matchingFullTableName = strtolower($recordTableInfo->getTableFullName()); |
120 | 123 | $tableInfo = $from; |
121 | - if($from instanceof TActiveRecord) |
|
122 | - $tableInfo = $gateway->getRecordTableInfo($from); |
|
124 | + if($from instanceof TActiveRecord) { |
|
125 | + $tableInfo = $gateway->getRecordTableInfo($from); |
|
126 | + } |
|
123 | 127 | //find first non-empty FK |
124 | 128 | foreach($tableInfo->getForeignKeys() as $fkeys) |
125 | 129 | { |
@@ -128,8 +132,9 @@ discard block |
||
128 | 132 | { |
129 | 133 | $hasFkField = !$loose && $this->getContext()->hasFkField(); |
130 | 134 | $key = $hasFkField ? $this->getFkFields($fkeys['keys']) : $fkeys['keys']; |
131 | - if(!empty($key)) |
|
132 | - return $key; |
|
135 | + if(!empty($key)) { |
|
136 | + return $key; |
|
137 | + } |
|
133 | 138 | } |
134 | 139 | } |
135 | 140 | |
@@ -157,8 +162,9 @@ discard block |
||
157 | 162 | $fields = []; |
158 | 163 | foreach($fkeys as $fkName => $field) |
159 | 164 | { |
160 | - if(in_array($fkName, $matching[2])) |
|
161 | - $fields[$fkName] = $field; |
|
165 | + if(in_array($fkName, $matching[2])) { |
|
166 | + $fields[$fkName] = $field; |
|
167 | + } |
|
162 | 168 | } |
163 | 169 | return $fields; |
164 | 170 | } |
@@ -171,8 +177,9 @@ discard block |
||
171 | 177 | protected function getObjectHash($obj, $properties) |
172 | 178 | { |
173 | 179 | $ids = []; |
174 | - foreach($properties as $property) |
|
175 | - $ids[] = is_object($obj) ? (string)$obj->getColumnValue($property) : (string)$obj[$property]; |
|
180 | + foreach($properties as $property) { |
|
181 | + $ids[] = is_object($obj) ? (string)$obj->getColumnValue($property) : (string)$obj[$property]; |
|
182 | + } |
|
176 | 183 | return serialize($ids); |
177 | 184 | } |
178 | 185 | |
@@ -196,14 +203,16 @@ discard block |
||
196 | 203 | */ |
197 | 204 | protected function getIndexValues($keys, $results) |
198 | 205 | { |
199 | - if(!is_array($results) && !$results instanceof \ArrayAccess) |
|
200 | - $results = [$results]; |
|
206 | + if(!is_array($results) && !$results instanceof \ArrayAccess) { |
|
207 | + $results = [$results]; |
|
208 | + } |
|
201 | 209 | $values = []; |
202 | 210 | foreach($results as $result) |
203 | 211 | { |
204 | 212 | $value = []; |
205 | - foreach($keys as $name) |
|
206 | - $value[] = $result->getColumnValue($name); |
|
213 | + foreach($keys as $name) { |
|
214 | + $value[] = $result->getColumnValue($name); |
|
215 | + } |
|
207 | 216 | $values[] = $value; |
208 | 217 | } |
209 | 218 | return $values; |
@@ -219,8 +228,9 @@ discard block |
||
219 | 228 | protected function populateResult(&$results, $properties, &$fkObjects, $fields) |
220 | 229 | { |
221 | 230 | $collections = []; |
222 | - foreach($fkObjects as $fkObject) |
|
223 | - $collections[$this->getObjectHash($fkObject, $fields)][] = $fkObject; |
|
231 | + foreach($fkObjects as $fkObject) { |
|
232 | + $collections[$this->getObjectHash($fkObject, $fields)][] = $fkObject; |
|
233 | + } |
|
224 | 234 | $this->setResultCollection($results, $collections, $properties); |
225 | 235 | } |
226 | 236 | |
@@ -234,11 +244,12 @@ discard block |
||
234 | 244 | { |
235 | 245 | if(is_array($results) || $results instanceof \ArrayAccess) |
236 | 246 | { |
237 | - for($i = 0,$k = count($results);$i < $k;$i++) |
|
238 | - $this->setObjectProperty($results[$i], $properties, $collections); |
|
247 | + for($i = 0,$k = count($results);$i < $k;$i++) { |
|
248 | + $this->setObjectProperty($results[$i], $properties, $collections); |
|
249 | + } |
|
250 | + } else { |
|
251 | + $this->setObjectProperty($results, $properties, $collections); |
|
239 | 252 | } |
240 | - else |
|
241 | - $this->setObjectProperty($results, $properties, $collections); |
|
242 | 253 | } |
243 | 254 | |
244 | 255 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function getRelationForeignKeys() |
83 | 83 | { |
84 | - if($this->_fkeys === null) |
|
84 | + if ($this->_fkeys === null) |
|
85 | 85 | $this->_fkeys = $this->getRelationHandler()->getRelationForeignKeys(); |
86 | 86 | return $this->_fkeys; |
87 | 87 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function getCondition() |
119 | 119 | { |
120 | - return isset($this->_relation[3])?$this->_relation[3]:null; |
|
120 | + return isset($this->_relation[3]) ? $this->_relation[3] : null; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function getParameters() |
128 | 128 | { |
129 | - return isset($this->_relation[4])?$this->_relation[4]:[]; |
|
129 | + return isset($this->_relation[4]) ? $this->_relation[4] : []; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function getRelationHandler($criteria = null) |
176 | 176 | { |
177 | - if(!$this->hasRecordRelation()) |
|
177 | + if (!$this->hasRecordRelation()) |
|
178 | 178 | { |
179 | 179 | throw new TActiveRecordException('ar_undefined_relation_prop', |
180 | 180 | $this->_property, get_class($this->_record), 'RELATIONS'); |
181 | 181 | } |
182 | - if($criteria === null) |
|
182 | + if ($criteria === null) |
|
183 | 183 | $criteria = new TActiveRecordCriteria($this->getCondition(), $this->getParameters()); |
184 | - switch($this->getRelationType()) |
|
184 | + switch ($this->getRelationType()) |
|
185 | 185 | { |
186 | 186 | case TActiveRecord::HAS_MANY: |
187 | 187 | return new TActiveRecordHasMany($this, $criteria); |
@@ -202,14 +202,14 @@ discard block |
||
202 | 202 | public function updateAssociatedRecords($updateBelongsTo = false) |
203 | 203 | { |
204 | 204 | $success = true; |
205 | - foreach($this->_record->getRecordRelations() as $data) |
|
205 | + foreach ($this->_record->getRecordRelations() as $data) |
|
206 | 206 | { |
207 | 207 | list($property, $relation) = $data; |
208 | 208 | $belongsTo = $relation[0] == TActiveRecord::BELONGS_TO; |
209 | - if(($updateBelongsTo && $belongsTo) || (!$updateBelongsTo && !$belongsTo)) |
|
209 | + if (($updateBelongsTo && $belongsTo) || (!$updateBelongsTo && !$belongsTo)) |
|
210 | 210 | { |
211 | 211 | $obj = $this->getSourceRecord(); |
212 | - if(!$this->isEmptyFkObject($obj->getColumnValue($property))) |
|
212 | + if (!$this->isEmptyFkObject($obj->getColumnValue($property))) |
|
213 | 213 | { |
214 | 214 | $context = new TActiveRecordRelationContext($this->getSourceRecord(), $property, $relation); |
215 | 215 | $success = $context->getRelationHandler()->updateAssociatedRecords() && $success; |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | |
222 | 222 | protected function isEmptyFkObject($obj) |
223 | 223 | { |
224 | - if(is_object($obj)) |
|
224 | + if (is_object($obj)) |
|
225 | 225 | return $obj instanceof TList ? $obj->count() === 0 : false; |
226 | - elseif(is_array($obj)) |
|
226 | + elseif (is_array($obj)) |
|
227 | 227 | return count($obj) === 0; |
228 | 228 | else |
229 | 229 | return empty($obj); |
@@ -81,8 +81,9 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function getRelationForeignKeys() |
83 | 83 | { |
84 | - if($this->_fkeys === null) |
|
85 | - $this->_fkeys = $this->getRelationHandler()->getRelationForeignKeys(); |
|
84 | + if($this->_fkeys === null) { |
|
85 | + $this->_fkeys = $this->getRelationHandler()->getRelationForeignKeys(); |
|
86 | + } |
|
86 | 87 | return $this->_fkeys; |
87 | 88 | } |
88 | 89 | |
@@ -179,8 +180,9 @@ discard block |
||
179 | 180 | throw new TActiveRecordException('ar_undefined_relation_prop', |
180 | 181 | $this->_property, get_class($this->_record), 'RELATIONS'); |
181 | 182 | } |
182 | - if($criteria === null) |
|
183 | - $criteria = new TActiveRecordCriteria($this->getCondition(), $this->getParameters()); |
|
183 | + if($criteria === null) { |
|
184 | + $criteria = new TActiveRecordCriteria($this->getCondition(), $this->getParameters()); |
|
185 | + } |
|
184 | 186 | switch($this->getRelationType()) |
185 | 187 | { |
186 | 188 | case TActiveRecord::HAS_MANY: |
@@ -221,12 +223,13 @@ discard block |
||
221 | 223 | |
222 | 224 | protected function isEmptyFkObject($obj) |
223 | 225 | { |
224 | - if(is_object($obj)) |
|
225 | - return $obj instanceof TList ? $obj->count() === 0 : false; |
|
226 | - elseif(is_array($obj)) |
|
227 | - return count($obj) === 0; |
|
228 | - else |
|
229 | - return empty($obj); |
|
226 | + if(is_object($obj)) { |
|
227 | + return $obj instanceof TList ? $obj->count() === 0 : false; |
|
228 | + } elseif(is_array($obj)) { |
|
229 | + return count($obj) === 0; |
|
230 | + } else { |
|
231 | + return empty($obj); |
|
232 | + } |
|
230 | 233 | } |
231 | 234 | } |
232 | 235 |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | */ |
122 | 122 | protected function getAssociationTable() |
123 | 123 | { |
124 | - if($this->_association === null) |
|
124 | + if ($this->_association === null) |
|
125 | 125 | { |
126 | 126 | $gateway = $this->getSourceRecord()->getRecordGateway(); |
127 | 127 | $conn = $this->getSourceRecord()->getDbConnection(); |
128 | 128 | //table name may include the fk column name separated with a dot. |
129 | 129 | $table = explode('.', $this->getContext()->getAssociationTable()); |
130 | - if(count($table) > 1) |
|
130 | + if (count($table) > 1) |
|
131 | 131 | { |
132 | 132 | $columns = preg_replace('/^\((.*)\)/', '\1', $table[1]); |
133 | 133 | $this->_association_columns = preg_split('/\s*[, ]\*/', $columns); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | protected function getSourceTable() |
144 | 144 | { |
145 | - if($this->_sourceTable === null) |
|
145 | + if ($this->_sourceTable === null) |
|
146 | 146 | { |
147 | 147 | $gateway = $this->getSourceRecord()->getRecordGateway(); |
148 | 148 | $this->_sourceTable = $gateway->getRecordTableInfo($this->getSourceRecord()); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | protected function getForeignTable() |
157 | 157 | { |
158 | - if($this->_foreignTable === null) |
|
158 | + if ($this->_foreignTable === null) |
|
159 | 159 | { |
160 | 160 | $gateway = $this->getSourceRecord()->getRecordGateway(); |
161 | 161 | $fkObject = $this->getContext()->getForeignRecordFinder(); |
@@ -195,10 +195,10 @@ discard block |
||
195 | 195 | $command = $this->createCommand($criteria, $foreignKeys, $indexValues, $sourceKeys); |
196 | 196 | $srcProps = array_keys($sourceKeys); |
197 | 197 | $collections = []; |
198 | - foreach($this->getCommandBuilder()->onExecuteCommand($command, $command->query()) as $row) |
|
198 | + foreach ($this->getCommandBuilder()->onExecuteCommand($command, $command->query()) as $row) |
|
199 | 199 | { |
200 | 200 | $hash = $this->getObjectHash($row, $srcProps); |
201 | - foreach($srcProps as $column) |
|
201 | + foreach ($srcProps as $column) |
|
202 | 202 | unset($row[$column]); |
203 | 203 | $obj = $this->createFkObject($type, $row, $foreignKeys); |
204 | 204 | $collections[$hash][] = $obj; |
@@ -215,10 +215,10 @@ discard block |
||
215 | 215 | protected function createFkObject($type, $row, $foreignKeys) |
216 | 216 | { |
217 | 217 | $obj = TActiveRecord::createRecord($type, $row); |
218 | - if(count($this->_association_columns) > 0) |
|
218 | + if (count($this->_association_columns) > 0) |
|
219 | 219 | { |
220 | 220 | $i = 0; |
221 | - foreach($foreignKeys as $ref => $fk) |
|
221 | + foreach ($foreignKeys as $ref => $fk) |
|
222 | 222 | $obj->setColumnValue($ref, $row[$this->_association_columns[$i++]]); |
223 | 223 | } |
224 | 224 | return $obj; |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $innerJoin = $this->getAssociationJoin($foreignKeys, $indexValues, $sourceKeys); |
236 | 236 | $fkTable = $this->getForeignTable()->getTableFullName(); |
237 | 237 | $srcColumns = $this->getSourceColumns($sourceKeys); |
238 | - if(($where = $criteria->getCondition()) === null) |
|
238 | + if (($where = $criteria->getCondition()) === null) |
|
239 | 239 | $where = '1=1'; |
240 | 240 | $sql = "SELECT {$fkTable}.*, {$srcColumns} FROM {$fkTable} {$innerJoin} WHERE {$where}"; |
241 | 241 | |
@@ -260,8 +260,8 @@ discard block |
||
260 | 260 | $table = $this->getAssociationTable(); |
261 | 261 | $tableName = $table->getTableFullName(); |
262 | 262 | $columnNames = array_merge(array_keys($sourceKeys), $this->_association_columns); |
263 | - foreach($columnNames as $name) |
|
264 | - $columns[] = $tableName . '.' . $table->getColumn($name)->getColumnName(); |
|
263 | + foreach ($columnNames as $name) |
|
264 | + $columns[] = $tableName.'.'.$table->getColumn($name)->getColumnName(); |
|
265 | 265 | return implode(', ', $columns); |
266 | 266 | } |
267 | 267 | |
@@ -283,9 +283,9 @@ discard block |
||
283 | 283 | $joins = []; |
284 | 284 | $hasAssociationColumns = count($this->_association_columns) > 0; |
285 | 285 | $i = 0; |
286 | - foreach($foreignKeys as $ref => $fk) |
|
286 | + foreach ($foreignKeys as $ref => $fk) |
|
287 | 287 | { |
288 | - if($hasAssociationColumns) |
|
288 | + if ($hasAssociationColumns) |
|
289 | 289 | $refField = $refInfo->getColumn($this->_association_columns[$i++])->getColumnName(); |
290 | 290 | else |
291 | 291 | $refField = $refInfo->getColumn($ref)->getColumnName(); |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | $obj = $this->getContext()->getSourceRecord(); |
307 | 307 | $fkObjects = &$obj->{$this->getContext()->getProperty()}; |
308 | 308 | $success = true; |
309 | - if(($total = count($fkObjects)) > 0) |
|
309 | + if (($total = count($fkObjects)) > 0) |
|
310 | 310 | { |
311 | 311 | $source = $this->getSourceRecord(); |
312 | 312 | $builder = $this->getAssociationTableCommandBuilder(); |
313 | - for($i = 0;$i < $total;$i++) |
|
313 | + for ($i = 0; $i < $total; $i++) |
|
314 | 314 | $success = $fkObjects[$i]->save() && $success; |
315 | 315 | return $this->updateAssociationTable($obj, $fkObjects, $builder) && $success; |
316 | 316 | } |
@@ -330,8 +330,8 @@ discard block |
||
330 | 330 | { |
331 | 331 | $condition = []; |
332 | 332 | $table = $this->getAssociationTable(); |
333 | - foreach($data as $name => $value) |
|
334 | - $condition[] = $table->getColumn($name)->getColumnName() . ' = ?'; |
|
333 | + foreach ($data as $name => $value) |
|
334 | + $condition[] = $table->getColumn($name)->getColumnName().' = ?'; |
|
335 | 335 | $command = $builder->createCountCommand(implode(' AND ', $condition), array_values($data)); |
336 | 336 | $result = $this->getCommandBuilder()->onExecuteCommand($command, intval($command->queryScalar())); |
337 | 337 | return intval($result) > 0; |
@@ -348,10 +348,10 @@ discard block |
||
348 | 348 | $source = $this->getSourceRecordValues($obj); |
349 | 349 | $foreignKeys = $this->findForeignKeys($this->getAssociationTable(), $fkObjects[0]); |
350 | 350 | $success = true; |
351 | - foreach($fkObjects as $fkObject) |
|
351 | + foreach ($fkObjects as $fkObject) |
|
352 | 352 | { |
353 | 353 | $data = array_merge($source, $this->getForeignObjectValues($foreignKeys, $fkObject)); |
354 | - if(!$this->hasAssociationData($builder, $data)) |
|
354 | + if (!$this->hasAssociationData($builder, $data)) |
|
355 | 355 | $success = $this->addAssociationData($builder, $data) && $success; |
356 | 356 | } |
357 | 357 | return $success; |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | $indexValues = $this->getIndexValues(array_values($sourceKeys), $obj); |
364 | 364 | $data = []; |
365 | 365 | $i = 0; |
366 | - foreach($sourceKeys as $name => $srcKey) |
|
366 | + foreach ($sourceKeys as $name => $srcKey) |
|
367 | 367 | $data[$name] = $indexValues[0][$i++]; |
368 | 368 | return $data; |
369 | 369 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | private function getForeignObjectValues($foreignKeys, $fkObject) |
372 | 372 | { |
373 | 373 | $data = []; |
374 | - foreach($foreignKeys as $name => $fKey) |
|
374 | + foreach ($foreignKeys as $name => $fKey) |
|
375 | 375 | $data[$name] = $fkObject->getColumnValue($fKey); |
376 | 376 | return $data; |
377 | 377 | } |
@@ -198,8 +198,9 @@ discard block |
||
198 | 198 | foreach($this->getCommandBuilder()->onExecuteCommand($command, $command->query()) as $row) |
199 | 199 | { |
200 | 200 | $hash = $this->getObjectHash($row, $srcProps); |
201 | - foreach($srcProps as $column) |
|
202 | - unset($row[$column]); |
|
201 | + foreach($srcProps as $column) { |
|
202 | + unset($row[$column]); |
|
203 | + } |
|
203 | 204 | $obj = $this->createFkObject($type, $row, $foreignKeys); |
204 | 205 | $collections[$hash][] = $obj; |
205 | 206 | } |
@@ -218,8 +219,9 @@ discard block |
||
218 | 219 | if(count($this->_association_columns) > 0) |
219 | 220 | { |
220 | 221 | $i = 0; |
221 | - foreach($foreignKeys as $ref => $fk) |
|
222 | - $obj->setColumnValue($ref, $row[$this->_association_columns[$i++]]); |
|
222 | + foreach($foreignKeys as $ref => $fk) { |
|
223 | + $obj->setColumnValue($ref, $row[$this->_association_columns[$i++]]); |
|
224 | + } |
|
223 | 225 | } |
224 | 226 | return $obj; |
225 | 227 | } |
@@ -235,8 +237,9 @@ discard block |
||
235 | 237 | $innerJoin = $this->getAssociationJoin($foreignKeys, $indexValues, $sourceKeys); |
236 | 238 | $fkTable = $this->getForeignTable()->getTableFullName(); |
237 | 239 | $srcColumns = $this->getSourceColumns($sourceKeys); |
238 | - if(($where = $criteria->getCondition()) === null) |
|
239 | - $where = '1=1'; |
|
240 | + if(($where = $criteria->getCondition()) === null) { |
|
241 | + $where = '1=1'; |
|
242 | + } |
|
240 | 243 | $sql = "SELECT {$fkTable}.*, {$srcColumns} FROM {$fkTable} {$innerJoin} WHERE {$where}"; |
241 | 244 | |
242 | 245 | $parameters = $criteria->getParameters()->toArray(); |
@@ -260,8 +263,9 @@ discard block |
||
260 | 263 | $table = $this->getAssociationTable(); |
261 | 264 | $tableName = $table->getTableFullName(); |
262 | 265 | $columnNames = array_merge(array_keys($sourceKeys), $this->_association_columns); |
263 | - foreach($columnNames as $name) |
|
264 | - $columns[] = $tableName . '.' . $table->getColumn($name)->getColumnName(); |
|
266 | + foreach($columnNames as $name) { |
|
267 | + $columns[] = $tableName . '.' . $table->getColumn($name)->getColumnName(); |
|
268 | + } |
|
265 | 269 | return implode(', ', $columns); |
266 | 270 | } |
267 | 271 | |
@@ -285,10 +289,11 @@ discard block |
||
285 | 289 | $i = 0; |
286 | 290 | foreach($foreignKeys as $ref => $fk) |
287 | 291 | { |
288 | - if($hasAssociationColumns) |
|
289 | - $refField = $refInfo->getColumn($this->_association_columns[$i++])->getColumnName(); |
|
290 | - else |
|
291 | - $refField = $refInfo->getColumn($ref)->getColumnName(); |
|
292 | + if($hasAssociationColumns) { |
|
293 | + $refField = $refInfo->getColumn($this->_association_columns[$i++])->getColumnName(); |
|
294 | + } else { |
|
295 | + $refField = $refInfo->getColumn($ref)->getColumnName(); |
|
296 | + } |
|
292 | 297 | $fkField = $fkInfo->getColumn($fk)->getColumnName(); |
293 | 298 | $joins[] = "{$fkTable}.{$fkField} = {$refTable}.{$refField}"; |
294 | 299 | } |
@@ -310,8 +315,9 @@ discard block |
||
310 | 315 | { |
311 | 316 | $source = $this->getSourceRecord(); |
312 | 317 | $builder = $this->getAssociationTableCommandBuilder(); |
313 | - for($i = 0;$i < $total;$i++) |
|
314 | - $success = $fkObjects[$i]->save() && $success; |
|
318 | + for($i = 0;$i < $total;$i++) { |
|
319 | + $success = $fkObjects[$i]->save() && $success; |
|
320 | + } |
|
315 | 321 | return $this->updateAssociationTable($obj, $fkObjects, $builder) && $success; |
316 | 322 | } |
317 | 323 | return $success; |
@@ -330,8 +336,9 @@ discard block |
||
330 | 336 | { |
331 | 337 | $condition = []; |
332 | 338 | $table = $this->getAssociationTable(); |
333 | - foreach($data as $name => $value) |
|
334 | - $condition[] = $table->getColumn($name)->getColumnName() . ' = ?'; |
|
339 | + foreach($data as $name => $value) { |
|
340 | + $condition[] = $table->getColumn($name)->getColumnName() . ' = ?'; |
|
341 | + } |
|
335 | 342 | $command = $builder->createCountCommand(implode(' AND ', $condition), array_values($data)); |
336 | 343 | $result = $this->getCommandBuilder()->onExecuteCommand($command, intval($command->queryScalar())); |
337 | 344 | return intval($result) > 0; |
@@ -351,8 +358,9 @@ discard block |
||
351 | 358 | foreach($fkObjects as $fkObject) |
352 | 359 | { |
353 | 360 | $data = array_merge($source, $this->getForeignObjectValues($foreignKeys, $fkObject)); |
354 | - if(!$this->hasAssociationData($builder, $data)) |
|
355 | - $success = $this->addAssociationData($builder, $data) && $success; |
|
361 | + if(!$this->hasAssociationData($builder, $data)) { |
|
362 | + $success = $this->addAssociationData($builder, $data) && $success; |
|
363 | + } |
|
356 | 364 | } |
357 | 365 | return $success; |
358 | 366 | } |
@@ -363,16 +371,18 @@ discard block |
||
363 | 371 | $indexValues = $this->getIndexValues(array_values($sourceKeys), $obj); |
364 | 372 | $data = []; |
365 | 373 | $i = 0; |
366 | - foreach($sourceKeys as $name => $srcKey) |
|
367 | - $data[$name] = $indexValues[0][$i++]; |
|
374 | + foreach($sourceKeys as $name => $srcKey) { |
|
375 | + $data[$name] = $indexValues[0][$i++]; |
|
376 | + } |
|
368 | 377 | return $data; |
369 | 378 | } |
370 | 379 | |
371 | 380 | private function getForeignObjectValues($foreignKeys, $fkObject) |
372 | 381 | { |
373 | 382 | $data = []; |
374 | - foreach($foreignKeys as $name => $fKey) |
|
375 | - $data[$name] = $fkObject->getColumnValue($fKey); |
|
383 | + foreach($foreignKeys as $name => $fKey) { |
|
384 | + $data[$name] = $fkObject->getColumnValue($fKey); |
|
385 | + } |
|
376 | 386 | return $data; |
377 | 387 | } |
378 | 388 | } |