@@ -73,6 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @param string cache implements of TSqlMapCacheTypes, either 'Basic', 'LRU' or 'FIFO'. |
76 | + * @param string $value |
|
76 | 77 | */ |
77 | 78 | public function setImplementation($value) |
78 | 79 | { |
@@ -129,6 +130,7 @@ discard block |
||
129 | 130 | /** |
130 | 131 | * Register a mapped statement that will trigger a cache flush. |
131 | 132 | * @param TMappedStatement mapped statement that may flush the cache. |
133 | + * @param IMappedStatement $mappedStatement |
|
132 | 134 | */ |
133 | 135 | public function registerTriggerStatement($mappedStatement) |
134 | 136 | { |
@@ -174,7 +176,7 @@ discard block |
||
174 | 176 | } |
175 | 177 | |
176 | 178 | /** |
177 | - * @return float cache hit ratio. |
|
179 | + * @return integer cache hit ratio. |
|
178 | 180 | */ |
179 | 181 | public function getHitRatio() |
180 | 182 | { |
@@ -223,7 +225,7 @@ discard block |
||
223 | 225 | } |
224 | 226 | |
225 | 227 | /** |
226 | - * @param string serialized object |
|
228 | + * @param string string object |
|
227 | 229 | * @return string crc32 hash of the serialized object. |
228 | 230 | */ |
229 | 231 | protected function generateKey($string) |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | private $_hits = 0; |
37 | 37 | private $_requests = 0; |
38 | 38 | private $_id; |
39 | - private $_implementation=TSqlMapCacheTypes::Basic; |
|
39 | + private $_implementation = TSqlMapCacheTypes::Basic; |
|
40 | 40 | private $_properties = array(); |
41 | 41 | private $_flushInterval = 0; |
42 | 42 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | if (isset(self::$_cacheTypes[$value])) |
80 | 80 | $this->_implementation = $value; |
81 | 81 | else |
82 | - $this->_implementation = TPropertyValue::ensureEnum($value,'TSqlMapCacheTypes'); |
|
82 | + $this->_implementation = TPropertyValue::ensureEnum($value, 'TSqlMapCacheTypes'); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function setFlushInterval($value) |
89 | 89 | { |
90 | - $this->_flushInterval=TPropertyValue::ensureInteger($value); |
|
90 | + $this->_flushInterval = TPropertyValue::ensureInteger($value); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | * Initialize the cache implementation, sets the actual cache contain if supplied. |
103 | 103 | * @param ISqLMapCache cache implementation instance. |
104 | 104 | */ |
105 | - public function initialize($cache=null) |
|
105 | + public function initialize($cache = null) |
|
106 | 106 | { |
107 | - if($cache===null) |
|
108 | - $this->_cache= Prado::createComponent($this->getImplementationClass(), $this); |
|
107 | + if ($cache === null) |
|
108 | + $this->_cache = Prado::createComponent($this->getImplementationClass(), $this); |
|
109 | 109 | else |
110 | - $this->_cache=$cache; |
|
110 | + $this->_cache = $cache; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $implementation = $this->_implementation; |
119 | 119 | if (isset(self::$_cacheTypes[$implementation])) return self::$_cacheTypes[$implementation]; |
120 | 120 | |
121 | - switch(TPropertyValue::ensureEnum($implementation,'TSqlMapCacheTypes')) |
|
121 | + switch (TPropertyValue::ensureEnum($implementation, 'TSqlMapCacheTypes')) |
|
122 | 122 | { |
123 | 123 | case TSqlMapCacheTypes::FIFO: return 'TSqlMapFifoCache'; |
124 | 124 | case TSqlMapCacheTypes::LRU : return 'TSqlMapLruCache'; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function registerTriggerStatement($mappedStatement) |
134 | 134 | { |
135 | - $mappedStatement->attachEventHandler('OnExecuteQuery',array($this, 'flush')); |
|
135 | + $mappedStatement->attachEventHandler('OnExecuteQuery', array($this, 'flush')); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function get($key) |
151 | 151 | { |
152 | - if($key instanceof TSqlMapCacheKey) |
|
152 | + if ($key instanceof TSqlMapCacheKey) |
|
153 | 153 | $key = $key->getHash(); |
154 | 154 | |
155 | 155 | //if flush ? |
156 | 156 | $value = $this->_cache->get($key); |
157 | 157 | $this->_requests++; |
158 | - if($value!==null) |
|
158 | + if ($value !== null) |
|
159 | 159 | $this->_hits++; |
160 | 160 | return $value; |
161 | 161 | } |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function set($key, $value) |
168 | 168 | { |
169 | - if($key instanceof TSqlMapCacheKey) |
|
169 | + if ($key instanceof TSqlMapCacheKey) |
|
170 | 170 | $key = $key->getHash(); |
171 | 171 | |
172 | - if($value!==null) |
|
172 | + if ($value !== null) |
|
173 | 173 | $this->_cache->set($key, $value, $this->_flushInterval); |
174 | 174 | } |
175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function getHitRatio() |
180 | 180 | { |
181 | - if($this->_requests != 0) |
|
181 | + if ($this->_requests != 0) |
|
182 | 182 | return $this->_hits / $this->_requests; |
183 | 183 | else |
184 | 184 | return 0; |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | */ |
197 | 197 | class TSqlMapCacheTypes extends TEnumerable |
198 | 198 | { |
199 | - const Basic='Basic'; |
|
200 | - const FIFO='FIFO'; |
|
201 | - const LRU='LRU'; |
|
199 | + const Basic = 'Basic'; |
|
200 | + const FIFO = 'FIFO'; |
|
201 | + const LRU = 'LRU'; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | protected function generateKey($string) |
230 | 230 | { |
231 | - return sprintf('%x',crc32($string)); |
|
231 | + return sprintf('%x', crc32($string)); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -76,10 +76,11 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function setImplementation($value) |
78 | 78 | { |
79 | - if (isset(self::$_cacheTypes[$value])) |
|
80 | - $this->_implementation = $value; |
|
81 | - else |
|
82 | - $this->_implementation = TPropertyValue::ensureEnum($value,'TSqlMapCacheTypes'); |
|
79 | + if (isset(self::$_cacheTypes[$value])) { |
|
80 | + $this->_implementation = $value; |
|
81 | + } else { |
|
82 | + $this->_implementation = TPropertyValue::ensureEnum($value,'TSqlMapCacheTypes'); |
|
83 | + } |
|
83 | 84 | } |
84 | 85 | |
85 | 86 | /** |
@@ -104,10 +105,11 @@ discard block |
||
104 | 105 | */ |
105 | 106 | public function initialize($cache=null) |
106 | 107 | { |
107 | - if($cache===null) |
|
108 | - $this->_cache= Prado::createComponent($this->getImplementationClass(), $this); |
|
109 | - else |
|
110 | - $this->_cache=$cache; |
|
108 | + if($cache===null) { |
|
109 | + $this->_cache= Prado::createComponent($this->getImplementationClass(), $this); |
|
110 | + } else { |
|
111 | + $this->_cache=$cache; |
|
112 | + } |
|
111 | 113 | } |
112 | 114 | |
113 | 115 | /** |
@@ -116,7 +118,9 @@ discard block |
||
116 | 118 | public function getImplementationClass() |
117 | 119 | { |
118 | 120 | $implementation = $this->_implementation; |
119 | - if (isset(self::$_cacheTypes[$implementation])) return self::$_cacheTypes[$implementation]; |
|
121 | + if (isset(self::$_cacheTypes[$implementation])) { |
|
122 | + return self::$_cacheTypes[$implementation]; |
|
123 | + } |
|
120 | 124 | |
121 | 125 | switch(TPropertyValue::ensureEnum($implementation,'TSqlMapCacheTypes')) |
122 | 126 | { |
@@ -149,14 +153,16 @@ discard block |
||
149 | 153 | */ |
150 | 154 | public function get($key) |
151 | 155 | { |
152 | - if($key instanceof TSqlMapCacheKey) |
|
153 | - $key = $key->getHash(); |
|
156 | + if($key instanceof TSqlMapCacheKey) { |
|
157 | + $key = $key->getHash(); |
|
158 | + } |
|
154 | 159 | |
155 | 160 | //if flush ? |
156 | 161 | $value = $this->_cache->get($key); |
157 | 162 | $this->_requests++; |
158 | - if($value!==null) |
|
159 | - $this->_hits++; |
|
163 | + if($value!==null) { |
|
164 | + $this->_hits++; |
|
165 | + } |
|
160 | 166 | return $value; |
161 | 167 | } |
162 | 168 | |
@@ -166,11 +172,13 @@ discard block |
||
166 | 172 | */ |
167 | 173 | public function set($key, $value) |
168 | 174 | { |
169 | - if($key instanceof TSqlMapCacheKey) |
|
170 | - $key = $key->getHash(); |
|
175 | + if($key instanceof TSqlMapCacheKey) { |
|
176 | + $key = $key->getHash(); |
|
177 | + } |
|
171 | 178 | |
172 | - if($value!==null) |
|
173 | - $this->_cache->set($key, $value, $this->_flushInterval); |
|
179 | + if($value!==null) { |
|
180 | + $this->_cache->set($key, $value, $this->_flushInterval); |
|
181 | + } |
|
174 | 182 | } |
175 | 183 | |
176 | 184 | /** |
@@ -178,10 +186,11 @@ discard block |
||
178 | 186 | */ |
179 | 187 | public function getHitRatio() |
180 | 188 | { |
181 | - if($this->_requests != 0) |
|
182 | - return $this->_hits / $this->_requests; |
|
183 | - else |
|
184 | - return 0; |
|
189 | + if($this->_requests != 0) { |
|
190 | + return $this->_hits / $this->_requests; |
|
191 | + } else { |
|
192 | + return 0; |
|
193 | + } |
|
185 | 194 | } |
186 | 195 | } |
187 | 196 |
@@ -268,6 +268,7 @@ |
||
268 | 268 | * @param TSqlMapTypeHandlerRegistry type handler registry |
269 | 269 | * @param string result class name. |
270 | 270 | * @param array result data. |
271 | + * @param string $type |
|
271 | 272 | * @return mixed result object. |
272 | 273 | */ |
273 | 274 | protected function createInstanceOf($registry,$type,$row=null) |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function setID($value) |
57 | 57 | { |
58 | - $this->_ID=$value; |
|
58 | + $this->_ID = $value; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function initialize($manager) |
248 | 248 | { |
249 | - if(strlen($this->_resultMapName) > 0) |
|
249 | + if (strlen($this->_resultMapName) > 0) |
|
250 | 250 | $this->_resultMap = $manager->getResultMap($this->_resultMapName); |
251 | - if(strlen($this->_parameterMapName) > 0) |
|
251 | + if (strlen($this->_parameterMapName) > 0) |
|
252 | 252 | $this->_parameterMap = $manager->getParameterMap($this->_parameterMapName); |
253 | 253 | } |
254 | 254 | |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function createInstanceOfListClass($registry) |
260 | 260 | { |
261 | - if(strlen($type = $this->getListClass()) > 0) |
|
262 | - return $this->createInstanceOf($registry,$type); |
|
261 | + if (strlen($type = $this->getListClass()) > 0) |
|
262 | + return $this->createInstanceOf($registry, $type); |
|
263 | 263 | return array(); |
264 | 264 | } |
265 | 265 | |
@@ -270,10 +270,10 @@ discard block |
||
270 | 270 | * @param array result data. |
271 | 271 | * @return mixed result object. |
272 | 272 | */ |
273 | - protected function createInstanceOf($registry,$type,$row=null) |
|
273 | + protected function createInstanceOf($registry, $type, $row = null) |
|
274 | 274 | { |
275 | 275 | $handler = $registry->getTypeHandler($type); |
276 | - if($handler!==null) |
|
276 | + if ($handler !== null) |
|
277 | 277 | return $handler->createNewInstance($row); |
278 | 278 | else |
279 | 279 | return $registry->createInstanceOf($type); |
@@ -285,10 +285,10 @@ discard block |
||
285 | 285 | * @param array result data. |
286 | 286 | * @return mixed result object. |
287 | 287 | */ |
288 | - public function createInstanceOfResultClass($registry,$row) |
|
288 | + public function createInstanceOfResultClass($registry, $row) |
|
289 | 289 | { |
290 | - if(strlen($type= $this->getResultClass()) > 0) |
|
291 | - return $this->createInstanceOf($registry,$type,$row); |
|
290 | + if (strlen($type = $this->getResultClass()) > 0) |
|
291 | + return $this->createInstanceOf($registry, $type, $row); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | public function __sleep() |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | if (!$this->_extendStatement) $exprops[] = "\0$cn\0_extendStatement"; |
309 | 309 | if (!$this->_cache) $exprops[] = "\0$cn\0_cache"; |
310 | 310 | |
311 | - return array_diff(parent::__sleep(),$exprops); |
|
311 | + return array_diff(parent::__sleep(), $exprops); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | } |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | { |
325 | 325 | private $_generate; |
326 | 326 | |
327 | - public function getGenerate(){ return $this->_generate; } |
|
328 | - public function setGenerate($value){ $this->_generate = $value; } |
|
327 | + public function getGenerate() { return $this->_generate; } |
|
328 | + public function setGenerate($value) { $this->_generate = $value; } |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | */ |
341 | 341 | class TSqlMapInsert extends TSqlMapStatement |
342 | 342 | { |
343 | - private $_selectKey=null; |
|
343 | + private $_selectKey = null; |
|
344 | 344 | |
345 | 345 | /** |
346 | 346 | * @return TSqlMapSelectKey select key element. |
@@ -246,10 +246,12 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function initialize($manager) |
248 | 248 | { |
249 | - if(strlen($this->_resultMapName) > 0) |
|
250 | - $this->_resultMap = $manager->getResultMap($this->_resultMapName); |
|
251 | - if(strlen($this->_parameterMapName) > 0) |
|
252 | - $this->_parameterMap = $manager->getParameterMap($this->_parameterMapName); |
|
249 | + if(strlen($this->_resultMapName) > 0) { |
|
250 | + $this->_resultMap = $manager->getResultMap($this->_resultMapName); |
|
251 | + } |
|
252 | + if(strlen($this->_parameterMapName) > 0) { |
|
253 | + $this->_parameterMap = $manager->getParameterMap($this->_parameterMapName); |
|
254 | + } |
|
253 | 255 | } |
254 | 256 | |
255 | 257 | /** |
@@ -258,8 +260,9 @@ discard block |
||
258 | 260 | */ |
259 | 261 | public function createInstanceOfListClass($registry) |
260 | 262 | { |
261 | - if(strlen($type = $this->getListClass()) > 0) |
|
262 | - return $this->createInstanceOf($registry,$type); |
|
263 | + if(strlen($type = $this->getListClass()) > 0) { |
|
264 | + return $this->createInstanceOf($registry,$type); |
|
265 | + } |
|
263 | 266 | return array(); |
264 | 267 | } |
265 | 268 | |
@@ -273,10 +276,11 @@ discard block |
||
273 | 276 | protected function createInstanceOf($registry,$type,$row=null) |
274 | 277 | { |
275 | 278 | $handler = $registry->getTypeHandler($type); |
276 | - if($handler!==null) |
|
277 | - return $handler->createNewInstance($row); |
|
278 | - else |
|
279 | - return $registry->createInstanceOf($type); |
|
279 | + if($handler!==null) { |
|
280 | + return $handler->createNewInstance($row); |
|
281 | + } else { |
|
282 | + return $registry->createInstanceOf($type); |
|
283 | + } |
|
280 | 284 | } |
281 | 285 | |
282 | 286 | /** |
@@ -287,26 +291,51 @@ discard block |
||
287 | 291 | */ |
288 | 292 | public function createInstanceOfResultClass($registry,$row) |
289 | 293 | { |
290 | - if(strlen($type= $this->getResultClass()) > 0) |
|
291 | - return $this->createInstanceOf($registry,$type,$row); |
|
294 | + if(strlen($type= $this->getResultClass()) > 0) { |
|
295 | + return $this->createInstanceOf($registry,$type,$row); |
|
296 | + } |
|
292 | 297 | } |
293 | 298 | |
294 | 299 | public function __sleep() |
295 | 300 | { |
296 | 301 | $cn = __CLASS__; |
297 | 302 | $exprops = array("\0$cn\0_resultMap"); |
298 | - if (!$this->_parameterMapName) $exprops[] = "\0$cn\0_parameterMapName"; |
|
299 | - if (!$this->_parameterMap) $exprops[] = "\0$cn\0_parameterMap"; |
|
300 | - if (!$this->_parameterClassName) $exprops[] = "\0$cn\0_parameterClassName"; |
|
301 | - if (!$this->_resultMapName) $exprops[] = "\0$cn\0_resultMapName"; |
|
302 | - if (!$this->_resultMap) $exprops[] = "\0$cn\0_resultMap"; |
|
303 | - if (!$this->_resultClassName) $exprops[] = "\0$cn\0_resultClassName"; |
|
304 | - if (!$this->_cacheModelName) $exprops[] = "\0$cn\0_cacheModelName"; |
|
305 | - if (!$this->_SQL) $exprops[] = "\0$cn\0_SQL"; |
|
306 | - if (!$this->_listClass) $exprops[] = "\0$cn\0_listClass"; |
|
307 | - if (!$this->_typeHandler) $exprops[] = "\0$cn\0_typeHandler"; |
|
308 | - if (!$this->_extendStatement) $exprops[] = "\0$cn\0_extendStatement"; |
|
309 | - if (!$this->_cache) $exprops[] = "\0$cn\0_cache"; |
|
303 | + if (!$this->_parameterMapName) { |
|
304 | + $exprops[] = "\0$cn\0_parameterMapName"; |
|
305 | + } |
|
306 | + if (!$this->_parameterMap) { |
|
307 | + $exprops[] = "\0$cn\0_parameterMap"; |
|
308 | + } |
|
309 | + if (!$this->_parameterClassName) { |
|
310 | + $exprops[] = "\0$cn\0_parameterClassName"; |
|
311 | + } |
|
312 | + if (!$this->_resultMapName) { |
|
313 | + $exprops[] = "\0$cn\0_resultMapName"; |
|
314 | + } |
|
315 | + if (!$this->_resultMap) { |
|
316 | + $exprops[] = "\0$cn\0_resultMap"; |
|
317 | + } |
|
318 | + if (!$this->_resultClassName) { |
|
319 | + $exprops[] = "\0$cn\0_resultClassName"; |
|
320 | + } |
|
321 | + if (!$this->_cacheModelName) { |
|
322 | + $exprops[] = "\0$cn\0_cacheModelName"; |
|
323 | + } |
|
324 | + if (!$this->_SQL) { |
|
325 | + $exprops[] = "\0$cn\0_SQL"; |
|
326 | + } |
|
327 | + if (!$this->_listClass) { |
|
328 | + $exprops[] = "\0$cn\0_listClass"; |
|
329 | + } |
|
330 | + if (!$this->_typeHandler) { |
|
331 | + $exprops[] = "\0$cn\0_typeHandler"; |
|
332 | + } |
|
333 | + if (!$this->_extendStatement) { |
|
334 | + $exprops[] = "\0$cn\0_extendStatement"; |
|
335 | + } |
|
336 | + if (!$this->_cache) { |
|
337 | + $exprops[] = "\0$cn\0_cache"; |
|
338 | + } |
|
310 | 339 | |
311 | 340 | return array_diff(parent::__sleep(),$exprops); |
312 | 341 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * Create an instance of an object give by the attribute named 'class' in the |
24 | 24 | * node and set the properties on the object given by attribute names and values. |
25 | 25 | * @param SimpleXmlNode property node |
26 | - * @return Object new instance of class with class name given by 'class' attribute value. |
|
26 | + * @return TComponent new instance of class with class name given by 'class' attribute value. |
|
27 | 27 | */ |
28 | 28 | protected function createObjectFromNode($node) |
29 | 29 | { |
@@ -44,6 +44,7 @@ discard block |
||
44 | 44 | * @param Object object instance |
45 | 45 | * @param SimpleXmlNode property node |
46 | 46 | * @param array exception property name |
47 | + * @param TComponent $obj |
|
47 | 48 | */ |
48 | 49 | protected function setObjectPropFromNode($obj,$node,$except=array()) |
49 | 50 | { |
@@ -65,6 +66,8 @@ discard block |
||
65 | 66 | * Gets the filename relative to the basefile. |
66 | 67 | * @param string base filename |
67 | 68 | * @param string relative filename |
69 | + * @param string $basefile |
|
70 | + * @param string $resource |
|
68 | 71 | * @return string absolute filename. |
69 | 72 | */ |
70 | 73 | protected function getAbsoluteFilePath($basefile,$resource) |
@@ -98,9 +101,10 @@ discard block |
||
98 | 101 | |
99 | 102 | /** |
100 | 103 | * Get element node by ID value (try for attribute name ID as case insensitive). |
101 | - * @param SimpleXmlDocument $document |
|
104 | + * @param SimpleXMLElement $document |
|
102 | 105 | * @param string tag name. |
103 | 106 | * @param string id value. |
107 | + * @param string $tag |
|
104 | 108 | * @return SimpleXmlElement node if found, null otherwise. |
105 | 109 | */ |
106 | 110 | protected function getElementByIdValue($document, $tag, $value) |
@@ -146,6 +150,7 @@ discard block |
||
146 | 150 | |
147 | 151 | /** |
148 | 152 | * @param TSqlMapManager manager instance. |
153 | + * @param TSqlMapManager $manager |
|
149 | 154 | */ |
150 | 155 | public function __construct($manager) |
151 | 156 | { |
@@ -524,6 +529,7 @@ discard block |
||
524 | 529 | * in the sql text. Extracts inline parameter maps. |
525 | 530 | * @param TSqlMapStatement mapped statement. |
526 | 531 | * @param SimpleXmlElement statement node. |
532 | + * @param TSqlMapStatement $statement |
|
527 | 533 | */ |
528 | 534 | protected function processSqlStatement($statement, $node) |
529 | 535 | { |
@@ -547,6 +553,7 @@ discard block |
||
547 | 553 | * @param TSqlMapStatement statement object. |
548 | 554 | * @param string sql text |
549 | 555 | * @param SimpleXmlElement statement node. |
556 | + * @param string $sqlStatement |
|
550 | 557 | */ |
551 | 558 | protected function applyInlineParameterMap($statement, $sqlStatement, $node) |
552 | 559 | { |
@@ -644,6 +651,7 @@ discard block |
||
644 | 651 | /** |
645 | 652 | * Load the selectKey statement from xml mapping. |
646 | 653 | * @param SimpleXmlElement selectkey node |
654 | + * @param TSqlMapInsert $insert |
|
647 | 655 | */ |
648 | 656 | protected function loadSelectKeyTag($insert, $node) |
649 | 657 | { |
@@ -734,6 +742,7 @@ discard block |
||
734 | 742 | * Load the flush interval |
735 | 743 | * @param TSqlMapCacheModel cache model |
736 | 744 | * @param SimpleXmlElement cache node |
745 | + * @param TSqlMapCacheModel $cacheModel |
|
737 | 746 | */ |
738 | 747 | protected function loadFlushInterval($cacheModel, $node) |
739 | 748 | { |
@@ -769,6 +778,7 @@ discard block |
||
769 | 778 | * @param TSqlMapCacheModel cache model |
770 | 779 | * @param SimpleXmlElement parent node. |
771 | 780 | * @param SimpleXmlElement flush node. |
781 | + * @param TSqlMapCacheModel $cacheModel |
|
772 | 782 | */ |
773 | 783 | protected function loadFlushOnCache($cacheModel,$parent,$node) |
774 | 784 | { |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TSqlMapXmlConfigBuilder, TSqlMapXmlConfiguration, TSqlMapXmlMappingConfiguration classes file. |
|
4 | - * |
|
5 | - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Data.SqlMap.Configuration |
|
10 | - */ |
|
3 | + * TSqlMapXmlConfigBuilder, TSqlMapXmlConfiguration, TSqlMapXmlMappingConfiguration classes file. |
|
4 | + * |
|
5 | + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Data.SqlMap.Configuration |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement'); |
13 | 13 |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | */ |
28 | 28 | protected function createObjectFromNode($node) |
29 | 29 | { |
30 | - if(isset($node['class'])) |
|
30 | + if (isset($node['class'])) |
|
31 | 31 | { |
32 | - $obj = Prado::createComponent((string)$node['class']); |
|
33 | - $this->setObjectPropFromNode($obj,$node,array('class')); |
|
32 | + $obj = Prado::createComponent((string) $node['class']); |
|
33 | + $this->setObjectPropFromNode($obj, $node, array('class')); |
|
34 | 34 | return $obj; |
35 | 35 | } |
36 | 36 | throw new TSqlMapConfigurationException( |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | * @param SimpleXmlNode property node |
46 | 46 | * @param array exception property name |
47 | 47 | */ |
48 | - protected function setObjectPropFromNode($obj,$node,$except=array()) |
|
48 | + protected function setObjectPropFromNode($obj, $node, $except = array()) |
|
49 | 49 | { |
50 | - foreach($node->attributes() as $name=>$value) |
|
50 | + foreach ($node->attributes() as $name=>$value) |
|
51 | 51 | { |
52 | - if(!in_array($name,$except)) |
|
52 | + if (!in_array($name, $except)) |
|
53 | 53 | { |
54 | - if($obj->canSetProperty($name)) |
|
55 | - $obj->{$name} = (string)$value; |
|
54 | + if ($obj->canSetProperty($name)) |
|
55 | + $obj->{$name} = (string) $value; |
|
56 | 56 | else |
57 | 57 | throw new TSqlMapConfigurationException( |
58 | 58 | 'sqlmap_invalid_property', $name, get_class($obj), |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | * @param string relative filename |
68 | 68 | * @return string absolute filename. |
69 | 69 | */ |
70 | - protected function getAbsoluteFilePath($basefile,$resource) |
|
70 | + protected function getAbsoluteFilePath($basefile, $resource) |
|
71 | 71 | { |
72 | 72 | $basedir = dirname($basefile); |
73 | - $file = realpath($basedir.DIRECTORY_SEPARATOR.$resource); |
|
74 | - if(!is_string($file) || !is_file($file)) |
|
73 | + $file = realpath($basedir . DIRECTORY_SEPARATOR . $resource); |
|
74 | + if (!is_string($file) || !is_file($file)) |
|
75 | 75 | $file = realpath($resource); |
76 | - if(is_string($file) && is_file($file)) |
|
76 | + if (is_string($file) && is_file($file)) |
|
77 | 77 | return $file; |
78 | 78 | else |
79 | 79 | throw new TSqlMapConfigurationException( |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | * @param string filename. |
86 | 86 | * @return SimpleXmlElement xml document. |
87 | 87 | */ |
88 | - protected function loadXmlDocument($filename,TSqlMapXmlConfiguration $config) |
|
88 | + protected function loadXmlDocument($filename, TSqlMapXmlConfiguration $config) |
|
89 | 89 | { |
90 | - if( strpos($filename, '${') !== false) |
|
90 | + if (strpos($filename, '${') !== false) |
|
91 | 91 | $filename = $config->replaceProperties($filename); |
92 | 92 | |
93 | - if(!is_file($filename)) |
|
93 | + if (!is_file($filename)) |
|
94 | 94 | throw new TSqlMapConfigurationException( |
95 | 95 | 'sqlmap_unable_to_find_config', $filename); |
96 | 96 | return simplexml_load_string($config->replaceProperties(file_get_contents($filename))); |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | protected function getElementByIdValue($document, $tag, $value) |
107 | 107 | { |
108 | 108 | //hack to allow upper case and lower case attribute names. |
109 | - foreach(array('id','ID','Id', 'iD') as $id) |
|
109 | + foreach (array('id', 'ID', 'Id', 'iD') as $id) |
|
110 | 110 | { |
111 | 111 | $xpath = "//{$tag}[@{$id}='{$value}']"; |
112 | - foreach($document->xpath($xpath) as $node) |
|
112 | + foreach ($document->xpath($xpath) as $node) |
|
113 | 113 | return $node; |
114 | 114 | } |
115 | 115 | } |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | /** |
143 | 143 | * @var array global properties. |
144 | 144 | */ |
145 | - private $_properties=array(); |
|
145 | + private $_properties = array(); |
|
146 | 146 | |
147 | 147 | /** |
148 | 148 | * @param TSqlMapManager manager instance. |
149 | 149 | */ |
150 | 150 | public function __construct($manager) |
151 | 151 | { |
152 | - $this->_manager=$manager; |
|
152 | + $this->_manager = $manager; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | public function getManager() |
@@ -166,25 +166,25 @@ discard block |
||
166 | 166 | * Configure the TSqlMapManager using the given xml file. |
167 | 167 | * @param string SqlMap configuration xml file. |
168 | 168 | */ |
169 | - public function configure($filename=null) |
|
169 | + public function configure($filename = null) |
|
170 | 170 | { |
171 | - $this->_configFile=$filename; |
|
172 | - $document = $this->loadXmlDocument($filename,$this); |
|
171 | + $this->_configFile = $filename; |
|
172 | + $document = $this->loadXmlDocument($filename, $this); |
|
173 | 173 | |
174 | - foreach($document->xpath('//property') as $property) |
|
174 | + foreach ($document->xpath('//property') as $property) |
|
175 | 175 | $this->loadGlobalProperty($property); |
176 | 176 | |
177 | - foreach($document->xpath('//typeHandler') as $handler) |
|
177 | + foreach ($document->xpath('//typeHandler') as $handler) |
|
178 | 178 | $this->loadTypeHandler($handler); |
179 | 179 | |
180 | - foreach($document->xpath('//connection[last()]') as $conn) |
|
180 | + foreach ($document->xpath('//connection[last()]') as $conn) |
|
181 | 181 | $this->loadDatabaseConnection($conn); |
182 | 182 | |
183 | 183 | //try to load configuration in the current config file. |
184 | 184 | $mapping = new TSqlMapXmlMappingConfiguration($this); |
185 | 185 | $mapping->configure($filename); |
186 | 186 | |
187 | - foreach($document->xpath('//sqlMap') as $sqlmap) |
|
187 | + foreach ($document->xpath('//sqlMap') as $sqlmap) |
|
188 | 188 | $this->loadSqlMappingFiles($sqlmap); |
189 | 189 | |
190 | 190 | $this->resolveResultMapping(); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | */ |
198 | 198 | protected function loadGlobalProperty($node) |
199 | 199 | { |
200 | - $this->_properties[(string)$node['name']] = (string)$node['value']; |
|
200 | + $this->_properties[(string) $node['name']] = (string) $node['value']; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | */ |
227 | 227 | protected function loadSqlMappingFiles($node) |
228 | 228 | { |
229 | - if(strlen($resource = (string)$node['resource']) > 0) |
|
229 | + if (strlen($resource = (string) $node['resource']) > 0) |
|
230 | 230 | { |
231 | - if( strpos($resource, '${') !== false) |
|
231 | + if (strpos($resource, '${') !== false) |
|
232 | 232 | $resource = $this->replaceProperties($resource); |
233 | 233 | |
234 | 234 | $mapping = new TSqlMapXmlMappingConfiguration($this); |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | protected function resolveResultMapping() |
244 | 244 | { |
245 | 245 | $maps = $this->_manager->getResultMaps(); |
246 | - foreach($maps as $entry) |
|
246 | + foreach ($maps as $entry) |
|
247 | 247 | { |
248 | - foreach($entry->getColumns() as $item) |
|
248 | + foreach ($entry->getColumns() as $item) |
|
249 | 249 | { |
250 | 250 | $resultMap = $item->getResultMapping(); |
251 | - if(strlen($resultMap) > 0) |
|
251 | + if (strlen($resultMap) > 0) |
|
252 | 252 | { |
253 | - if($maps->contains($resultMap)) |
|
253 | + if ($maps->contains($resultMap)) |
|
254 | 254 | $item->setNestedResultMap($maps[$resultMap]); |
255 | 255 | else |
256 | 256 | throw new TSqlMapConfigurationException( |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $resultMap, $this->_configFile, $entry->getID()); |
259 | 259 | } |
260 | 260 | } |
261 | - if($entry->getDiscriminator()!==null) |
|
261 | + if ($entry->getDiscriminator() !== null) |
|
262 | 262 | $entry->getDiscriminator()->initialize($this->_manager); |
263 | 263 | } |
264 | 264 | } |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | */ |
269 | 269 | protected function attachCacheModels() |
270 | 270 | { |
271 | - foreach($this->_manager->getMappedStatements() as $mappedStatement) |
|
271 | + foreach ($this->_manager->getMappedStatements() as $mappedStatement) |
|
272 | 272 | { |
273 | - if(strlen($model = $mappedStatement->getStatement()->getCacheModel()) > 0) |
|
273 | + if (strlen($model = $mappedStatement->getStatement()->getCacheModel()) > 0) |
|
274 | 274 | { |
275 | 275 | $cache = $this->_manager->getCacheModel($model); |
276 | 276 | $mappedStatement->getStatement()->setCache($cache); |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public function replaceProperties($string) |
288 | 288 | { |
289 | - foreach($this->_properties as $find => $replace) |
|
290 | - $string = str_replace('${'.$find.'}', $replace, $string); |
|
289 | + foreach ($this->_properties as $find => $replace) |
|
290 | + $string = str_replace('${' . $find . '}', $replace, $string); |
|
291 | 291 | return $string; |
292 | 292 | } |
293 | 293 | } |
@@ -309,25 +309,25 @@ discard block |
||
309 | 309 | |
310 | 310 | private $_document; |
311 | 311 | |
312 | - private $_FlushOnExecuteStatements=array(); |
|
312 | + private $_FlushOnExecuteStatements = array(); |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * Regular expressions for escaping simple/inline parameter symbols |
316 | 316 | */ |
317 | - const SIMPLE_MARK='$'; |
|
318 | - const INLINE_SYMBOL='#'; |
|
319 | - const ESCAPED_SIMPLE_MARK_REGEXP='/\$\$/'; |
|
320 | - const ESCAPED_INLINE_SYMBOL_REGEXP='/\#\#/'; |
|
321 | - const SIMPLE_PLACEHOLDER='`!!`'; |
|
322 | - const INLINE_PLACEHOLDER='`!!!`'; |
|
317 | + const SIMPLE_MARK = '$'; |
|
318 | + const INLINE_SYMBOL = '#'; |
|
319 | + const ESCAPED_SIMPLE_MARK_REGEXP = '/\$\$/'; |
|
320 | + const ESCAPED_INLINE_SYMBOL_REGEXP = '/\#\#/'; |
|
321 | + const SIMPLE_PLACEHOLDER = '`!!`'; |
|
322 | + const INLINE_PLACEHOLDER = '`!!!`'; |
|
323 | 323 | |
324 | 324 | /** |
325 | 325 | * @param TSqlMapXmlConfiguration parent xml configuration. |
326 | 326 | */ |
327 | 327 | public function __construct(TSqlMapXmlConfiguration $xmlConfig) |
328 | 328 | { |
329 | - $this->_xmlConfig=$xmlConfig; |
|
330 | - $this->_manager=$xmlConfig->getManager(); |
|
329 | + $this->_xmlConfig = $xmlConfig; |
|
330 | + $this->_manager = $xmlConfig->getManager(); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | protected function getConfigFile() |
@@ -341,44 +341,44 @@ discard block |
||
341 | 341 | */ |
342 | 342 | public function configure($filename) |
343 | 343 | { |
344 | - $this->_configFile=$filename; |
|
345 | - $document = $this->loadXmlDocument($filename,$this->_xmlConfig); |
|
346 | - $this->_document=$document; |
|
344 | + $this->_configFile = $filename; |
|
345 | + $document = $this->loadXmlDocument($filename, $this->_xmlConfig); |
|
346 | + $this->_document = $document; |
|
347 | 347 | |
348 | 348 | static $bCacheDependencies; |
349 | - if($bCacheDependencies === null) |
|
349 | + if ($bCacheDependencies === null) |
|
350 | 350 | $bCacheDependencies = Prado::getApplication()->getMode() !== TApplicationMode::Performance; |
351 | 351 | |
352 | - if($bCacheDependencies) |
|
352 | + if ($bCacheDependencies) |
|
353 | 353 | $this->_manager->getCacheDependencies() |
354 | 354 | ->getDependencies() |
355 | 355 | ->add(new TFileCacheDependency($filename)); |
356 | 356 | |
357 | - foreach($document->xpath('//resultMap') as $node) |
|
357 | + foreach ($document->xpath('//resultMap') as $node) |
|
358 | 358 | $this->loadResultMap($node); |
359 | 359 | |
360 | - foreach($document->xpath('//parameterMap') as $node) |
|
360 | + foreach ($document->xpath('//parameterMap') as $node) |
|
361 | 361 | $this->loadParameterMap($node); |
362 | 362 | |
363 | - foreach($document->xpath('//statement') as $node) |
|
363 | + foreach ($document->xpath('//statement') as $node) |
|
364 | 364 | $this->loadStatementTag($node); |
365 | 365 | |
366 | - foreach($document->xpath('//select') as $node) |
|
366 | + foreach ($document->xpath('//select') as $node) |
|
367 | 367 | $this->loadSelectTag($node); |
368 | 368 | |
369 | - foreach($document->xpath('//insert') as $node) |
|
369 | + foreach ($document->xpath('//insert') as $node) |
|
370 | 370 | $this->loadInsertTag($node); |
371 | 371 | |
372 | - foreach($document->xpath('//update') as $node) |
|
372 | + foreach ($document->xpath('//update') as $node) |
|
373 | 373 | $this->loadUpdateTag($node); |
374 | 374 | |
375 | - foreach($document->xpath('//delete') as $node) |
|
375 | + foreach ($document->xpath('//delete') as $node) |
|
376 | 376 | $this->loadDeleteTag($node); |
377 | 377 | |
378 | - foreach($document->xpath('//procedure') as $node) |
|
378 | + foreach ($document->xpath('//procedure') as $node) |
|
379 | 379 | $this->loadProcedureTag($node); |
380 | 380 | |
381 | - foreach($document->xpath('//cacheModel') as $node) |
|
381 | + foreach ($document->xpath('//cacheModel') as $node) |
|
382 | 382 | $this->loadCacheModel($node); |
383 | 383 | |
384 | 384 | $this->registerCacheTriggers(); |
@@ -393,16 +393,16 @@ discard block |
||
393 | 393 | $resultMap = $this->createResultMap($node); |
394 | 394 | |
395 | 395 | //find extended result map. |
396 | - if(strlen($extendMap = $resultMap->getExtends()) > 0) |
|
396 | + if (strlen($extendMap = $resultMap->getExtends()) > 0) |
|
397 | 397 | { |
398 | - if(!$this->_manager->getResultMaps()->contains($extendMap)) |
|
398 | + if (!$this->_manager->getResultMaps()->contains($extendMap)) |
|
399 | 399 | { |
400 | - $extendNode=$this->getElementByIdValue($this->_document,'resultMap',$extendMap); |
|
401 | - if($extendNode!==null) |
|
400 | + $extendNode = $this->getElementByIdValue($this->_document, 'resultMap', $extendMap); |
|
401 | + if ($extendNode !== null) |
|
402 | 402 | $this->loadResultMap($extendNode); |
403 | 403 | } |
404 | 404 | |
405 | - if(!$this->_manager->getResultMaps()->contains($extendMap)) |
|
405 | + if (!$this->_manager->getResultMaps()->contains($extendMap)) |
|
406 | 406 | throw new TSqlMapConfigurationException( |
407 | 407 | 'sqlmap_unable_to_find_parent_result_map', $node, $this->_configFile, $extendMap); |
408 | 408 | |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | } |
412 | 412 | |
413 | 413 | //add the result map |
414 | - if(!$this->_manager->getResultMaps()->contains($resultMap->getID())) |
|
414 | + if (!$this->_manager->getResultMaps()->contains($resultMap->getID())) |
|
415 | 415 | $this->_manager->addResultMap($resultMap); |
416 | 416 | } |
417 | 417 | |
@@ -424,36 +424,36 @@ discard block |
||
424 | 424 | protected function createResultMap($node) |
425 | 425 | { |
426 | 426 | $resultMap = new TResultMap(); |
427 | - $this->setObjectPropFromNode($resultMap,$node); |
|
427 | + $this->setObjectPropFromNode($resultMap, $node); |
|
428 | 428 | |
429 | 429 | //result nodes |
430 | - foreach($node->result as $result) |
|
430 | + foreach ($node->result as $result) |
|
431 | 431 | { |
432 | 432 | $property = new TResultProperty($resultMap); |
433 | - $this->setObjectPropFromNode($property,$result); |
|
433 | + $this->setObjectPropFromNode($property, $result); |
|
434 | 434 | $resultMap->addResultProperty($property); |
435 | 435 | } |
436 | 436 | |
437 | 437 | //create the discriminator |
438 | 438 | $discriminator = null; |
439 | - if(isset($node->discriminator)) |
|
439 | + if (isset($node->discriminator)) |
|
440 | 440 | { |
441 | 441 | $discriminator = new TDiscriminator(); |
442 | 442 | $this->setObjectPropFromNode($discriminator, $node->discriminator); |
443 | 443 | $discriminator->initMapping($resultMap); |
444 | 444 | } |
445 | 445 | |
446 | - foreach($node->xpath('subMap') as $subMapNode) |
|
446 | + foreach ($node->xpath('subMap') as $subMapNode) |
|
447 | 447 | { |
448 | - if($discriminator===null) |
|
448 | + if ($discriminator === null) |
|
449 | 449 | throw new TSqlMapConfigurationException( |
450 | - 'sqlmap_undefined_discriminator', $node, $this->_configFile,$subMapNode); |
|
450 | + 'sqlmap_undefined_discriminator', $node, $this->_configFile, $subMapNode); |
|
451 | 451 | $subMap = new TSubMap; |
452 | - $this->setObjectPropFromNode($subMap,$subMapNode); |
|
452 | + $this->setObjectPropFromNode($subMap, $subMapNode); |
|
453 | 453 | $discriminator->addSubMap($subMap); |
454 | 454 | } |
455 | 455 | |
456 | - if($discriminator!==null) |
|
456 | + if ($discriminator !== null) |
|
457 | 457 | $resultMap->setDiscriminator($discriminator); |
458 | 458 | |
459 | 459 | return $resultMap; |
@@ -468,22 +468,22 @@ discard block |
||
468 | 468 | { |
469 | 469 | $parameterMap = $this->createParameterMap($node); |
470 | 470 | |
471 | - if(strlen($extendMap = $parameterMap->getExtends()) > 0) |
|
471 | + if (strlen($extendMap = $parameterMap->getExtends()) > 0) |
|
472 | 472 | { |
473 | - if(!$this->_manager->getParameterMaps()->contains($extendMap)) |
|
473 | + if (!$this->_manager->getParameterMaps()->contains($extendMap)) |
|
474 | 474 | { |
475 | - $extendNode=$this->getElementByIdValue($this->_document,'parameterMap',$extendMap); |
|
476 | - if($extendNode!==null) |
|
475 | + $extendNode = $this->getElementByIdValue($this->_document, 'parameterMap', $extendMap); |
|
476 | + if ($extendNode !== null) |
|
477 | 477 | $this->loadParameterMap($extendNode); |
478 | 478 | } |
479 | 479 | |
480 | - if(!$this->_manager->getParameterMaps()->contains($extendMap)) |
|
480 | + if (!$this->_manager->getParameterMaps()->contains($extendMap)) |
|
481 | 481 | throw new TSqlMapConfigurationException( |
482 | - 'sqlmap_unable_to_find_parent_parameter_map', $node, $this->_configFile,$extendMap); |
|
482 | + 'sqlmap_unable_to_find_parent_parameter_map', $node, $this->_configFile, $extendMap); |
|
483 | 483 | $superMap = $this->_manager->getParameterMap($extendMap); |
484 | 484 | $index = 0; |
485 | - foreach($superMap->getPropertyNames() as $propertyName) |
|
486 | - $parameterMap->insertProperty($index++,$superMap->getProperty($propertyName)); |
|
485 | + foreach ($superMap->getPropertyNames() as $propertyName) |
|
486 | + $parameterMap->insertProperty($index++, $superMap->getProperty($propertyName)); |
|
487 | 487 | } |
488 | 488 | $this->_manager->addParameterMap($parameterMap); |
489 | 489 | } |
@@ -496,11 +496,11 @@ discard block |
||
496 | 496 | protected function createParameterMap($node) |
497 | 497 | { |
498 | 498 | $parameterMap = new TParameterMap(); |
499 | - $this->setObjectPropFromNode($parameterMap,$node); |
|
500 | - foreach($node->parameter as $parameter) |
|
499 | + $this->setObjectPropFromNode($parameterMap, $node); |
|
500 | + foreach ($node->parameter as $parameter) |
|
501 | 501 | { |
502 | 502 | $property = new TParameterProperty(); |
503 | - $this->setObjectPropFromNode($property,$parameter); |
|
503 | + $this->setObjectPropFromNode($property, $parameter); |
|
504 | 504 | $parameterMap->addProperty($property); |
505 | 505 | } |
506 | 506 | return $parameterMap; |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | protected function loadStatementTag($node) |
514 | 514 | { |
515 | 515 | $statement = new TSqlMapStatement(); |
516 | - $this->setObjectPropFromNode($statement,$node); |
|
516 | + $this->setObjectPropFromNode($statement, $node); |
|
517 | 517 | $this->processSqlStatement($statement, $node); |
518 | 518 | $mappedStatement = new TMappedStatement($this->_manager, $statement); |
519 | 519 | $this->_manager->addMappedStatement($mappedStatement); |
@@ -527,15 +527,15 @@ discard block |
||
527 | 527 | */ |
528 | 528 | protected function processSqlStatement($statement, $node) |
529 | 529 | { |
530 | - $commandText = (string)$node; |
|
531 | - if(strlen($extend = $statement->getExtends()) > 0) |
|
530 | + $commandText = (string) $node; |
|
531 | + if (strlen($extend = $statement->getExtends()) > 0) |
|
532 | 532 | { |
533 | - $superNode = $this->getElementByIdValue($this->_document,'*',$extend); |
|
534 | - if($superNode!==null) |
|
535 | - $commandText = (string)$superNode . $commandText; |
|
533 | + $superNode = $this->getElementByIdValue($this->_document, '*', $extend); |
|
534 | + if ($superNode !== null) |
|
535 | + $commandText = (string) $superNode . $commandText; |
|
536 | 536 | else |
537 | 537 | throw new TSqlMapConfigurationException( |
538 | - 'sqlmap_unable_to_find_parent_sql', $extend, $this->_configFile,$node); |
|
538 | + 'sqlmap_unable_to_find_parent_sql', $extend, $this->_configFile, $node); |
|
539 | 539 | } |
540 | 540 | //$commandText = $this->_xmlConfig->replaceProperties($commandText); |
541 | 541 | $statement->initialize($this->_manager); |
@@ -553,24 +553,24 @@ discard block |
||
553 | 553 | $scope['file'] = $this->_configFile; |
554 | 554 | $scope['node'] = $node; |
555 | 555 | |
556 | - $sqlStatement=preg_replace(self::ESCAPED_INLINE_SYMBOL_REGEXP,self::INLINE_PLACEHOLDER,$sqlStatement); |
|
557 | - if($statement->parameterMap() === null) |
|
556 | + $sqlStatement = preg_replace(self::ESCAPED_INLINE_SYMBOL_REGEXP, self::INLINE_PLACEHOLDER, $sqlStatement); |
|
557 | + if ($statement->parameterMap() === null) |
|
558 | 558 | { |
559 | 559 | // Build a Parametermap with the inline parameters. |
560 | 560 | // if they exist. Then delete inline infos from sqltext. |
561 | 561 | $parameterParser = new TInlineParameterMapParser; |
562 | 562 | $sqlText = $parameterParser->parse($sqlStatement, $scope); |
563 | - if(count($sqlText['parameters']) > 0) |
|
563 | + if (count($sqlText['parameters']) > 0) |
|
564 | 564 | { |
565 | 565 | $map = new TParameterMap(); |
566 | - $map->setID($statement->getID().'-InLineParameterMap'); |
|
566 | + $map->setID($statement->getID() . '-InLineParameterMap'); |
|
567 | 567 | $statement->setInlineParameterMap($map); |
568 | - foreach($sqlText['parameters'] as $property) |
|
568 | + foreach ($sqlText['parameters'] as $property) |
|
569 | 569 | $map->addProperty($property); |
570 | 570 | } |
571 | 571 | $sqlStatement = $sqlText['sql']; |
572 | 572 | } |
573 | - $sqlStatement=preg_replace('/'.self::INLINE_PLACEHOLDER.'/',self::INLINE_SYMBOL,$sqlStatement); |
|
573 | + $sqlStatement = preg_replace('/' . self::INLINE_PLACEHOLDER . '/', self::INLINE_SYMBOL, $sqlStatement); |
|
574 | 574 | |
575 | 575 | $this->prepareSql($statement, $sqlStatement, $node); |
576 | 576 | } |
@@ -582,19 +582,19 @@ discard block |
||
582 | 582 | * @param SimpleXmlElement statement node. |
583 | 583 | * @todo Extend to dynamic sql. |
584 | 584 | */ |
585 | - protected function prepareSql($statement,$sqlStatement, $node) |
|
585 | + protected function prepareSql($statement, $sqlStatement, $node) |
|
586 | 586 | { |
587 | 587 | $simpleDynamic = new TSimpleDynamicParser; |
588 | - $sqlStatement=preg_replace(self::ESCAPED_SIMPLE_MARK_REGEXP,self::SIMPLE_PLACEHOLDER,$sqlStatement); |
|
588 | + $sqlStatement = preg_replace(self::ESCAPED_SIMPLE_MARK_REGEXP, self::SIMPLE_PLACEHOLDER, $sqlStatement); |
|
589 | 589 | $dynamics = $simpleDynamic->parse($sqlStatement); |
590 | - if(count($dynamics['parameters']) > 0) |
|
590 | + if (count($dynamics['parameters']) > 0) |
|
591 | 591 | { |
592 | 592 | $sql = new TSimpleDynamicSql($dynamics['parameters']); |
593 | 593 | $sqlStatement = $dynamics['sql']; |
594 | 594 | } |
595 | 595 | else |
596 | 596 | $sql = new TStaticSql(); |
597 | - $sqlStatement=preg_replace('/'.self::SIMPLE_PLACEHOLDER.'/',self::SIMPLE_MARK,$sqlStatement); |
|
597 | + $sqlStatement = preg_replace('/' . self::SIMPLE_PLACEHOLDER . '/', self::SIMPLE_MARK, $sqlStatement); |
|
598 | 598 | $sql->buildPreparedStatement($statement, $sqlStatement); |
599 | 599 | $statement->setSqlText($sql); |
600 | 600 | } |
@@ -606,10 +606,10 @@ discard block |
||
606 | 606 | protected function loadSelectTag($node) |
607 | 607 | { |
608 | 608 | $select = new TSqlMapSelect; |
609 | - $this->setObjectPropFromNode($select,$node); |
|
610 | - $this->processSqlStatement($select,$node); |
|
609 | + $this->setObjectPropFromNode($select, $node); |
|
610 | + $this->processSqlStatement($select, $node); |
|
611 | 611 | $mappedStatement = new TMappedStatement($this->_manager, $select); |
612 | - if(strlen($select->getCacheModel()) > 0) |
|
612 | + if (strlen($select->getCacheModel()) > 0) |
|
613 | 613 | $mappedStatement = new TCachingStatement($mappedStatement); |
614 | 614 | |
615 | 615 | $this->_manager->addMappedStatement($mappedStatement); |
@@ -635,9 +635,9 @@ discard block |
||
635 | 635 | protected function createInsertStatement($node) |
636 | 636 | { |
637 | 637 | $insert = new TSqlMapInsert; |
638 | - $this->setObjectPropFromNode($insert,$node); |
|
639 | - if(isset($node->selectKey)) |
|
640 | - $this->loadSelectKeyTag($insert,$node->selectKey); |
|
638 | + $this->setObjectPropFromNode($insert, $node); |
|
639 | + if (isset($node->selectKey)) |
|
640 | + $this->loadSelectKeyTag($insert, $node->selectKey); |
|
641 | 641 | return $insert; |
642 | 642 | } |
643 | 643 | |
@@ -648,10 +648,10 @@ discard block |
||
648 | 648 | protected function loadSelectKeyTag($insert, $node) |
649 | 649 | { |
650 | 650 | $selectKey = new TSqlMapSelectKey; |
651 | - $this->setObjectPropFromNode($selectKey,$node); |
|
651 | + $this->setObjectPropFromNode($selectKey, $node); |
|
652 | 652 | $selectKey->setID($insert->getID()); |
653 | - $selectKey->setID($insert->getID().'.SelectKey'); |
|
654 | - $this->processSqlStatement($selectKey,$node); |
|
653 | + $selectKey->setID($insert->getID() . '.SelectKey'); |
|
654 | + $this->processSqlStatement($selectKey, $node); |
|
655 | 655 | $insert->setSelectKey($selectKey); |
656 | 656 | $mappedStatement = new TMappedStatement($this->_manager, $selectKey); |
657 | 657 | $this->_manager->addMappedStatement($mappedStatement); |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | protected function loadUpdateTag($node) |
665 | 665 | { |
666 | 666 | $update = new TSqlMapUpdate; |
667 | - $this->setObjectPropFromNode($update,$node); |
|
667 | + $this->setObjectPropFromNode($update, $node); |
|
668 | 668 | $this->processSqlStatement($update, $node); |
669 | 669 | $mappedStatement = new TUpdateMappedStatement($this->_manager, $update); |
670 | 670 | $this->_manager->addMappedStatement($mappedStatement); |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | protected function loadDeleteTag($node) |
678 | 678 | { |
679 | 679 | $delete = new TSqlMapDelete; |
680 | - $this->setObjectPropFromNode($delete,$node); |
|
680 | + $this->setObjectPropFromNode($delete, $node); |
|
681 | 681 | $this->processSqlStatement($delete, $node); |
682 | 682 | $mappedStatement = new TDeleteMappedStatement($this->_manager, $delete); |
683 | 683 | $this->_manager->addMappedStatement($mappedStatement); |
@@ -700,34 +700,34 @@ discard block |
||
700 | 700 | protected function loadCacheModel($node) |
701 | 701 | { |
702 | 702 | $cacheModel = new TSqlMapCacheModel; |
703 | - $properties = array('id','implementation'); |
|
704 | - foreach($node->attributes() as $name=>$value) |
|
703 | + $properties = array('id', 'implementation'); |
|
704 | + foreach ($node->attributes() as $name=>$value) |
|
705 | 705 | { |
706 | - if(in_array(strtolower($name), $properties)) |
|
707 | - $cacheModel->{'set'.$name}((string)$value); |
|
706 | + if (in_array(strtolower($name), $properties)) |
|
707 | + $cacheModel->{'set' . $name}((string) $value); |
|
708 | 708 | } |
709 | 709 | $cache = Prado::createComponent($cacheModel->getImplementationClass(), $cacheModel); |
710 | - $this->setObjectPropFromNode($cache,$node,$properties); |
|
710 | + $this->setObjectPropFromNode($cache, $node, $properties); |
|
711 | 711 | |
712 | - foreach($node->xpath('property') as $propertyNode) |
|
712 | + foreach ($node->xpath('property') as $propertyNode) |
|
713 | 713 | { |
714 | 714 | $name = $propertyNode->attributes()->name; |
715 | - if($name===null || $name==='') continue; |
|
715 | + if ($name === null || $name === '') continue; |
|
716 | 716 | |
717 | 717 | $value = $propertyNode->attributes()->value; |
718 | - if($value===null || $value==='') continue; |
|
718 | + if ($value === null || $value === '') continue; |
|
719 | 719 | |
720 | - if( !TPropertyAccess::has($cache, $name) ) continue; |
|
720 | + if (!TPropertyAccess::has($cache, $name)) continue; |
|
721 | 721 | |
722 | 722 | TPropertyAccess::set($cache, $name, $value); |
723 | 723 | } |
724 | 724 | |
725 | - $this->loadFlushInterval($cacheModel,$node); |
|
725 | + $this->loadFlushInterval($cacheModel, $node); |
|
726 | 726 | |
727 | 727 | $cacheModel->initialize($cache); |
728 | 728 | $this->_manager->addCacheModel($cacheModel); |
729 | - foreach($node->xpath('flushOnExecute') as $flush) |
|
730 | - $this->loadFlushOnCache($cacheModel,$node,$flush); |
|
729 | + foreach ($node->xpath('flushOnExecute') as $flush) |
|
730 | + $this->loadFlushOnCache($cacheModel, $node, $flush); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -738,26 +738,26 @@ discard block |
||
738 | 738 | protected function loadFlushInterval($cacheModel, $node) |
739 | 739 | { |
740 | 740 | $flushInterval = $node->xpath('flushInterval'); |
741 | - if($flushInterval === null || count($flushInterval) === 0) return; |
|
741 | + if ($flushInterval === null || count($flushInterval) === 0) return; |
|
742 | 742 | $duration = 0; |
743 | - foreach($flushInterval[0]->attributes() as $name=>$value) |
|
743 | + foreach ($flushInterval[0]->attributes() as $name=>$value) |
|
744 | 744 | { |
745 | - switch(strToLower($name)) |
|
745 | + switch (strToLower($name)) |
|
746 | 746 | { |
747 | 747 | case 'seconds': |
748 | - $duration += (integer)$value; |
|
748 | + $duration += (integer) $value; |
|
749 | 749 | break; |
750 | 750 | case 'minutes': |
751 | - $duration += 60 * (integer)$value; |
|
751 | + $duration += 60 * (integer) $value; |
|
752 | 752 | break; |
753 | 753 | case 'hours': |
754 | - $duration += 3600 * (integer)$value; |
|
754 | + $duration += 3600 * (integer) $value; |
|
755 | 755 | break; |
756 | 756 | case 'days': |
757 | - $duration += 86400 * (integer)$value; |
|
757 | + $duration += 86400 * (integer) $value; |
|
758 | 758 | break; |
759 | 759 | case 'duration': |
760 | - $duration = (integer)$value; |
|
760 | + $duration = (integer) $value; |
|
761 | 761 | break 2; // switch, foreach |
762 | 762 | } |
763 | 763 | } |
@@ -770,15 +770,15 @@ discard block |
||
770 | 770 | * @param SimpleXmlElement parent node. |
771 | 771 | * @param SimpleXmlElement flush node. |
772 | 772 | */ |
773 | - protected function loadFlushOnCache($cacheModel,$parent,$node) |
|
773 | + protected function loadFlushOnCache($cacheModel, $parent, $node) |
|
774 | 774 | { |
775 | 775 | $id = $cacheModel->getID(); |
776 | - if(!isset($this->_FlushOnExecuteStatements[$id])) |
|
776 | + if (!isset($this->_FlushOnExecuteStatements[$id])) |
|
777 | 777 | $this->_FlushOnExecuteStatements[$id] = array(); |
778 | - foreach($node->attributes() as $name=>$value) |
|
778 | + foreach ($node->attributes() as $name=>$value) |
|
779 | 779 | { |
780 | - if(strtolower($name)==='statement') |
|
781 | - $this->_FlushOnExecuteStatements[$id][] = (string)$value; |
|
780 | + if (strtolower($name) === 'statement') |
|
781 | + $this->_FlushOnExecuteStatements[$id][] = (string) $value; |
|
782 | 782 | } |
783 | 783 | } |
784 | 784 | |
@@ -787,10 +787,10 @@ discard block |
||
787 | 787 | */ |
788 | 788 | protected function registerCacheTriggers() |
789 | 789 | { |
790 | - foreach($this->_FlushOnExecuteStatements as $cacheID => $statementIDs) |
|
790 | + foreach ($this->_FlushOnExecuteStatements as $cacheID => $statementIDs) |
|
791 | 791 | { |
792 | 792 | $cacheModel = $this->_manager->getCacheModel($cacheID); |
793 | - foreach($statementIDs as $statementID) |
|
793 | + foreach ($statementIDs as $statementID) |
|
794 | 794 | { |
795 | 795 | $statement = $this->_manager->getMappedStatement($statementID); |
796 | 796 | $cacheModel->registerTriggerStatement($statement); |
@@ -51,12 +51,13 @@ discard block |
||
51 | 51 | { |
52 | 52 | if(!in_array($name,$except)) |
53 | 53 | { |
54 | - if($obj->canSetProperty($name)) |
|
55 | - $obj->{$name} = (string)$value; |
|
56 | - else |
|
57 | - throw new TSqlMapConfigurationException( |
|
54 | + if($obj->canSetProperty($name)) { |
|
55 | + $obj->{$name} = (string)$value; |
|
56 | + } else { |
|
57 | + throw new TSqlMapConfigurationException( |
|
58 | 58 | 'sqlmap_invalid_property', $name, get_class($obj), |
59 | 59 | $node, $this->getConfigFile()); |
60 | + } |
|
60 | 61 | } |
61 | 62 | } |
62 | 63 | } |
@@ -71,13 +72,15 @@ discard block |
||
71 | 72 | { |
72 | 73 | $basedir = dirname($basefile); |
73 | 74 | $file = realpath($basedir.DIRECTORY_SEPARATOR.$resource); |
74 | - if(!is_string($file) || !is_file($file)) |
|
75 | - $file = realpath($resource); |
|
76 | - if(is_string($file) && is_file($file)) |
|
77 | - return $file; |
|
78 | - else |
|
79 | - throw new TSqlMapConfigurationException( |
|
75 | + if(!is_string($file) || !is_file($file)) { |
|
76 | + $file = realpath($resource); |
|
77 | + } |
|
78 | + if(is_string($file) && is_file($file)) { |
|
79 | + return $file; |
|
80 | + } else { |
|
81 | + throw new TSqlMapConfigurationException( |
|
80 | 82 | 'sqlmap_unable_to_find_resource', $resource); |
83 | + } |
|
81 | 84 | } |
82 | 85 | |
83 | 86 | /** |
@@ -87,12 +90,14 @@ discard block |
||
87 | 90 | */ |
88 | 91 | protected function loadXmlDocument($filename,TSqlMapXmlConfiguration $config) |
89 | 92 | { |
90 | - if( strpos($filename, '${') !== false) |
|
91 | - $filename = $config->replaceProperties($filename); |
|
93 | + if( strpos($filename, '${') !== false) { |
|
94 | + $filename = $config->replaceProperties($filename); |
|
95 | + } |
|
92 | 96 | |
93 | - if(!is_file($filename)) |
|
94 | - throw new TSqlMapConfigurationException( |
|
97 | + if(!is_file($filename)) { |
|
98 | + throw new TSqlMapConfigurationException( |
|
95 | 99 | 'sqlmap_unable_to_find_config', $filename); |
100 | + } |
|
96 | 101 | return simplexml_load_string($config->replaceProperties(file_get_contents($filename))); |
97 | 102 | } |
98 | 103 | |
@@ -109,8 +114,9 @@ discard block |
||
109 | 114 | foreach(array('id','ID','Id', 'iD') as $id) |
110 | 115 | { |
111 | 116 | $xpath = "//{$tag}[@{$id}='{$value}']"; |
112 | - foreach($document->xpath($xpath) as $node) |
|
113 | - return $node; |
|
117 | + foreach($document->xpath($xpath) as $node) { |
|
118 | + return $node; |
|
119 | + } |
|
114 | 120 | } |
115 | 121 | } |
116 | 122 | |
@@ -171,21 +177,25 @@ discard block |
||
171 | 177 | $this->_configFile=$filename; |
172 | 178 | $document = $this->loadXmlDocument($filename,$this); |
173 | 179 | |
174 | - foreach($document->xpath('//property') as $property) |
|
175 | - $this->loadGlobalProperty($property); |
|
180 | + foreach($document->xpath('//property') as $property) { |
|
181 | + $this->loadGlobalProperty($property); |
|
182 | + } |
|
176 | 183 | |
177 | - foreach($document->xpath('//typeHandler') as $handler) |
|
178 | - $this->loadTypeHandler($handler); |
|
184 | + foreach($document->xpath('//typeHandler') as $handler) { |
|
185 | + $this->loadTypeHandler($handler); |
|
186 | + } |
|
179 | 187 | |
180 | - foreach($document->xpath('//connection[last()]') as $conn) |
|
181 | - $this->loadDatabaseConnection($conn); |
|
188 | + foreach($document->xpath('//connection[last()]') as $conn) { |
|
189 | + $this->loadDatabaseConnection($conn); |
|
190 | + } |
|
182 | 191 | |
183 | 192 | //try to load configuration in the current config file. |
184 | 193 | $mapping = new TSqlMapXmlMappingConfiguration($this); |
185 | 194 | $mapping->configure($filename); |
186 | 195 | |
187 | - foreach($document->xpath('//sqlMap') as $sqlmap) |
|
188 | - $this->loadSqlMappingFiles($sqlmap); |
|
196 | + foreach($document->xpath('//sqlMap') as $sqlmap) { |
|
197 | + $this->loadSqlMappingFiles($sqlmap); |
|
198 | + } |
|
189 | 199 | |
190 | 200 | $this->resolveResultMapping(); |
191 | 201 | $this->attachCacheModels(); |
@@ -228,8 +238,9 @@ discard block |
||
228 | 238 | { |
229 | 239 | if(strlen($resource = (string)$node['resource']) > 0) |
230 | 240 | { |
231 | - if( strpos($resource, '${') !== false) |
|
232 | - $resource = $this->replaceProperties($resource); |
|
241 | + if( strpos($resource, '${') !== false) { |
|
242 | + $resource = $this->replaceProperties($resource); |
|
243 | + } |
|
233 | 244 | |
234 | 245 | $mapping = new TSqlMapXmlMappingConfiguration($this); |
235 | 246 | $filename = $this->getAbsoluteFilePath($this->_configFile, $resource); |
@@ -250,16 +261,18 @@ discard block |
||
250 | 261 | $resultMap = $item->getResultMapping(); |
251 | 262 | if(strlen($resultMap) > 0) |
252 | 263 | { |
253 | - if($maps->contains($resultMap)) |
|
254 | - $item->setNestedResultMap($maps[$resultMap]); |
|
255 | - else |
|
256 | - throw new TSqlMapConfigurationException( |
|
264 | + if($maps->contains($resultMap)) { |
|
265 | + $item->setNestedResultMap($maps[$resultMap]); |
|
266 | + } else { |
|
267 | + throw new TSqlMapConfigurationException( |
|
257 | 268 | 'sqlmap_unable_to_find_result_mapping', |
258 | 269 | $resultMap, $this->_configFile, $entry->getID()); |
270 | + } |
|
259 | 271 | } |
260 | 272 | } |
261 | - if($entry->getDiscriminator()!==null) |
|
262 | - $entry->getDiscriminator()->initialize($this->_manager); |
|
273 | + if($entry->getDiscriminator()!==null) { |
|
274 | + $entry->getDiscriminator()->initialize($this->_manager); |
|
275 | + } |
|
263 | 276 | } |
264 | 277 | } |
265 | 278 | |
@@ -286,8 +299,9 @@ discard block |
||
286 | 299 | */ |
287 | 300 | public function replaceProperties($string) |
288 | 301 | { |
289 | - foreach($this->_properties as $find => $replace) |
|
290 | - $string = str_replace('${'.$find.'}', $replace, $string); |
|
302 | + foreach($this->_properties as $find => $replace) { |
|
303 | + $string = str_replace('${'.$find.'}', $replace, $string); |
|
304 | + } |
|
291 | 305 | return $string; |
292 | 306 | } |
293 | 307 | } |
@@ -346,40 +360,51 @@ discard block |
||
346 | 360 | $this->_document=$document; |
347 | 361 | |
348 | 362 | static $bCacheDependencies; |
349 | - if($bCacheDependencies === null) |
|
350 | - $bCacheDependencies = Prado::getApplication()->getMode() !== TApplicationMode::Performance; |
|
363 | + if($bCacheDependencies === null) { |
|
364 | + $bCacheDependencies = Prado::getApplication()->getMode() !== TApplicationMode::Performance; |
|
365 | + } |
|
351 | 366 | |
352 | - if($bCacheDependencies) |
|
353 | - $this->_manager->getCacheDependencies() |
|
367 | + if($bCacheDependencies) { |
|
368 | + $this->_manager->getCacheDependencies() |
|
354 | 369 | ->getDependencies() |
355 | 370 | ->add(new TFileCacheDependency($filename)); |
371 | + } |
|
356 | 372 | |
357 | - foreach($document->xpath('//resultMap') as $node) |
|
358 | - $this->loadResultMap($node); |
|
373 | + foreach($document->xpath('//resultMap') as $node) { |
|
374 | + $this->loadResultMap($node); |
|
375 | + } |
|
359 | 376 | |
360 | - foreach($document->xpath('//parameterMap') as $node) |
|
361 | - $this->loadParameterMap($node); |
|
377 | + foreach($document->xpath('//parameterMap') as $node) { |
|
378 | + $this->loadParameterMap($node); |
|
379 | + } |
|
362 | 380 | |
363 | - foreach($document->xpath('//statement') as $node) |
|
364 | - $this->loadStatementTag($node); |
|
381 | + foreach($document->xpath('//statement') as $node) { |
|
382 | + $this->loadStatementTag($node); |
|
383 | + } |
|
365 | 384 | |
366 | - foreach($document->xpath('//select') as $node) |
|
367 | - $this->loadSelectTag($node); |
|
385 | + foreach($document->xpath('//select') as $node) { |
|
386 | + $this->loadSelectTag($node); |
|
387 | + } |
|
368 | 388 | |
369 | - foreach($document->xpath('//insert') as $node) |
|
370 | - $this->loadInsertTag($node); |
|
389 | + foreach($document->xpath('//insert') as $node) { |
|
390 | + $this->loadInsertTag($node); |
|
391 | + } |
|
371 | 392 | |
372 | - foreach($document->xpath('//update') as $node) |
|
373 | - $this->loadUpdateTag($node); |
|
393 | + foreach($document->xpath('//update') as $node) { |
|
394 | + $this->loadUpdateTag($node); |
|
395 | + } |
|
374 | 396 | |
375 | - foreach($document->xpath('//delete') as $node) |
|
376 | - $this->loadDeleteTag($node); |
|
397 | + foreach($document->xpath('//delete') as $node) { |
|
398 | + $this->loadDeleteTag($node); |
|
399 | + } |
|
377 | 400 | |
378 | - foreach($document->xpath('//procedure') as $node) |
|
379 | - $this->loadProcedureTag($node); |
|
401 | + foreach($document->xpath('//procedure') as $node) { |
|
402 | + $this->loadProcedureTag($node); |
|
403 | + } |
|
380 | 404 | |
381 | - foreach($document->xpath('//cacheModel') as $node) |
|
382 | - $this->loadCacheModel($node); |
|
405 | + foreach($document->xpath('//cacheModel') as $node) { |
|
406 | + $this->loadCacheModel($node); |
|
407 | + } |
|
383 | 408 | |
384 | 409 | $this->registerCacheTriggers(); |
385 | 410 | } |
@@ -398,21 +423,24 @@ discard block |
||
398 | 423 | if(!$this->_manager->getResultMaps()->contains($extendMap)) |
399 | 424 | { |
400 | 425 | $extendNode=$this->getElementByIdValue($this->_document,'resultMap',$extendMap); |
401 | - if($extendNode!==null) |
|
402 | - $this->loadResultMap($extendNode); |
|
426 | + if($extendNode!==null) { |
|
427 | + $this->loadResultMap($extendNode); |
|
428 | + } |
|
403 | 429 | } |
404 | 430 | |
405 | - if(!$this->_manager->getResultMaps()->contains($extendMap)) |
|
406 | - throw new TSqlMapConfigurationException( |
|
431 | + if(!$this->_manager->getResultMaps()->contains($extendMap)) { |
|
432 | + throw new TSqlMapConfigurationException( |
|
407 | 433 | 'sqlmap_unable_to_find_parent_result_map', $node, $this->_configFile, $extendMap); |
434 | + } |
|
408 | 435 | |
409 | 436 | $superMap = $this->_manager->getResultMap($extendMap); |
410 | 437 | $resultMap->getColumns()->mergeWith($superMap->getColumns()); |
411 | 438 | } |
412 | 439 | |
413 | 440 | //add the result map |
414 | - if(!$this->_manager->getResultMaps()->contains($resultMap->getID())) |
|
415 | - $this->_manager->addResultMap($resultMap); |
|
441 | + if(!$this->_manager->getResultMaps()->contains($resultMap->getID())) { |
|
442 | + $this->_manager->addResultMap($resultMap); |
|
443 | + } |
|
416 | 444 | } |
417 | 445 | |
418 | 446 | /** |
@@ -445,16 +473,18 @@ discard block |
||
445 | 473 | |
446 | 474 | foreach($node->xpath('subMap') as $subMapNode) |
447 | 475 | { |
448 | - if($discriminator===null) |
|
449 | - throw new TSqlMapConfigurationException( |
|
476 | + if($discriminator===null) { |
|
477 | + throw new TSqlMapConfigurationException( |
|
450 | 478 | 'sqlmap_undefined_discriminator', $node, $this->_configFile,$subMapNode); |
479 | + } |
|
451 | 480 | $subMap = new TSubMap; |
452 | 481 | $this->setObjectPropFromNode($subMap,$subMapNode); |
453 | 482 | $discriminator->addSubMap($subMap); |
454 | 483 | } |
455 | 484 | |
456 | - if($discriminator!==null) |
|
457 | - $resultMap->setDiscriminator($discriminator); |
|
485 | + if($discriminator!==null) { |
|
486 | + $resultMap->setDiscriminator($discriminator); |
|
487 | + } |
|
458 | 488 | |
459 | 489 | return $resultMap; |
460 | 490 | } |
@@ -473,17 +503,20 @@ discard block |
||
473 | 503 | if(!$this->_manager->getParameterMaps()->contains($extendMap)) |
474 | 504 | { |
475 | 505 | $extendNode=$this->getElementByIdValue($this->_document,'parameterMap',$extendMap); |
476 | - if($extendNode!==null) |
|
477 | - $this->loadParameterMap($extendNode); |
|
506 | + if($extendNode!==null) { |
|
507 | + $this->loadParameterMap($extendNode); |
|
508 | + } |
|
478 | 509 | } |
479 | 510 | |
480 | - if(!$this->_manager->getParameterMaps()->contains($extendMap)) |
|
481 | - throw new TSqlMapConfigurationException( |
|
511 | + if(!$this->_manager->getParameterMaps()->contains($extendMap)) { |
|
512 | + throw new TSqlMapConfigurationException( |
|
482 | 513 | 'sqlmap_unable_to_find_parent_parameter_map', $node, $this->_configFile,$extendMap); |
514 | + } |
|
483 | 515 | $superMap = $this->_manager->getParameterMap($extendMap); |
484 | 516 | $index = 0; |
485 | - foreach($superMap->getPropertyNames() as $propertyName) |
|
486 | - $parameterMap->insertProperty($index++,$superMap->getProperty($propertyName)); |
|
517 | + foreach($superMap->getPropertyNames() as $propertyName) { |
|
518 | + $parameterMap->insertProperty($index++,$superMap->getProperty($propertyName)); |
|
519 | + } |
|
487 | 520 | } |
488 | 521 | $this->_manager->addParameterMap($parameterMap); |
489 | 522 | } |
@@ -531,11 +564,12 @@ discard block |
||
531 | 564 | if(strlen($extend = $statement->getExtends()) > 0) |
532 | 565 | { |
533 | 566 | $superNode = $this->getElementByIdValue($this->_document,'*',$extend); |
534 | - if($superNode!==null) |
|
535 | - $commandText = (string)$superNode . $commandText; |
|
536 | - else |
|
537 | - throw new TSqlMapConfigurationException( |
|
567 | + if($superNode!==null) { |
|
568 | + $commandText = (string)$superNode . $commandText; |
|
569 | + } else { |
|
570 | + throw new TSqlMapConfigurationException( |
|
538 | 571 | 'sqlmap_unable_to_find_parent_sql', $extend, $this->_configFile,$node); |
572 | + } |
|
539 | 573 | } |
540 | 574 | //$commandText = $this->_xmlConfig->replaceProperties($commandText); |
541 | 575 | $statement->initialize($this->_manager); |
@@ -565,8 +599,9 @@ discard block |
||
565 | 599 | $map = new TParameterMap(); |
566 | 600 | $map->setID($statement->getID().'-InLineParameterMap'); |
567 | 601 | $statement->setInlineParameterMap($map); |
568 | - foreach($sqlText['parameters'] as $property) |
|
569 | - $map->addProperty($property); |
|
602 | + foreach($sqlText['parameters'] as $property) { |
|
603 | + $map->addProperty($property); |
|
604 | + } |
|
570 | 605 | } |
571 | 606 | $sqlStatement = $sqlText['sql']; |
572 | 607 | } |
@@ -591,9 +626,9 @@ discard block |
||
591 | 626 | { |
592 | 627 | $sql = new TSimpleDynamicSql($dynamics['parameters']); |
593 | 628 | $sqlStatement = $dynamics['sql']; |
629 | + } else { |
|
630 | + $sql = new TStaticSql(); |
|
594 | 631 | } |
595 | - else |
|
596 | - $sql = new TStaticSql(); |
|
597 | 632 | $sqlStatement=preg_replace('/'.self::SIMPLE_PLACEHOLDER.'/',self::SIMPLE_MARK,$sqlStatement); |
598 | 633 | $sql->buildPreparedStatement($statement, $sqlStatement); |
599 | 634 | $statement->setSqlText($sql); |
@@ -609,8 +644,9 @@ discard block |
||
609 | 644 | $this->setObjectPropFromNode($select,$node); |
610 | 645 | $this->processSqlStatement($select,$node); |
611 | 646 | $mappedStatement = new TMappedStatement($this->_manager, $select); |
612 | - if(strlen($select->getCacheModel()) > 0) |
|
613 | - $mappedStatement = new TCachingStatement($mappedStatement); |
|
647 | + if(strlen($select->getCacheModel()) > 0) { |
|
648 | + $mappedStatement = new TCachingStatement($mappedStatement); |
|
649 | + } |
|
614 | 650 | |
615 | 651 | $this->_manager->addMappedStatement($mappedStatement); |
616 | 652 | } |
@@ -636,8 +672,9 @@ discard block |
||
636 | 672 | { |
637 | 673 | $insert = new TSqlMapInsert; |
638 | 674 | $this->setObjectPropFromNode($insert,$node); |
639 | - if(isset($node->selectKey)) |
|
640 | - $this->loadSelectKeyTag($insert,$node->selectKey); |
|
675 | + if(isset($node->selectKey)) { |
|
676 | + $this->loadSelectKeyTag($insert,$node->selectKey); |
|
677 | + } |
|
641 | 678 | return $insert; |
642 | 679 | } |
643 | 680 | |
@@ -703,8 +740,9 @@ discard block |
||
703 | 740 | $properties = array('id','implementation'); |
704 | 741 | foreach($node->attributes() as $name=>$value) |
705 | 742 | { |
706 | - if(in_array(strtolower($name), $properties)) |
|
707 | - $cacheModel->{'set'.$name}((string)$value); |
|
743 | + if(in_array(strtolower($name), $properties)) { |
|
744 | + $cacheModel->{'set'.$name}((string)$value); |
|
745 | + } |
|
708 | 746 | } |
709 | 747 | $cache = Prado::createComponent($cacheModel->getImplementationClass(), $cacheModel); |
710 | 748 | $this->setObjectPropFromNode($cache,$node,$properties); |
@@ -712,12 +750,18 @@ discard block |
||
712 | 750 | foreach($node->xpath('property') as $propertyNode) |
713 | 751 | { |
714 | 752 | $name = $propertyNode->attributes()->name; |
715 | - if($name===null || $name==='') continue; |
|
753 | + if($name===null || $name==='') { |
|
754 | + continue; |
|
755 | + } |
|
716 | 756 | |
717 | 757 | $value = $propertyNode->attributes()->value; |
718 | - if($value===null || $value==='') continue; |
|
758 | + if($value===null || $value==='') { |
|
759 | + continue; |
|
760 | + } |
|
719 | 761 | |
720 | - if( !TPropertyAccess::has($cache, $name) ) continue; |
|
762 | + if( !TPropertyAccess::has($cache, $name) ) { |
|
763 | + continue; |
|
764 | + } |
|
721 | 765 | |
722 | 766 | TPropertyAccess::set($cache, $name, $value); |
723 | 767 | } |
@@ -726,8 +770,9 @@ discard block |
||
726 | 770 | |
727 | 771 | $cacheModel->initialize($cache); |
728 | 772 | $this->_manager->addCacheModel($cacheModel); |
729 | - foreach($node->xpath('flushOnExecute') as $flush) |
|
730 | - $this->loadFlushOnCache($cacheModel,$node,$flush); |
|
773 | + foreach($node->xpath('flushOnExecute') as $flush) { |
|
774 | + $this->loadFlushOnCache($cacheModel,$node,$flush); |
|
775 | + } |
|
731 | 776 | } |
732 | 777 | |
733 | 778 | /** |
@@ -738,7 +783,9 @@ discard block |
||
738 | 783 | protected function loadFlushInterval($cacheModel, $node) |
739 | 784 | { |
740 | 785 | $flushInterval = $node->xpath('flushInterval'); |
741 | - if($flushInterval === null || count($flushInterval) === 0) return; |
|
786 | + if($flushInterval === null || count($flushInterval) === 0) { |
|
787 | + return; |
|
788 | + } |
|
742 | 789 | $duration = 0; |
743 | 790 | foreach($flushInterval[0]->attributes() as $name=>$value) |
744 | 791 | { |
@@ -773,12 +820,14 @@ discard block |
||
773 | 820 | protected function loadFlushOnCache($cacheModel,$parent,$node) |
774 | 821 | { |
775 | 822 | $id = $cacheModel->getID(); |
776 | - if(!isset($this->_FlushOnExecuteStatements[$id])) |
|
777 | - $this->_FlushOnExecuteStatements[$id] = array(); |
|
823 | + if(!isset($this->_FlushOnExecuteStatements[$id])) { |
|
824 | + $this->_FlushOnExecuteStatements[$id] = array(); |
|
825 | + } |
|
778 | 826 | foreach($node->attributes() as $name=>$value) |
779 | 827 | { |
780 | - if(strtolower($name)==='statement') |
|
781 | - $this->_FlushOnExecuteStatements[$id][] = (string)$value; |
|
828 | + if(strtolower($name)==='statement') { |
|
829 | + $this->_FlushOnExecuteStatements[$id][] = (string)$value; |
|
830 | + } |
|
782 | 831 | } |
783 | 832 | } |
784 | 833 |
@@ -116,6 +116,7 @@ |
||
116 | 116 | /** |
117 | 117 | * @param object handler to method calls. |
118 | 118 | * @param object the object to by proxied. |
119 | + * @param TLazyLoadList $handler |
|
119 | 120 | */ |
120 | 121 | public function __construct($handler, $object) |
121 | 122 | { |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | { |
21 | 21 | private $_param; |
22 | 22 | private $_target; |
23 | - private $_propertyName=''; |
|
24 | - private $_statement=''; |
|
25 | - private $_loaded=false; |
|
23 | + private $_propertyName = ''; |
|
24 | + private $_statement = ''; |
|
25 | + private $_loaded = false; |
|
26 | 26 | private $_innerList; |
27 | 27 | private $_connection; |
28 | 28 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $this->_param = $param; |
40 | 40 | $this->_target = $target; |
41 | 41 | $this->_statement = $mappedStatement; |
42 | - $this->_connection=$mappedStatement->getManager()->getDbConnection(); |
|
42 | + $this->_connection = $mappedStatement->getManager()->getDbConnection(); |
|
43 | 43 | $this->_propertyName = $propertyName; |
44 | 44 | } |
45 | 45 | |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | { |
56 | 56 | $handler = new self($mappedStatement, $param, $target, $propertyName); |
57 | 57 | $statement = $mappedStatement->getStatement(); |
58 | - $registry=$mappedStatement->getManager()->getTypeHandlers(); |
|
58 | + $registry = $mappedStatement->getManager()->getTypeHandlers(); |
|
59 | 59 | $list = $statement->createInstanceOfListClass($registry); |
60 | - if(!is_object($list)) |
|
61 | - throw new TSqlMapExecutionException('sqlmap_invalid_lazyload_list',$statement->getID()); |
|
60 | + if (!is_object($list)) |
|
61 | + throw new TSqlMapExecutionException('sqlmap_invalid_lazyload_list', $statement->getID()); |
|
62 | 62 | return new TObjectProxy($handler, $list); |
63 | 63 | } |
64 | 64 | |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | */ |
78 | 78 | protected function fetchListData() |
79 | 79 | { |
80 | - if($this->_loaded == false) |
|
80 | + if ($this->_loaded == false) |
|
81 | 81 | { |
82 | - $this->_innerList = $this->_statement->executeQueryForList($this->_connection,$this->_param); |
|
82 | + $this->_innerList = $this->_statement->executeQueryForList($this->_connection, $this->_param); |
|
83 | 83 | $this->_loaded = true; |
84 | 84 | //replace the target property with real list |
85 | 85 | TPropertyAccess::set($this->_target, $this->_propertyName, $this->_innerList); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | public function hasMethod($method) |
95 | 95 | { |
96 | 96 | $this->fetchListData(); |
97 | - if(is_object($this->_innerList)) |
|
97 | + if (is_object($this->_innerList)) |
|
98 | 98 | return in_array($method, get_class_methods($this->_innerList)); |
99 | 99 | return false; |
100 | 100 | } |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | * @param array method arguments |
131 | 131 | * @return mixed method return value. |
132 | 132 | */ |
133 | - public function __call($method,$params) |
|
133 | + public function __call($method, $params) |
|
134 | 134 | { |
135 | - if($this->_handler->hasMethod($method)) |
|
135 | + if ($this->_handler->hasMethod($method)) |
|
136 | 136 | return $this->_handler->intercept($method, $params); |
137 | 137 | else |
138 | 138 | return call_user_func_array(array($this->_object, $method), $params); |
@@ -57,8 +57,9 @@ discard block |
||
57 | 57 | $statement = $mappedStatement->getStatement(); |
58 | 58 | $registry=$mappedStatement->getManager()->getTypeHandlers(); |
59 | 59 | $list = $statement->createInstanceOfListClass($registry); |
60 | - if(!is_object($list)) |
|
61 | - throw new TSqlMapExecutionException('sqlmap_invalid_lazyload_list',$statement->getID()); |
|
60 | + if(!is_object($list)) { |
|
61 | + throw new TSqlMapExecutionException('sqlmap_invalid_lazyload_list',$statement->getID()); |
|
62 | + } |
|
62 | 63 | return new TObjectProxy($handler, $list); |
63 | 64 | } |
64 | 65 | |
@@ -94,8 +95,9 @@ discard block |
||
94 | 95 | public function hasMethod($method) |
95 | 96 | { |
96 | 97 | $this->fetchListData(); |
97 | - if(is_object($this->_innerList)) |
|
98 | - return in_array($method, get_class_methods($this->_innerList)); |
|
98 | + if(is_object($this->_innerList)) { |
|
99 | + return in_array($method, get_class_methods($this->_innerList)); |
|
100 | + } |
|
99 | 101 | return false; |
100 | 102 | } |
101 | 103 | } |
@@ -132,10 +134,11 @@ discard block |
||
132 | 134 | */ |
133 | 135 | public function __call($method,$params) |
134 | 136 | { |
135 | - if($this->_handler->hasMethod($method)) |
|
136 | - return $this->_handler->intercept($method, $params); |
|
137 | - else |
|
138 | - return call_user_func_array(array($this->_object, $method), $params); |
|
137 | + if($this->_handler->hasMethod($method)) { |
|
138 | + return $this->_handler->intercept($method, $params); |
|
139 | + } else { |
|
140 | + return call_user_func_array(array($this->_object, $method), $params); |
|
141 | + } |
|
139 | 142 | } |
140 | 143 | } |
141 | 144 |
@@ -28,6 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * Create a new cache with limited cache size. |
30 | 30 | * @param TSqlMapCacheModel $cacheModel. |
31 | + * @param integer $cacheModel |
|
31 | 32 | */ |
32 | 33 | public function __construct($cacheModel=null) |
33 | 34 | { |
@@ -93,6 +94,7 @@ discard block |
||
93 | 94 | class TSqlMapFifoCache extends TSqlMapCache |
94 | 95 | { |
95 | 96 | /** |
97 | + * @param string $key |
|
96 | 98 | * @return mixed Gets a cached object with the specified key. |
97 | 99 | */ |
98 | 100 | public function get($key) |
@@ -105,6 +107,8 @@ discard block |
||
105 | 107 | * The expire and dependency parameters are ignored. |
106 | 108 | * @param string cache key |
107 | 109 | * @param mixed value to cache. |
110 | + * @param string $key |
|
111 | + * @param TComponent $value |
|
108 | 112 | */ |
109 | 113 | public function set($key, $value,$expire=0,$dependency=null) |
110 | 114 | { |
@@ -129,6 +133,7 @@ discard block |
||
129 | 133 | class TSqlMapLruCache extends TSqlMapCache |
130 | 134 | { |
131 | 135 | /** |
136 | + * @param string $key |
|
132 | 137 | * @return mixed Gets a cached object with the specified key. |
133 | 138 | */ |
134 | 139 | public function get($key) |
@@ -146,6 +151,8 @@ discard block |
||
146 | 151 | * The expire and dependency parameters are ignored. |
147 | 152 | * @param string the key identifying the value to be cached |
148 | 153 | * @param mixed the value to be cached |
154 | + * @param string $key |
|
155 | + * @param TComponent $value |
|
149 | 156 | */ |
150 | 157 | public function set($key, $value,$expire=0,$dependency=null) |
151 | 158 | { |
@@ -205,6 +212,9 @@ discard block |
||
205 | 212 | return $keyList; |
206 | 213 | } |
207 | 214 | |
215 | + /** |
|
216 | + * @param TList $keyList |
|
217 | + */ |
|
208 | 218 | protected function setKeyList($keyList) |
209 | 219 | { |
210 | 220 | $this->getCache()->set($this->getKeyListId(), $keyList); |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | * Create a new cache with limited cache size. |
30 | 30 | * @param TSqlMapCacheModel $cacheModel. |
31 | 31 | */ |
32 | - public function __construct($cacheModel=null) |
|
32 | + public function __construct($cacheModel = null) |
|
33 | 33 | { |
34 | 34 | $this->_cache = new TMap; |
35 | 35 | $this->_keyList = new TList; |
36 | - $this->_cacheModel=$cacheModel; |
|
36 | + $this->_cacheModel = $cacheModel; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function setCacheSize($value) |
44 | 44 | { |
45 | - $this->_cacheSize=TPropertyValue::ensureInteger($value,100); |
|
45 | + $this->_cacheSize = TPropertyValue::ensureInteger($value, 100); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | /** |
77 | 77 | * @throws TSqlMapException not implemented. |
78 | 78 | */ |
79 | - public function add($id,$value,$expire=0,$dependency=null) |
|
79 | + public function add($id, $value, $expire = 0, $dependency = null) |
|
80 | 80 | { |
81 | 81 | throw new TSqlMapException('sqlmap_use_set_to_store_cache'); |
82 | 82 | } |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | * @param string cache key |
107 | 107 | * @param mixed value to cache. |
108 | 108 | */ |
109 | - public function set($key, $value,$expire=0,$dependency=null) |
|
109 | + public function set($key, $value, $expire = 0, $dependency = null) |
|
110 | 110 | { |
111 | 111 | $this->_cache->add($key, $value); |
112 | 112 | $this->_keyList->add($key); |
113 | - if($this->_keyList->getCount() > $this->_cacheSize) |
|
113 | + if ($this->_keyList->getCount() > $this->_cacheSize) |
|
114 | 114 | { |
115 | 115 | $oldestKey = $this->_keyList->removeAt(0); |
116 | 116 | $this->_cache->remove($oldestKey); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function get($key) |
135 | 135 | { |
136 | - if($this->_keyList->contains($key)) |
|
136 | + if ($this->_keyList->contains($key)) |
|
137 | 137 | { |
138 | 138 | $this->_keyList->remove($key); |
139 | 139 | $this->_keyList->add($key); |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @param string the key identifying the value to be cached |
148 | 148 | * @param mixed the value to be cached |
149 | 149 | */ |
150 | - public function set($key, $value,$expire=0,$dependency=null) |
|
150 | + public function set($key, $value, $expire = 0, $dependency = null) |
|
151 | 151 | { |
152 | 152 | $this->_cache->add($key, $value); |
153 | 153 | $this->_keyList->add($key); |
154 | - if($this->_keyList->getCount() > $this->_cacheSize) |
|
154 | + if ($this->_keyList->getCount() > $this->_cacheSize) |
|
155 | 155 | { |
156 | 156 | $oldestKey = $this->_keyList->removeAt(0); |
157 | 157 | $this->_cache->remove($oldestKey); |
@@ -169,15 +169,15 @@ discard block |
||
169 | 169 | */ |
170 | 170 | class TSqlMapApplicationCache implements ICache |
171 | 171 | { |
172 | - protected $_cacheModel=null; |
|
172 | + protected $_cacheModel = null; |
|
173 | 173 | |
174 | 174 | /** |
175 | 175 | * Create a new cache with limited cache size. |
176 | 176 | * @param TSqlMapCacheModel $cacheModel. |
177 | 177 | */ |
178 | - public function __construct($cacheModel=null) |
|
178 | + public function __construct($cacheModel = null) |
|
179 | 179 | { |
180 | - $this->_cacheModel=$cacheModel; |
|
180 | + $this->_cacheModel = $cacheModel; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected function getKeyListId() |
188 | 188 | { |
189 | - $id='keyList'; |
|
189 | + $id = 'keyList'; |
|
190 | 190 | if ($this->_cacheModel instanceof TSqlMapCacheModel) |
191 | - $id.='_'.$this->_cacheModel->getId(); |
|
191 | + $id .= '_' . $this->_cacheModel->getId(); |
|
192 | 192 | return $id; |
193 | 193 | } |
194 | 194 | /** |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | */ |
198 | 198 | protected function getKeyList() |
199 | 199 | { |
200 | - if (($keyList=$this->getCache()->get($this->getKeyListId()))===false) |
|
200 | + if (($keyList = $this->getCache()->get($this->getKeyListId())) === false) |
|
201 | 201 | { |
202 | - $keyList=new TList(); |
|
202 | + $keyList = new TList(); |
|
203 | 203 | $this->getCache()->set($this->getKeyListId(), $keyList); |
204 | 204 | } |
205 | 205 | return $keyList; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function delete($key) |
217 | 217 | { |
218 | - $keyList=$this->getKeyList(); |
|
218 | + $keyList = $this->getKeyList(); |
|
219 | 219 | $keyList->remove($key); |
220 | 220 | $this->getCache()->delete($key); |
221 | 221 | $this->setKeyList($keyList); |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function flush() |
228 | 228 | { |
229 | - $keyList=$this->getKeyList(); |
|
230 | - $cache=$this->getCache(); |
|
229 | + $keyList = $this->getKeyList(); |
|
230 | + $cache = $this->getCache(); |
|
231 | 231 | foreach ($keyList as $key) |
232 | 232 | { |
233 | 233 | $cache->delete($key); |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | if ($result === false) |
246 | 246 | { |
247 | 247 | // if the key has not been found in cache (e.g expired), remove from keylist |
248 | - $keyList=$this->getKeyList(); |
|
248 | + $keyList = $this->getKeyList(); |
|
249 | 249 | if ($keyList->contains($key)) |
250 | 250 | { |
251 | 251 | $keyList->remove($key); |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | * @param string the key identifying the value to be cached |
261 | 261 | * @param mixed the value to be cached |
262 | 262 | */ |
263 | - public function set($key, $value,$expire=0,$dependency=null) |
|
263 | + public function set($key, $value, $expire = 0, $dependency = null) |
|
264 | 264 | { |
265 | - $this->getCache()->set($key, $value, $expire,$dependency); |
|
266 | - $keyList=$this->getKeyList(); |
|
265 | + $this->getCache()->set($key, $value, $expire, $dependency); |
|
266 | + $keyList = $this->getKeyList(); |
|
267 | 267 | if (!$keyList->contains($key)) |
268 | 268 | { |
269 | 269 | $keyList->add($key); |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | /** |
283 | 283 | * @throws TSqlMapException not implemented. |
284 | 284 | */ |
285 | - public function add($id,$value,$expire=0,$dependency=null) |
|
285 | + public function add($id, $value, $expire = 0, $dependency = null) |
|
286 | 286 | { |
287 | 287 | throw new TSqlMapException('sqlmap_use_set_to_store_cache'); |
288 | 288 | } |
@@ -187,8 +187,9 @@ |
||
187 | 187 | protected function getKeyListId() |
188 | 188 | { |
189 | 189 | $id='keyList'; |
190 | - if ($this->_cacheModel instanceof TSqlMapCacheModel) |
|
191 | - $id.='_'.$this->_cacheModel->getId(); |
|
190 | + if ($this->_cacheModel instanceof TSqlMapCacheModel) { |
|
191 | + $id.='_'.$this->_cacheModel->getId(); |
|
192 | + } |
|
192 | 193 | return $id; |
193 | 194 | } |
194 | 195 | /** |
@@ -40,6 +40,7 @@ discard block |
||
40 | 40 | * @param int page size |
41 | 41 | * @param mixed delegate for each data row retrieved. |
42 | 42 | * @param int number of page to fetch on initialization |
43 | + * @param integer $pageSize |
|
43 | 44 | */ |
44 | 45 | public function __construct(IMappedStatement $statement,$parameter, $pageSize, $delegate=null, $page=0) |
45 | 46 | { |
@@ -55,6 +56,8 @@ discard block |
||
55 | 56 | * @param mixed query parameters |
56 | 57 | * @param int page size. |
57 | 58 | * @param int number of page. |
59 | + * @param IMappedStatement $statement |
|
60 | + * @param integer $page |
|
58 | 61 | */ |
59 | 62 | protected function initialize($statement, $parameter, $pageSize, $page) |
60 | 63 | { |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | private $_parameter; |
32 | 32 | private $_prevPageList; |
33 | 33 | private $_nextPageList; |
34 | - private $_delegate=null; |
|
34 | + private $_delegate = null; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Create a new SqlMap paged list. |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | * @param mixed delegate for each data row retrieved. |
42 | 42 | * @param int number of page to fetch on initialization |
43 | 43 | */ |
44 | - public function __construct(IMappedStatement $statement,$parameter, $pageSize, $delegate=null, $page=0) |
|
44 | + public function __construct(IMappedStatement $statement, $parameter, $pageSize, $delegate = null, $page = 0) |
|
45 | 45 | { |
46 | 46 | parent::__construct(); |
47 | 47 | parent::setCustomPaging(true); |
48 | - $this->initialize($statement,$parameter, $pageSize, $page); |
|
49 | - $this->_delegate=$delegate; |
|
48 | + $this->initialize($statement, $parameter, $pageSize, $page); |
|
49 | + $this->_delegate = $delegate; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | { |
115 | 115 | $total = $data instanceof TList ? $data->getCount() : count($data); |
116 | 116 | $pageSize = $this->getPageSize(); |
117 | - if($total < 1) |
|
117 | + if ($total < 1) |
|
118 | 118 | { |
119 | 119 | $param->setData($data); |
120 | 120 | $this->_prevPageList = null; |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | return; |
123 | 123 | } |
124 | 124 | |
125 | - if($param->getNewPageIndex() < 1) |
|
125 | + if ($param->getNewPageIndex() < 1) |
|
126 | 126 | { |
127 | 127 | $this->_prevPageList = null; |
128 | - if($total <= $pageSize) |
|
128 | + if ($total <= $pageSize) |
|
129 | 129 | { |
130 | 130 | $param->setData($data); |
131 | 131 | $this->_nextPageList = null; |
@@ -133,18 +133,18 @@ discard block |
||
133 | 133 | else |
134 | 134 | { |
135 | 135 | $param->setData(array_slice($data, 0, $pageSize)); |
136 | - $this->_nextPageList = array_slice($data, $pageSize-1,$total); |
|
136 | + $this->_nextPageList = array_slice($data, $pageSize - 1, $total); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | else |
140 | 140 | { |
141 | - if($total <= $pageSize) |
|
141 | + if ($total <= $pageSize) |
|
142 | 142 | { |
143 | 143 | $this->_prevPageList = array_slice($data, 0, $total); |
144 | 144 | $param->setData(array()); |
145 | 145 | $this->_nextPageList = null; |
146 | 146 | } |
147 | - else if($total <= $pageSize*2) |
|
147 | + else if ($total <= $pageSize * 2) |
|
148 | 148 | { |
149 | 149 | $this->_prevPageList = array_slice($data, 0, $pageSize); |
150 | 150 | $param->setData(array_slice($data, $pageSize, $total)); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | { |
155 | 155 | $this->_prevPageList = array_slice($data, 0, $pageSize); |
156 | 156 | $param->setData(array_slice($data, $pageSize, $pageSize)); |
157 | - $this->_nextPageList = array_slice($data, $pageSize*2, $total-$pageSize*2); |
|
157 | + $this->_nextPageList = array_slice($data, $pageSize * 2, $total - $pageSize * 2); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | { |
169 | 169 | $index = $param->getNewPageIndex(); |
170 | 170 | $pageSize = $this->getPageSize(); |
171 | - return $index < 1 ? array($index, $pageSize*2) : array(($index-1)*$pageSize, $pageSize*3); |
|
171 | + return $index < 1 ? array($index, $pageSize * 2) : array(($index - 1) * $pageSize, $pageSize * 3); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function getIsNextPageAvailable() |
178 | 178 | { |
179 | - return $this->_nextPageList!==null; |
|
179 | + return $this->_nextPageList !== null; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function getIsPreviousPageAvailable() |
186 | 186 | { |
187 | - return $this->_prevPageList!==null; |
|
187 | + return $this->_prevPageList !== null; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function getIsLastPage() |
194 | 194 | { |
195 | - return ($this->_nextPageList===null) || $this->_nextPageList->getCount() < 1; |
|
195 | + return ($this->_nextPageList === null) || $this->_nextPageList->getCount() < 1; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -129,28 +129,24 @@ |
||
129 | 129 | { |
130 | 130 | $param->setData($data); |
131 | 131 | $this->_nextPageList = null; |
132 | - } |
|
133 | - else |
|
132 | + } else |
|
134 | 133 | { |
135 | 134 | $param->setData(array_slice($data, 0, $pageSize)); |
136 | 135 | $this->_nextPageList = array_slice($data, $pageSize-1,$total); |
137 | 136 | } |
138 | - } |
|
139 | - else |
|
137 | + } else |
|
140 | 138 | { |
141 | 139 | if($total <= $pageSize) |
142 | 140 | { |
143 | 141 | $this->_prevPageList = array_slice($data, 0, $total); |
144 | 142 | $param->setData(array()); |
145 | 143 | $this->_nextPageList = null; |
146 | - } |
|
147 | - else if($total <= $pageSize*2) |
|
144 | + } else if($total <= $pageSize*2) |
|
148 | 145 | { |
149 | 146 | $this->_prevPageList = array_slice($data, 0, $pageSize); |
150 | 147 | $param->setData(array_slice($data, $pageSize, $total)); |
151 | 148 | $this->_nextPageList = null; |
152 | - } |
|
153 | - else |
|
149 | + } else |
|
154 | 150 | { |
155 | 151 | $this->_prevPageList = array_slice($data, 0, $pageSize); |
156 | 152 | $param->setData(array_slice($data, $pageSize, $pageSize)); |
@@ -40,6 +40,7 @@ discard block |
||
40 | 40 | * @param mixed The object used to set the parameters in the SQL. |
41 | 41 | * @param string The property of the result object to be used as the key. |
42 | 42 | * @param string The property of the result object to be used as the value (or null) |
43 | + * @param TDbConnection $connection |
|
43 | 44 | * @return TMap A map of object containing the rows keyed by <tt>$keyProperty</tt>. |
44 | 45 | */ |
45 | 46 | public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null); |
@@ -50,6 +51,7 @@ discard block |
||
50 | 51 | * number of row effected. |
51 | 52 | * @param IDbConnection database connection to execute the query |
52 | 53 | * @param mixed The object used to set the parameters in the SQL. |
54 | + * @param TDbConnection $connection |
|
53 | 55 | * @return integer The number of row effected. |
54 | 56 | */ |
55 | 57 | public function executeUpdate($connection, $parameter); |
@@ -62,6 +64,7 @@ discard block |
||
62 | 64 | * @param TList A list to populate the result with. |
63 | 65 | * @param integer The number of rows to skip over. |
64 | 66 | * @param integer The maximum number of rows to return. |
67 | + * @param TDbConnection $connection |
|
65 | 68 | * @return TList A TList of result objects. |
66 | 69 | */ |
67 | 70 | public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1); |
@@ -73,6 +76,7 @@ discard block |
||
73 | 76 | * @param IDbConnection database connection to execute the query |
74 | 77 | * @param mixed The object used to set the parameters in the SQL. |
75 | 78 | * @param object The result object. |
79 | + * @param TDbConnection $connection |
|
76 | 80 | * @return object result. |
77 | 81 | */ |
78 | 82 | public function executeQueryForObject($connection,$parameter, $result=null); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string The property of the result object to be used as the value (or null) |
43 | 43 | * @return TMap A map of object containing the rows keyed by <tt>$keyProperty</tt>. |
44 | 44 | */ |
45 | - public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null); |
|
45 | + public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty = null); |
|
46 | 46 | |
47 | 47 | |
48 | 48 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param integer The maximum number of rows to return. |
65 | 65 | * @return TList A TList of result objects. |
66 | 66 | */ |
67 | - public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1); |
|
67 | + public function executeQueryForList($connection, $parameter, $result = null, $skip = -1, $max = -1); |
|
68 | 68 | |
69 | 69 | |
70 | 70 | /** |
@@ -75,6 +75,6 @@ discard block |
||
75 | 75 | * @param object The result object. |
76 | 76 | * @return object result. |
77 | 77 | */ |
78 | - public function executeQueryForObject($connection,$parameter, $result=null); |
|
78 | + public function executeQueryForObject($connection, $parameter, $result = null); |
|
79 | 79 | } |
80 | 80 |
@@ -97,6 +97,10 @@ |
||
97 | 97 | return $cacheKey->getHash(); |
98 | 98 | } |
99 | 99 | |
100 | + /** |
|
101 | + * @param integer $skip |
|
102 | + * @param integer $max |
|
103 | + */ |
|
100 | 104 | protected function createCommand($connection, $parameter, $skip=null, $max=null) |
101 | 105 | { |
102 | 106 | return $this->_mappedStatement->getCommand()->create($this->getManager(), |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | return $this->_mappedStatement->getManager(); |
41 | 41 | } |
42 | 42 | |
43 | - public function executeQueryForMap($connection, $parameter,$keyProperty, $valueProperty=null, $skip=-1, $max=-1,$delegate=null) |
|
43 | + public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty = null, $skip = -1, $max = -1, $delegate = null) |
|
44 | 44 | { |
45 | 45 | $sql = $this->createCommand($connection, $parameter, $skip, $max); |
46 | - $key = $this->getCacheKey(array(clone($sql), $keyProperty, $valueProperty,$skip, $max)); |
|
46 | + $key = $this->getCacheKey(array(clone($sql), $keyProperty, $valueProperty, $skip, $max)); |
|
47 | 47 | $map = $this->getStatement()->getCache()->get($key); |
48 | - if($map===null) |
|
48 | + if ($map === null) |
|
49 | 49 | { |
50 | 50 | $map = $this->_mappedStatement->runQueryForMap( |
51 | - $connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate); |
|
51 | + $connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate); |
|
52 | 52 | $this->getStatement()->getCache()->set($key, $map); |
53 | 53 | } |
54 | 54 | return $map; |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | return $this->executeInsert($connection, $parameter); |
65 | 65 | } |
66 | 66 | |
67 | - public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null) |
|
67 | + public function executeQueryForList($connection, $parameter, $result = null, $skip = -1, $max = -1, $delegate = null) |
|
68 | 68 | { |
69 | 69 | $sql = $this->createCommand($connection, $parameter, $skip, $max); |
70 | 70 | $key = $this->getCacheKey(array(clone($sql), $parameter, $skip, $max)); |
71 | 71 | $list = $this->getStatement()->getCache()->get($key); |
72 | - if($list===null) |
|
72 | + if ($list === null) |
|
73 | 73 | { |
74 | 74 | $list = $this->_mappedStatement->runQueryForList( |
75 | 75 | $connection, $parameter, $sql, $result, $delegate); |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | return $list; |
79 | 79 | } |
80 | 80 | |
81 | - public function executeQueryForObject($connection, $parameter, $result=null) |
|
81 | + public function executeQueryForObject($connection, $parameter, $result = null) |
|
82 | 82 | { |
83 | 83 | $sql = $this->createCommand($connection, $parameter); |
84 | 84 | $key = $this->getCacheKey(array(clone($sql), $parameter)); |
85 | 85 | $object = $this->getStatement()->getCache()->get($key); |
86 | - if($object===null) |
|
86 | + if ($object === null) |
|
87 | 87 | { |
88 | 88 | $object = $this->_mappedStatement->runQueryForObject($connection, $sql, $result); |
89 | 89 | $this->getStatement()->getCache()->set($key, $object); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | return $cacheKey->getHash(); |
98 | 98 | } |
99 | 99 | |
100 | - protected function createCommand($connection, $parameter, $skip=null, $max=null) |
|
100 | + protected function createCommand($connection, $parameter, $skip = null, $max = null) |
|
101 | 101 | { |
102 | 102 | return $this->_mappedStatement->getCommand()->create($this->getManager(), |
103 | 103 | $connection, $this->getStatement(), $parameter, $skip, $max); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | - * @return TSqlMapper The SqlMap used by this MappedStatement |
|
87 | + * @return TSqlMapManager The SqlMap used by this MappedStatement |
|
88 | 88 | */ |
89 | 89 | public function getManager() |
90 | 90 | { |
@@ -469,6 +469,7 @@ discard block |
||
469 | 469 | * @param IDbConnection database connection |
470 | 470 | * @param mixed insert statement parameter |
471 | 471 | * @param TSqlMapSelectKey select key statement |
472 | + * @param TSqlMapSelectKey $selectKey |
|
472 | 473 | * @return string last insert ID. |
473 | 474 | */ |
474 | 475 | protected function executeSelectKey($connection, $parameter, $selectKey) |
@@ -569,6 +570,7 @@ discard block |
||
569 | 570 | * @param string result object class name |
570 | 571 | * @param array a result set row retrieved from the database |
571 | 572 | * @param object the result object, will create if necessary. |
573 | + * @param string $resultClass |
|
572 | 574 | * @return object result object filled with data |
573 | 575 | */ |
574 | 576 | protected function fillResultClass($resultClass, $row, $resultObject) |
@@ -591,6 +593,7 @@ discard block |
||
591 | 593 | * Apply the result to a TList or an array. |
592 | 594 | * @param array a result set row retrieved from the database |
593 | 595 | * @param object result object, array or list |
596 | + * @param ArrayAccess $resultObject |
|
594 | 597 | * @return object result filled with data. |
595 | 598 | */ |
596 | 599 | protected function fillResultArrayList($row, $resultObject) |
@@ -633,6 +636,7 @@ discard block |
||
633 | 636 | * @param string result map name. |
634 | 637 | * @param array a result set row retrieved from the database |
635 | 638 | * @param object result object to fill, will create new instances if required. |
639 | + * @param string $parentGroup |
|
636 | 640 | * @return object result object filled with data. |
637 | 641 | */ |
638 | 642 | protected function fillResultMap($resultMapName, $row, $parentGroup=null, &$resultObject=null) |
@@ -772,6 +776,7 @@ discard block |
||
772 | 776 | * Converts the first array value to scalar value of given type. |
773 | 777 | * @param array list of results |
774 | 778 | * @param string scalar type. |
779 | + * @param string $type |
|
775 | 780 | * @return mixed scalar value. |
776 | 781 | */ |
777 | 782 | protected function getScalarResult($result, $type) |
@@ -961,6 +966,10 @@ discard block |
||
961 | 966 | public function setKeys($value){ $this->_keys = $value; } |
962 | 967 | |
963 | 968 | public function getMethod(){ return $this->_method; } |
969 | + |
|
970 | + /** |
|
971 | + * @param integer $value |
|
972 | + */ |
|
964 | 973 | public function setMethod($value){ $this->_method = $value; } |
965 | 974 | } |
966 | 975 | |
@@ -1003,6 +1012,7 @@ discard block |
||
1003 | 1012 | * @param string parent node id |
1004 | 1013 | * @param string new node id |
1005 | 1014 | * @param mixed node value |
1015 | + * @param string $node |
|
1006 | 1016 | */ |
1007 | 1017 | public function add($parent, $node, $object='') |
1008 | 1018 | { |
@@ -1168,6 +1178,9 @@ discard block |
||
1168 | 1178 | private $_parameterObject; |
1169 | 1179 | private $_list; |
1170 | 1180 | |
1181 | + /** |
|
1182 | + * @param ArrayAccess $list |
|
1183 | + */ |
|
1171 | 1184 | public function __construct($result, $parameter, &$list) |
1172 | 1185 | { |
1173 | 1186 | $this->_resultObject = $result; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @var TPostSelectBinding[] post select statement queue. |
41 | 41 | */ |
42 | - private $_selectQueue=array(); |
|
42 | + private $_selectQueue = array(); |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @var boolean true when data is mapped to a particular row. |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | */ |
162 | 162 | protected function executeSQLQueryLimit($connection, $command, $max, $skip) |
163 | 163 | { |
164 | - if($max>-1 || $skip > -1) |
|
164 | + if ($max > -1 || $skip > -1) |
|
165 | 165 | { |
166 | - $maxStr=$max>0?' LIMIT '.$max:''; |
|
167 | - $skipStr=$skip>0?' OFFSET '.$skip:''; |
|
168 | - $command->setText($command->getText().$maxStr.$skipStr); |
|
166 | + $maxStr = $max > 0 ? ' LIMIT ' . $max : ''; |
|
167 | + $skipStr = $skip > 0 ? ' OFFSET ' . $skip : ''; |
|
168 | + $command->setText($command->getText() . $maxStr . $skipStr); |
|
169 | 169 | } |
170 | 170 | $connection->setActive(true); |
171 | 171 | return $command->query(); |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | * @param callback row delegate handler |
200 | 200 | * @see executeQueryForList() |
201 | 201 | */ |
202 | - public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null) |
|
202 | + public function executeQueryForList($connection, $parameter, $result = null, $skip = -1, $max = -1, $delegate = null) |
|
203 | 203 | { |
204 | - $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter,$skip,$max); |
|
204 | + $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter, $skip, $max); |
|
205 | 205 | return $this->runQueryForList($connection, $parameter, $sql, $result, $delegate); |
206 | 206 | } |
207 | 207 | |
@@ -221,17 +221,16 @@ discard block |
||
221 | 221 | * @return array a list of result objects |
222 | 222 | * @see executeQueryForList() |
223 | 223 | */ |
224 | - public function runQueryForList($connection, $parameter, $sql, $result, $delegate=null) |
|
224 | + public function runQueryForList($connection, $parameter, $sql, $result, $delegate = null) |
|
225 | 225 | { |
226 | - $registry=$this->getManager()->getTypeHandlers(); |
|
227 | - $list = $result instanceof ArrayAccess ? $result : |
|
228 | - $this->_statement->createInstanceOfListClass($registry); |
|
226 | + $registry = $this->getManager()->getTypeHandlers(); |
|
227 | + $list = $result instanceof ArrayAccess ? $result : $this->_statement->createInstanceOfListClass($registry); |
|
229 | 228 | $connection->setActive(true); |
230 | 229 | $reader = $sql->query(); |
231 | 230 | //$reader = $this->executeSQLQueryLimit($connection, $sql, $max, $skip); |
232 | - if($delegate!==null) |
|
231 | + if ($delegate !== null) |
|
233 | 232 | { |
234 | - foreach($reader as $row) |
|
233 | + foreach ($reader as $row) |
|
235 | 234 | { |
236 | 235 | $obj = $this->applyResultMap($row); |
237 | 236 | $param = new TResultSetListItemParameter($obj, $parameter, $list); |
@@ -241,14 +240,14 @@ discard block |
||
241 | 240 | else |
242 | 241 | { |
243 | 242 | //var_dump($sql,$parameter); |
244 | - foreach($reader as $row) |
|
243 | + foreach ($reader as $row) |
|
245 | 244 | { |
246 | 245 | // var_dump($row); |
247 | 246 | $list[] = $this->applyResultMap($row); |
248 | 247 | } |
249 | 248 | } |
250 | 249 | |
251 | - if(!$this->_groupBy->isEmpty()) |
|
250 | + if (!$this->_groupBy->isEmpty()) |
|
252 | 251 | { |
253 | 252 | $list = $this->_groupBy->collect(); |
254 | 253 | $this->initialGroupByResults(); |
@@ -272,7 +271,7 @@ discard block |
||
272 | 271 | * @param callback row delegate handler |
273 | 272 | * @return array An array of object containing the rows keyed by keyProperty. |
274 | 273 | */ |
275 | - public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null, $skip=-1, $max=-1, $delegate=null) |
|
274 | + public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty = null, $skip = -1, $max = -1, $delegate = null) |
|
276 | 275 | { |
277 | 276 | $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter, $skip, $max); |
278 | 277 | return $this->runQueryForMap($connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate); |
@@ -296,21 +295,20 @@ discard block |
||
296 | 295 | * @return array An array of object containing the rows keyed by keyProperty. |
297 | 296 | * @see executeQueryForMap() |
298 | 297 | */ |
299 | - public function runQueryForMap($connection, $parameter, $command, $keyProperty, $valueProperty=null, $delegate=null) |
|
298 | + public function runQueryForMap($connection, $parameter, $command, $keyProperty, $valueProperty = null, $delegate = null) |
|
300 | 299 | { |
301 | 300 | $map = array(); |
302 | 301 | //$recordSet = $this->executeSQLQuery($connection, $sql); |
303 | 302 | $connection->setActive(true); |
304 | 303 | $reader = $command->query(); |
305 | - if($delegate!==null) |
|
304 | + if ($delegate !== null) |
|
306 | 305 | { |
307 | 306 | //while($row = $recordSet->fetchRow()) |
308 | - foreach($reader as $row) |
|
307 | + foreach ($reader as $row) |
|
309 | 308 | { |
310 | 309 | $obj = $this->applyResultMap($row); |
311 | 310 | $key = TPropertyAccess::get($obj, $keyProperty); |
312 | - $value = ($valueProperty===null) ? $obj : |
|
313 | - TPropertyAccess::get($obj, $valueProperty); |
|
311 | + $value = ($valueProperty === null) ? $obj : TPropertyAccess::get($obj, $valueProperty); |
|
314 | 312 | $param = new TResultSetMapItemParameter($key, $value, $parameter, $map); |
315 | 313 | $this->raiseRowDelegate($delegate, $param); |
316 | 314 | } |
@@ -318,12 +316,11 @@ discard block |
||
318 | 316 | else |
319 | 317 | { |
320 | 318 | //while($row = $recordSet->fetchRow()) |
321 | - foreach($reader as $row) |
|
319 | + foreach ($reader as $row) |
|
322 | 320 | { |
323 | 321 | $obj = $this->applyResultMap($row); |
324 | 322 | $key = TPropertyAccess::get($obj, $keyProperty); |
325 | - $map[$key] = ($valueProperty===null) ? $obj : |
|
326 | - TPropertyAccess::get($obj, $valueProperty); |
|
323 | + $map[$key] = ($valueProperty === null) ? $obj : TPropertyAccess::get($obj, $valueProperty); |
|
327 | 324 | } |
328 | 325 | } |
329 | 326 | $this->onExecuteQuery($command); |
@@ -338,24 +335,24 @@ discard block |
||
338 | 335 | */ |
339 | 336 | protected function raiseRowDelegate($handler, $param) |
340 | 337 | { |
341 | - if(is_string($handler)) |
|
338 | + if (is_string($handler)) |
|
342 | 339 | { |
343 | - call_user_func($handler,$this,$param); |
|
340 | + call_user_func($handler, $this, $param); |
|
344 | 341 | } |
345 | - else if(is_callable($handler,true)) |
|
342 | + else if (is_callable($handler, true)) |
|
346 | 343 | { |
347 | 344 | // an array: 0 - object, 1 - method name/path |
348 | - list($object,$method)=$handler; |
|
349 | - if(is_string($object)) // static method call |
|
350 | - call_user_func($handler,$this,$param); |
|
345 | + list($object, $method) = $handler; |
|
346 | + if (is_string($object)) // static method call |
|
347 | + call_user_func($handler, $this, $param); |
|
351 | 348 | else |
352 | 349 | { |
353 | - if(($pos=strrpos($method,'.'))!==false) |
|
350 | + if (($pos = strrpos($method, '.')) !== false) |
|
354 | 351 | { |
355 | - $object=$this->getSubProperty(substr($method,0,$pos)); |
|
356 | - $method=substr($method,$pos+1); |
|
352 | + $object = $this->getSubProperty(substr($method, 0, $pos)); |
|
353 | + $method = substr($method, $pos + 1); |
|
357 | 354 | } |
358 | - $object->$method($this,$param); |
|
355 | + $object->$method($this, $param); |
|
359 | 356 | } |
360 | 357 | } |
361 | 358 | else |
@@ -370,7 +367,7 @@ discard block |
||
370 | 367 | * @param mixed The result object. |
371 | 368 | * @return ${return} |
372 | 369 | */ |
373 | - public function executeQueryForObject($connection, $parameter, $result=null) |
|
370 | + public function executeQueryForObject($connection, $parameter, $result = null) |
|
374 | 371 | { |
375 | 372 | $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter); |
376 | 373 | return $this->runQueryForObject($connection, $sql, $result); |
@@ -393,10 +390,10 @@ discard block |
||
393 | 390 | { |
394 | 391 | $object = null; |
395 | 392 | $connection->setActive(true); |
396 | - foreach($command->query() as $row) |
|
393 | + foreach ($command->query() as $row) |
|
397 | 394 | $object = $this->applyResultMap($row, $result); |
398 | 395 | |
399 | - if(!$this->_groupBy->isEmpty()) |
|
396 | + if (!$this->_groupBy->isEmpty()) |
|
400 | 397 | { |
401 | 398 | $list = $this->_groupBy->collect(); |
402 | 399 | $this->initialGroupByResults(); |
@@ -424,7 +421,7 @@ discard block |
||
424 | 421 | // var_dump($command,$parameter); |
425 | 422 | $result = $command->execute(); |
426 | 423 | |
427 | - if($generatedKey===null) |
|
424 | + if ($generatedKey === null) |
|
428 | 425 | $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter); |
429 | 426 | |
430 | 427 | $this->executePostSelect($connection); |
@@ -440,10 +437,10 @@ discard block |
||
440 | 437 | */ |
441 | 438 | protected function getPreGeneratedSelectKey($connection, $parameter) |
442 | 439 | { |
443 | - if($this->_statement instanceof TSqlMapInsert) |
|
440 | + if ($this->_statement instanceof TSqlMapInsert) |
|
444 | 441 | { |
445 | 442 | $selectKey = $this->_statement->getSelectKey(); |
446 | - if(($selectKey!==null) && !$selectKey->getIsAfter()) |
|
443 | + if (($selectKey !== null) && !$selectKey->getIsAfter()) |
|
447 | 444 | return $this->executeSelectKey($connection, $parameter, $selectKey); |
448 | 445 | } |
449 | 446 | } |
@@ -456,10 +453,10 @@ discard block |
||
456 | 453 | */ |
457 | 454 | protected function getPostGeneratedSelectKey($connection, $parameter) |
458 | 455 | { |
459 | - if($this->_statement instanceof TSqlMapInsert) |
|
456 | + if ($this->_statement instanceof TSqlMapInsert) |
|
460 | 457 | { |
461 | 458 | $selectKey = $this->_statement->getSelectKey(); |
462 | - if(($selectKey!==null) && $selectKey->getIsAfter()) |
|
459 | + if (($selectKey !== null) && $selectKey->getIsAfter()) |
|
463 | 460 | return $this->executeSelectKey($connection, $parameter, $selectKey); |
464 | 461 | } |
465 | 462 | } |
@@ -476,7 +473,7 @@ discard block |
||
476 | 473 | $mappedStatement = $this->getManager()->getMappedStatement($selectKey->getID()); |
477 | 474 | $generatedKey = $mappedStatement->executeQueryForObject( |
478 | 475 | $connection, $parameter, null); |
479 | - if(strlen($prop = $selectKey->getProperty()) > 0) |
|
476 | + if (strlen($prop = $selectKey->getProperty()) > 0) |
|
480 | 477 | TPropertyAccess::set($parameter, $prop, $generatedKey); |
481 | 478 | return $generatedKey; |
482 | 479 | } |
@@ -490,7 +487,7 @@ discard block |
||
490 | 487 | */ |
491 | 488 | public function executeUpdate($connection, $parameter) |
492 | 489 | { |
493 | - $sql = $this->_command->create($this->getManager(),$connection, $this->_statement, $parameter); |
|
490 | + $sql = $this->_command->create($this->getManager(), $connection, $this->_statement, $parameter); |
|
494 | 491 | $affectedRows = $sql->execute(); |
495 | 492 | //$this->executeSQLQuery($connection, $sql); |
496 | 493 | $this->executePostSelect($connection); |
@@ -504,7 +501,7 @@ discard block |
||
504 | 501 | */ |
505 | 502 | protected function executePostSelect($connection) |
506 | 503 | { |
507 | - while(count($this->_selectQueue)) |
|
504 | + while (count($this->_selectQueue)) |
|
508 | 505 | { |
509 | 506 | $postSelect = array_shift($this->_selectQueue); |
510 | 507 | $method = $postSelect->getMethod(); |
@@ -513,15 +510,15 @@ discard block |
||
513 | 510 | $keys = $postSelect->getKeys(); |
514 | 511 | $resultObject = $postSelect->getResultObject(); |
515 | 512 | |
516 | - if($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY) |
|
513 | + if ($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY) |
|
517 | 514 | { |
518 | 515 | $values = $statement->executeQueryForList($connection, $keys, null); |
519 | 516 | |
520 | - if($method == self::QUERY_FOR_ARRAY) |
|
517 | + if ($method == self::QUERY_FOR_ARRAY) |
|
521 | 518 | $values = $values->toArray(); |
522 | 519 | TPropertyAccess::set($resultObject, $property, $values); |
523 | 520 | } |
524 | - else if($method == self::QUERY_FOR_OBJECT) |
|
521 | + else if ($method == self::QUERY_FOR_OBJECT) |
|
525 | 522 | { |
526 | 523 | $value = $statement->executeQueryForObject($connection, $keys, null); |
527 | 524 | TPropertyAccess::set($resultObject, $property, $value); |
@@ -544,23 +541,23 @@ discard block |
||
544 | 541 | * @param object the result object, will create if necessary. |
545 | 542 | * @return object the result filled with data, null if not filled. |
546 | 543 | */ |
547 | - protected function applyResultMap($row, &$resultObject=null) |
|
544 | + protected function applyResultMap($row, &$resultObject = null) |
|
548 | 545 | { |
549 | - if($row === false) return null; |
|
546 | + if ($row === false) return null; |
|
550 | 547 | |
551 | 548 | $resultMapName = $this->_statement->getResultMap(); |
552 | 549 | $resultClass = $this->_statement->getResultClass(); |
553 | 550 | |
554 | - $obj=null; |
|
555 | - if($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
551 | + $obj = null; |
|
552 | + if ($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
556 | 553 | $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject); |
557 | - else if(strlen($resultClass) > 0) |
|
554 | + else if (strlen($resultClass) > 0) |
|
558 | 555 | $obj = $this->fillResultClass($resultClass, $row, $resultObject); |
559 | 556 | else |
560 | 557 | $obj = $this->fillDefaultResultMap(null, $row, $resultObject); |
561 | - if(class_exists('TActiveRecord',false) && $obj instanceof TActiveRecord) |
|
558 | + if (class_exists('TActiveRecord', false) && $obj instanceof TActiveRecord) |
|
562 | 559 | //Create a new clean active record. |
563 | - $obj=TActiveRecord::createRecord(get_class($obj),$obj); |
|
560 | + $obj = TActiveRecord::createRecord(get_class($obj), $obj); |
|
564 | 561 | return $obj; |
565 | 562 | } |
566 | 563 | |
@@ -573,15 +570,15 @@ discard block |
||
573 | 570 | */ |
574 | 571 | protected function fillResultClass($resultClass, $row, $resultObject) |
575 | 572 | { |
576 | - if($resultObject===null) |
|
573 | + if ($resultObject === null) |
|
577 | 574 | { |
578 | 575 | $registry = $this->getManager()->getTypeHandlers(); |
579 | - $resultObject = $this->_statement->createInstanceOfResultClass($registry,$row); |
|
576 | + $resultObject = $this->_statement->createInstanceOfResultClass($registry, $row); |
|
580 | 577 | } |
581 | 578 | |
582 | - if($resultObject instanceOf ArrayAccess) |
|
579 | + if ($resultObject instanceOf ArrayAccess) |
|
583 | 580 | return $this->fillResultArrayList($row, $resultObject); |
584 | - else if(is_object($resultObject)) |
|
581 | + else if (is_object($resultObject)) |
|
585 | 582 | return $this->fillResultObjectProperty($row, $resultObject); |
586 | 583 | else |
587 | 584 | return $this->fillDefaultResultMap(null, $row, $resultObject); |
@@ -595,11 +592,11 @@ discard block |
||
595 | 592 | */ |
596 | 593 | protected function fillResultArrayList($row, $resultObject) |
597 | 594 | { |
598 | - if($resultObject instanceof TList) |
|
599 | - foreach($row as $v) |
|
595 | + if ($resultObject instanceof TList) |
|
596 | + foreach ($row as $v) |
|
600 | 597 | $resultObject[] = $v; |
601 | 598 | else |
602 | - foreach($row as $k => $v) |
|
599 | + foreach ($row as $k => $v) |
|
603 | 600 | $resultObject[$k] = $v; |
604 | 601 | return $resultObject; |
605 | 602 | } |
@@ -613,17 +610,17 @@ discard block |
||
613 | 610 | protected function fillResultObjectProperty($row, $resultObject) |
614 | 611 | { |
615 | 612 | $index = 0; |
616 | - $registry=$this->getManager()->getTypeHandlers(); |
|
617 | - foreach($row as $k=>$v) |
|
613 | + $registry = $this->getManager()->getTypeHandlers(); |
|
614 | + foreach ($row as $k=>$v) |
|
618 | 615 | { |
619 | 616 | $property = new TResultProperty; |
620 | - if(is_string($k) && strlen($k) > 0) |
|
617 | + if (is_string($k) && strlen($k) > 0) |
|
621 | 618 | $property->setColumn($k); |
622 | 619 | $property->setColumnIndex(++$index); |
623 | - $type = gettype(TPropertyAccess::get($resultObject,$k)); |
|
620 | + $type = gettype(TPropertyAccess::get($resultObject, $k)); |
|
624 | 621 | $property->setType($type); |
625 | - $value = $property->getPropertyValue($registry,$row); |
|
626 | - TPropertyAccess::set($resultObject, $k,$value); |
|
622 | + $value = $property->getPropertyValue($registry, $row); |
|
623 | + TPropertyAccess::set($resultObject, $k, $value); |
|
627 | 624 | } |
628 | 625 | return $resultObject; |
629 | 626 | } |
@@ -635,21 +632,21 @@ discard block |
||
635 | 632 | * @param object result object to fill, will create new instances if required. |
636 | 633 | * @return object result object filled with data. |
637 | 634 | */ |
638 | - protected function fillResultMap($resultMapName, $row, $parentGroup=null, &$resultObject=null) |
|
635 | + protected function fillResultMap($resultMapName, $row, $parentGroup = null, &$resultObject = null) |
|
639 | 636 | { |
640 | 637 | $resultMap = $this->getManager()->getResultMap($resultMapName); |
641 | 638 | $registry = $this->getManager()->getTypeHandlers(); |
642 | - $resultMap = $resultMap->resolveSubMap($registry,$row); |
|
639 | + $resultMap = $resultMap->resolveSubMap($registry, $row); |
|
643 | 640 | |
644 | - if($resultObject===null) |
|
641 | + if ($resultObject === null) |
|
645 | 642 | $resultObject = $resultMap->createInstanceOfResult($registry); |
646 | 643 | |
647 | - if(is_object($resultObject)) |
|
644 | + if (is_object($resultObject)) |
|
648 | 645 | { |
649 | - if(strlen($resultMap->getGroupBy()) > 0) |
|
646 | + if (strlen($resultMap->getGroupBy()) > 0) |
|
650 | 647 | return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
651 | 648 | else |
652 | - foreach($resultMap->getColumns() as $property) |
|
649 | + foreach ($resultMap->getColumns() as $property) |
|
653 | 650 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
654 | 651 | } |
655 | 652 | else |
@@ -671,26 +668,26 @@ discard block |
||
671 | 668 | { |
672 | 669 | $group = $this->getResultMapGroupKey($resultMap, $row); |
673 | 670 | |
674 | - if(empty($parent)) |
|
671 | + if (empty($parent)) |
|
675 | 672 | { |
676 | 673 | $rootObject = array('object'=>$resultObject, 'property' => null); |
677 | 674 | $this->_groupBy->add(null, $group, $rootObject); |
678 | 675 | } |
679 | 676 | |
680 | - foreach($resultMap->getColumns() as $property) |
|
677 | + foreach ($resultMap->getColumns() as $property) |
|
681 | 678 | { |
682 | 679 | //set properties. |
683 | 680 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
684 | 681 | $nested = $property->getResultMapping(); |
685 | 682 | |
686 | 683 | //nested property |
687 | - if($this->getManager()->getResultMaps()->contains($nested)) |
|
684 | + if ($this->getManager()->getResultMaps()->contains($nested)) |
|
688 | 685 | { |
689 | 686 | $nestedMap = $this->getManager()->getResultMap($nested); |
690 | 687 | $groupKey = $this->getResultMapGroupKey($nestedMap, $row); |
691 | 688 | |
692 | 689 | //add the node reference first |
693 | - if(empty($parent)) |
|
690 | + if (empty($parent)) |
|
694 | 691 | $this->_groupBy->add($group, $groupKey, ''); |
695 | 692 | |
696 | 693 | //get the nested result mapping value |
@@ -698,7 +695,7 @@ discard block |
||
698 | 695 | |
699 | 696 | //add it to the object tree graph |
700 | 697 | $groupObject = array('object'=>$value, 'property' => $property->getProperty()); |
701 | - if(empty($parent)) |
|
698 | + if (empty($parent)) |
|
702 | 699 | $this->_groupBy->add($group, $groupKey, $groupObject); |
703 | 700 | else |
704 | 701 | $this->_groupBy->add($parent, $groupKey, $groupObject); |
@@ -716,10 +713,10 @@ discard block |
||
716 | 713 | protected function getResultMapGroupKey($resultMap, $row) |
717 | 714 | { |
718 | 715 | $groupBy = $resultMap->getGroupBy(); |
719 | - if(isset($row[$groupBy])) |
|
720 | - return $resultMap->getID().$row[$groupBy]; |
|
716 | + if (isset($row[$groupBy])) |
|
717 | + return $resultMap->getID() . $row[$groupBy]; |
|
721 | 718 | else |
722 | - return $resultMap->getID().crc32(serialize($row)); |
|
719 | + return $resultMap->getID() . crc32(serialize($row)); |
|
723 | 720 | } |
724 | 721 | |
725 | 722 | /** |
@@ -732,16 +729,16 @@ discard block |
||
732 | 729 | */ |
733 | 730 | protected function fillDefaultResultMap($resultMap, $row, $resultObject) |
734 | 731 | { |
735 | - if($resultObject===null) |
|
736 | - $resultObject=''; |
|
732 | + if ($resultObject === null) |
|
733 | + $resultObject = ''; |
|
737 | 734 | |
738 | - if($resultMap!==null) |
|
735 | + if ($resultMap !== null) |
|
739 | 736 | $result = $this->fillArrayResultMap($resultMap, $row, $resultObject); |
740 | 737 | else |
741 | 738 | $result = $row; |
742 | 739 | |
743 | 740 | //if scalar result types |
744 | - if(count($result) == 1 && ($type = gettype($resultObject))!= 'array') |
|
741 | + if (count($result) == 1 && ($type = gettype($resultObject)) != 'array') |
|
745 | 742 | return $this->getScalarResult($result, $type); |
746 | 743 | else |
747 | 744 | return $result; |
@@ -757,13 +754,13 @@ discard block |
||
757 | 754 | protected function fillArrayResultMap($resultMap, $row, $resultObject) |
758 | 755 | { |
759 | 756 | $result = array(); |
760 | - $registry=$this->getManager()->getTypeHandlers(); |
|
761 | - foreach($resultMap->getColumns() as $column) |
|
757 | + $registry = $this->getManager()->getTypeHandlers(); |
|
758 | + foreach ($resultMap->getColumns() as $column) |
|
762 | 759 | { |
763 | - if(($column->getType()===null) |
|
764 | - && ($resultObject!==null) && !is_object($resultObject)) |
|
760 | + if (($column->getType() === null) |
|
761 | + && ($resultObject !== null) && !is_object($resultObject)) |
|
765 | 762 | $column->setType(gettype($resultObject)); |
766 | - $result[$column->getProperty()] = $column->getPropertyValue($registry,$row); |
|
763 | + $result[$column->getProperty()] = $column->getPropertyValue($registry, $row); |
|
767 | 764 | } |
768 | 765 | return $result; |
769 | 766 | } |
@@ -793,26 +790,26 @@ discard block |
||
793 | 790 | $select = $property->getSelect(); |
794 | 791 | $key = $property->getProperty(); |
795 | 792 | $nested = $property->getNestedResultMap(); |
796 | - $registry=$this->getManager()->getTypeHandlers(); |
|
797 | - if($key === '') |
|
793 | + $registry = $this->getManager()->getTypeHandlers(); |
|
794 | + if ($key === '') |
|
798 | 795 | { |
799 | - $resultObject = $property->getPropertyValue($registry,$row); |
|
796 | + $resultObject = $property->getPropertyValue($registry, $row); |
|
800 | 797 | } |
801 | - else if(strlen($select) == 0 && ($nested===null)) |
|
798 | + else if (strlen($select) == 0 && ($nested === null)) |
|
802 | 799 | { |
803 | - $value = $property->getPropertyValue($registry,$row); |
|
800 | + $value = $property->getPropertyValue($registry, $row); |
|
804 | 801 | |
805 | 802 | $this->_IsRowDataFound = $this->_IsRowDataFound || ($value != null); |
806 | - if(is_array($resultObject) || is_object($resultObject)) |
|
803 | + if (is_array($resultObject) || is_object($resultObject)) |
|
807 | 804 | TPropertyAccess::set($resultObject, $key, $value); |
808 | 805 | else |
809 | 806 | $resultObject = $value; |
810 | 807 | } |
811 | - else if($nested!==null) |
|
808 | + else if ($nested !== null) |
|
812 | 809 | { |
813 | - if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
|
810 | + if ($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
|
814 | 811 | { |
815 | - if(strlen($resultMap->getGroupBy()) <= 0) |
|
812 | + if (strlen($resultMap->getGroupBy()) <= 0) |
|
816 | 813 | throw new TSqlMapExecutionException( |
817 | 814 | 'sqlmap_non_groupby_array_list_type', $resultMap->getID(), |
818 | 815 | get_class($resultObject), $key); |
@@ -820,7 +817,7 @@ discard block |
||
820 | 817 | else |
821 | 818 | { |
822 | 819 | $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers()); |
823 | - if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
820 | + if ($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
824 | 821 | $obj = null; |
825 | 822 | TPropertyAccess::set($resultObject, $key, $obj); |
826 | 823 | } |
@@ -849,10 +846,10 @@ discard block |
||
849 | 846 | $postSelect->setResultProperty($property); |
850 | 847 | $postSelect->setKeys($key); |
851 | 848 | |
852 | - if($property->instanceOfListType($resultObject)) |
|
849 | + if ($property->instanceOfListType($resultObject)) |
|
853 | 850 | { |
854 | 851 | $values = null; |
855 | - if($property->getLazyLoad()) |
|
852 | + if ($property->getLazyLoad()) |
|
856 | 853 | { |
857 | 854 | $values = TLazyLoadList::newInstance($statement, $key, |
858 | 855 | $resultObject, $property->getProperty()); |
@@ -861,12 +858,12 @@ discard block |
||
861 | 858 | else |
862 | 859 | $postSelect->setMethod(self::QUERY_FOR_LIST); |
863 | 860 | } |
864 | - else if($property->instanceOfArrayType($resultObject)) |
|
861 | + else if ($property->instanceOfArrayType($resultObject)) |
|
865 | 862 | $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
866 | 863 | else |
867 | 864 | $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
868 | 865 | |
869 | - if(!$property->getLazyLoad()) |
|
866 | + if (!$property->getLazyLoad()) |
|
870 | 867 | $this->_selectQueue[] = $postSelect; |
871 | 868 | } |
872 | 869 | |
@@ -877,23 +874,23 @@ discard block |
||
877 | 874 | * @param array current row data. |
878 | 875 | * @return array list of primary key values. |
879 | 876 | */ |
880 | - protected function getPostSelectKeys($resultMap, $property,$row) |
|
877 | + protected function getPostSelectKeys($resultMap, $property, $row) |
|
881 | 878 | { |
882 | 879 | $value = $property->getColumn(); |
883 | - if(is_int(strpos($value.',',0)) || is_int(strpos($value, '=',0))) |
|
880 | + if (is_int(strpos($value . ',', 0)) || is_int(strpos($value, '=', 0))) |
|
884 | 881 | { |
885 | 882 | $keys = array(); |
886 | - foreach(explode(',', $value) as $entry) |
|
883 | + foreach (explode(',', $value) as $entry) |
|
887 | 884 | { |
888 | - $pair =explode('=',$entry); |
|
885 | + $pair = explode('=', $entry); |
|
889 | 886 | $keys[trim($pair[0])] = $row[trim($pair[1])]; |
890 | 887 | } |
891 | 888 | return $keys; |
892 | 889 | } |
893 | 890 | else |
894 | 891 | { |
895 | - $registry=$this->getManager()->getTypeHandlers(); |
|
896 | - return $property->getPropertyValue($registry,$row); |
|
892 | + $registry = $this->getManager()->getTypeHandlers(); |
|
893 | + return $property->getPropertyValue($registry, $row); |
|
897 | 894 | } |
898 | 895 | } |
899 | 896 | |
@@ -907,7 +904,7 @@ discard block |
||
907 | 904 | protected function fillPropertyWithResultMap($resultMap, $row, &$resultObject) |
908 | 905 | { |
909 | 906 | $dataFound = false; |
910 | - foreach($resultMap->getColumns() as $property) |
|
907 | + foreach ($resultMap->getColumns() as $property) |
|
911 | 908 | { |
912 | 909 | $this->_IsRowDataFound = false; |
913 | 910 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
@@ -929,7 +926,7 @@ discard block |
||
929 | 926 | if (!count($this->_selectQueue)) $exprops[] = "\0$cn\0_selectQueue"; |
930 | 927 | if (is_null($this->_groupBy)) $exprops[] = "\0$cn\0_groupBy"; |
931 | 928 | if (!$this->_IsRowDataFound) $exprops[] = "\0$cn\0_IsRowDataFound"; |
932 | - return array_diff(parent::__sleep(),$exprops); |
|
929 | + return array_diff(parent::__sleep(), $exprops); |
|
933 | 930 | } |
934 | 931 | } |
935 | 932 | |
@@ -942,26 +939,26 @@ discard block |
||
942 | 939 | */ |
943 | 940 | class TPostSelectBinding |
944 | 941 | { |
945 | - private $_statement=null; |
|
946 | - private $_property=null; |
|
947 | - private $_resultObject=null; |
|
948 | - private $_keys=null; |
|
949 | - private $_method=TMappedStatement::QUERY_FOR_LIST; |
|
942 | + private $_statement = null; |
|
943 | + private $_property = null; |
|
944 | + private $_resultObject = null; |
|
945 | + private $_keys = null; |
|
946 | + private $_method = TMappedStatement::QUERY_FOR_LIST; |
|
950 | 947 | |
951 | - public function getStatement(){ return $this->_statement; } |
|
952 | - public function setStatement($value){ $this->_statement = $value; } |
|
948 | + public function getStatement() { return $this->_statement; } |
|
949 | + public function setStatement($value) { $this->_statement = $value; } |
|
953 | 950 | |
954 | - public function getResultProperty(){ return $this->_property; } |
|
955 | - public function setResultProperty($value){ $this->_property = $value; } |
|
951 | + public function getResultProperty() { return $this->_property; } |
|
952 | + public function setResultProperty($value) { $this->_property = $value; } |
|
956 | 953 | |
957 | - public function getResultObject(){ return $this->_resultObject; } |
|
958 | - public function setResultObject($value){ $this->_resultObject = $value; } |
|
954 | + public function getResultObject() { return $this->_resultObject; } |
|
955 | + public function setResultObject($value) { $this->_resultObject = $value; } |
|
959 | 956 | |
960 | - public function getKeys(){ return $this->_keys; } |
|
961 | - public function setKeys($value){ $this->_keys = $value; } |
|
957 | + public function getKeys() { return $this->_keys; } |
|
958 | + public function setKeys($value) { $this->_keys = $value; } |
|
962 | 959 | |
963 | - public function getMethod(){ return $this->_method; } |
|
964 | - public function setMethod($value){ $this->_method = $value; } |
|
960 | + public function getMethod() { return $this->_method; } |
|
961 | + public function setMethod($value) { $this->_method = $value; } |
|
965 | 962 | } |
966 | 963 | |
967 | 964 | /** |
@@ -1004,26 +1001,26 @@ discard block |
||
1004 | 1001 | * @param string new node id |
1005 | 1002 | * @param mixed node value |
1006 | 1003 | */ |
1007 | - public function add($parent, $node, $object='') |
|
1004 | + public function add($parent, $node, $object = '') |
|
1008 | 1005 | { |
1009 | - if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null) |
|
1010 | - && isset($this->_entries[$node]) && ($this->_entries[$node]!==null)) |
|
1006 | + if (isset($this->_entries[$parent]) && ($this->_entries[$parent] !== null) |
|
1007 | + && isset($this->_entries[$node]) && ($this->_entries[$node] !== null)) |
|
1011 | 1008 | { |
1012 | 1009 | $this->_entries[$node] = $object; |
1013 | 1010 | return; |
1014 | 1011 | } |
1015 | 1012 | $this->_entries[$node] = $object; |
1016 | - if(empty($parent)) |
|
1013 | + if (empty($parent)) |
|
1017 | 1014 | { |
1018 | - if(isset($this->_entries[$node])) |
|
1015 | + if (isset($this->_entries[$node])) |
|
1019 | 1016 | return; |
1020 | 1017 | $this->_tree[$node] = array(); |
1021 | 1018 | } |
1022 | 1019 | $found = $this->addNode($this->_tree, $parent, $node); |
1023 | - if(!$found && !empty($parent)) |
|
1020 | + if (!$found && !empty($parent)) |
|
1024 | 1021 | { |
1025 | 1022 | $this->_tree[$parent] = array(); |
1026 | - if(!isset($this->_entries[$parent]) || $object !== '') |
|
1023 | + if (!isset($this->_entries[$parent]) || $object !== '') |
|
1027 | 1024 | $this->_entries[$parent] = $object; |
1028 | 1025 | $this->addNode($this->_tree, $parent, $node); |
1029 | 1026 | } |
@@ -1040,11 +1037,11 @@ discard block |
||
1040 | 1037 | { |
1041 | 1038 | $found = false; |
1042 | 1039 | reset($childs); |
1043 | - for($i = 0, $k = count($childs); $i < $k; $i++) |
|
1040 | + for ($i = 0, $k = count($childs); $i < $k; $i++) |
|
1044 | 1041 | { |
1045 | 1042 | $key = key($childs); |
1046 | 1043 | next($childs); |
1047 | - if($key == $parent) |
|
1044 | + if ($key == $parent) |
|
1048 | 1045 | { |
1049 | 1046 | $found = true; |
1050 | 1047 | $childs[$key][$node] = array(); |
@@ -1062,7 +1059,7 @@ discard block |
||
1062 | 1059 | */ |
1063 | 1060 | public function collect() |
1064 | 1061 | { |
1065 | - while(count($this->_tree) > 0) |
|
1062 | + while (count($this->_tree) > 0) |
|
1066 | 1063 | $this->collectChildren(null, $this->_tree); |
1067 | 1064 | return $this->getCollection(); |
1068 | 1065 | } |
@@ -1074,8 +1071,8 @@ discard block |
||
1074 | 1071 | protected function hasChildren(&$nodes) |
1075 | 1072 | { |
1076 | 1073 | $hasChildren = false; |
1077 | - foreach($nodes as $node) |
|
1078 | - if(count($node) != 0) |
|
1074 | + foreach ($nodes as $node) |
|
1075 | + if (count($node) != 0) |
|
1079 | 1076 | return true; |
1080 | 1077 | return $hasChildren; |
1081 | 1078 | } |
@@ -1089,10 +1086,10 @@ discard block |
||
1089 | 1086 | { |
1090 | 1087 | $noChildren = !$this->hasChildren($nodes); |
1091 | 1088 | $childs = array(); |
1092 | - for(reset($nodes); $key = key($nodes);) |
|
1089 | + for (reset($nodes); $key = key($nodes);) |
|
1093 | 1090 | { |
1094 | 1091 | next($nodes); |
1095 | - if($noChildren) |
|
1092 | + if ($noChildren) |
|
1096 | 1093 | { |
1097 | 1094 | $childs[] = $key; |
1098 | 1095 | unset($nodes[$key]); |
@@ -1100,7 +1097,7 @@ discard block |
||
1100 | 1097 | else |
1101 | 1098 | $this->collectChildren($key, $nodes[$key]); |
1102 | 1099 | } |
1103 | - if(count($childs) > 0) |
|
1100 | + if (count($childs) > 0) |
|
1104 | 1101 | $this->onChildNodesVisited($parent, $childs); |
1105 | 1102 | } |
1106 | 1103 | |
@@ -1111,7 +1108,7 @@ discard block |
||
1111 | 1108 | */ |
1112 | 1109 | protected function onChildNodesVisited($parent, $nodes) |
1113 | 1110 | { |
1114 | - if(empty($parent) || empty($this->_entries[$parent])) |
|
1111 | + if (empty($parent) || empty($this->_entries[$parent])) |
|
1115 | 1112 | return; |
1116 | 1113 | |
1117 | 1114 | $parentObject = $this->_entries[$parent]['object']; |
@@ -1119,21 +1116,21 @@ discard block |
||
1119 | 1116 | |
1120 | 1117 | $list = TPropertyAccess::get($parentObject, $property); |
1121 | 1118 | |
1122 | - foreach($nodes as $node) |
|
1119 | + foreach ($nodes as $node) |
|
1123 | 1120 | { |
1124 | - if($list instanceof TList) |
|
1121 | + if ($list instanceof TList) |
|
1125 | 1122 | $parentObject->{$property}[] = $this->_entries[$node]['object']; |
1126 | - else if(is_array($list)) |
|
1123 | + else if (is_array($list)) |
|
1127 | 1124 | $list[] = $this->_entries[$node]['object']; |
1128 | 1125 | else |
1129 | 1126 | throw new TSqlMapExecutionException( |
1130 | 1127 | 'sqlmap_property_must_be_list'); |
1131 | 1128 | } |
1132 | 1129 | |
1133 | - if(is_array($list)) |
|
1130 | + if (is_array($list)) |
|
1134 | 1131 | TPropertyAccess::set($parentObject, $property, $list); |
1135 | 1132 | |
1136 | - if($this->_entries[$parent]['property'] === null) |
|
1133 | + if ($this->_entries[$parent]['property'] === null) |
|
1137 | 1134 | $this->_list[] = $parentObject; |
1138 | 1135 | } |
1139 | 1136 | |
@@ -1151,7 +1148,7 @@ discard block |
||
1151 | 1148 | if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree"; |
1152 | 1149 | if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries"; |
1153 | 1150 | if (!count($this->_list)) $exprops[] = "\0$cn\0_list"; |
1154 | - return array_diff(parent::__sleep(),$exprops); |
|
1151 | + return array_diff(parent::__sleep(), $exprops); |
|
1155 | 1152 | } |
1156 | 1153 | } |
1157 | 1154 |
@@ -237,8 +237,7 @@ discard block |
||
237 | 237 | $param = new TResultSetListItemParameter($obj, $parameter, $list); |
238 | 238 | $this->raiseRowDelegate($delegate, $param); |
239 | 239 | } |
240 | - } |
|
241 | - else |
|
240 | + } else |
|
242 | 241 | { |
243 | 242 | //var_dump($sql,$parameter); |
244 | 243 | foreach($reader as $row) |
@@ -314,8 +313,7 @@ discard block |
||
314 | 313 | $param = new TResultSetMapItemParameter($key, $value, $parameter, $map); |
315 | 314 | $this->raiseRowDelegate($delegate, $param); |
316 | 315 | } |
317 | - } |
|
318 | - else |
|
316 | + } else |
|
319 | 317 | { |
320 | 318 | //while($row = $recordSet->fetchRow()) |
321 | 319 | foreach($reader as $row) |
@@ -341,14 +339,14 @@ discard block |
||
341 | 339 | if(is_string($handler)) |
342 | 340 | { |
343 | 341 | call_user_func($handler,$this,$param); |
344 | - } |
|
345 | - else if(is_callable($handler,true)) |
|
342 | + } else if(is_callable($handler,true)) |
|
346 | 343 | { |
347 | 344 | // an array: 0 - object, 1 - method name/path |
348 | 345 | list($object,$method)=$handler; |
349 | - if(is_string($object)) // static method call |
|
346 | + if(is_string($object)) { |
|
347 | + // static method call |
|
350 | 348 | call_user_func($handler,$this,$param); |
351 | - else |
|
349 | + } else |
|
352 | 350 | { |
353 | 351 | if(($pos=strrpos($method,'.'))!==false) |
354 | 352 | { |
@@ -357,9 +355,9 @@ discard block |
||
357 | 355 | } |
358 | 356 | $object->$method($this,$param); |
359 | 357 | } |
358 | + } else { |
|
359 | + throw new TInvalidDataValueException('sqlmap_invalid_delegate', $this->getID(), $handler); |
|
360 | 360 | } |
361 | - else |
|
362 | - throw new TInvalidDataValueException('sqlmap_invalid_delegate', $this->getID(), $handler); |
|
363 | 361 | } |
364 | 362 | |
365 | 363 | /** |
@@ -393,8 +391,9 @@ discard block |
||
393 | 391 | { |
394 | 392 | $object = null; |
395 | 393 | $connection->setActive(true); |
396 | - foreach($command->query() as $row) |
|
397 | - $object = $this->applyResultMap($row, $result); |
|
394 | + foreach($command->query() as $row) { |
|
395 | + $object = $this->applyResultMap($row, $result); |
|
396 | + } |
|
398 | 397 | |
399 | 398 | if(!$this->_groupBy->isEmpty()) |
400 | 399 | { |
@@ -424,8 +423,9 @@ discard block |
||
424 | 423 | // var_dump($command,$parameter); |
425 | 424 | $result = $command->execute(); |
426 | 425 | |
427 | - if($generatedKey===null) |
|
428 | - $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter); |
|
426 | + if($generatedKey===null) { |
|
427 | + $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter); |
|
428 | + } |
|
429 | 429 | |
430 | 430 | $this->executePostSelect($connection); |
431 | 431 | $this->onExecuteQuery($command); |
@@ -443,8 +443,9 @@ discard block |
||
443 | 443 | if($this->_statement instanceof TSqlMapInsert) |
444 | 444 | { |
445 | 445 | $selectKey = $this->_statement->getSelectKey(); |
446 | - if(($selectKey!==null) && !$selectKey->getIsAfter()) |
|
447 | - return $this->executeSelectKey($connection, $parameter, $selectKey); |
|
446 | + if(($selectKey!==null) && !$selectKey->getIsAfter()) { |
|
447 | + return $this->executeSelectKey($connection, $parameter, $selectKey); |
|
448 | + } |
|
448 | 449 | } |
449 | 450 | } |
450 | 451 | |
@@ -459,8 +460,9 @@ discard block |
||
459 | 460 | if($this->_statement instanceof TSqlMapInsert) |
460 | 461 | { |
461 | 462 | $selectKey = $this->_statement->getSelectKey(); |
462 | - if(($selectKey!==null) && $selectKey->getIsAfter()) |
|
463 | - return $this->executeSelectKey($connection, $parameter, $selectKey); |
|
463 | + if(($selectKey!==null) && $selectKey->getIsAfter()) { |
|
464 | + return $this->executeSelectKey($connection, $parameter, $selectKey); |
|
465 | + } |
|
464 | 466 | } |
465 | 467 | } |
466 | 468 | |
@@ -476,8 +478,9 @@ discard block |
||
476 | 478 | $mappedStatement = $this->getManager()->getMappedStatement($selectKey->getID()); |
477 | 479 | $generatedKey = $mappedStatement->executeQueryForObject( |
478 | 480 | $connection, $parameter, null); |
479 | - if(strlen($prop = $selectKey->getProperty()) > 0) |
|
480 | - TPropertyAccess::set($parameter, $prop, $generatedKey); |
|
481 | + if(strlen($prop = $selectKey->getProperty()) > 0) { |
|
482 | + TPropertyAccess::set($parameter, $prop, $generatedKey); |
|
483 | + } |
|
481 | 484 | return $generatedKey; |
482 | 485 | } |
483 | 486 | |
@@ -517,11 +520,11 @@ discard block |
||
517 | 520 | { |
518 | 521 | $values = $statement->executeQueryForList($connection, $keys, null); |
519 | 522 | |
520 | - if($method == self::QUERY_FOR_ARRAY) |
|
521 | - $values = $values->toArray(); |
|
523 | + if($method == self::QUERY_FOR_ARRAY) { |
|
524 | + $values = $values->toArray(); |
|
525 | + } |
|
522 | 526 | TPropertyAccess::set($resultObject, $property, $values); |
523 | - } |
|
524 | - else if($method == self::QUERY_FOR_OBJECT) |
|
527 | + } else if($method == self::QUERY_FOR_OBJECT) |
|
525 | 528 | { |
526 | 529 | $value = $statement->executeQueryForObject($connection, $keys, null); |
527 | 530 | TPropertyAccess::set($resultObject, $property, $value); |
@@ -546,21 +549,25 @@ discard block |
||
546 | 549 | */ |
547 | 550 | protected function applyResultMap($row, &$resultObject=null) |
548 | 551 | { |
549 | - if($row === false) return null; |
|
552 | + if($row === false) { |
|
553 | + return null; |
|
554 | + } |
|
550 | 555 | |
551 | 556 | $resultMapName = $this->_statement->getResultMap(); |
552 | 557 | $resultClass = $this->_statement->getResultClass(); |
553 | 558 | |
554 | 559 | $obj=null; |
555 | - if($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
556 | - $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject); |
|
557 | - else if(strlen($resultClass) > 0) |
|
558 | - $obj = $this->fillResultClass($resultClass, $row, $resultObject); |
|
559 | - else |
|
560 | - $obj = $this->fillDefaultResultMap(null, $row, $resultObject); |
|
561 | - if(class_exists('TActiveRecord',false) && $obj instanceof TActiveRecord) |
|
562 | - //Create a new clean active record. |
|
560 | + if($this->getManager()->getResultMaps()->contains($resultMapName)) { |
|
561 | + $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject); |
|
562 | + } else if(strlen($resultClass) > 0) { |
|
563 | + $obj = $this->fillResultClass($resultClass, $row, $resultObject); |
|
564 | + } else { |
|
565 | + $obj = $this->fillDefaultResultMap(null, $row, $resultObject); |
|
566 | + } |
|
567 | + if(class_exists('TActiveRecord',false) && $obj instanceof TActiveRecord) { |
|
568 | + //Create a new clean active record. |
|
563 | 569 | $obj=TActiveRecord::createRecord(get_class($obj),$obj); |
570 | + } |
|
564 | 571 | return $obj; |
565 | 572 | } |
566 | 573 | |
@@ -579,12 +586,13 @@ discard block |
||
579 | 586 | $resultObject = $this->_statement->createInstanceOfResultClass($registry,$row); |
580 | 587 | } |
581 | 588 | |
582 | - if($resultObject instanceOf ArrayAccess) |
|
583 | - return $this->fillResultArrayList($row, $resultObject); |
|
584 | - else if(is_object($resultObject)) |
|
585 | - return $this->fillResultObjectProperty($row, $resultObject); |
|
586 | - else |
|
587 | - return $this->fillDefaultResultMap(null, $row, $resultObject); |
|
589 | + if($resultObject instanceOf ArrayAccess) { |
|
590 | + return $this->fillResultArrayList($row, $resultObject); |
|
591 | + } else if(is_object($resultObject)) { |
|
592 | + return $this->fillResultObjectProperty($row, $resultObject); |
|
593 | + } else { |
|
594 | + return $this->fillDefaultResultMap(null, $row, $resultObject); |
|
595 | + } |
|
588 | 596 | } |
589 | 597 | |
590 | 598 | /** |
@@ -595,12 +603,13 @@ discard block |
||
595 | 603 | */ |
596 | 604 | protected function fillResultArrayList($row, $resultObject) |
597 | 605 | { |
598 | - if($resultObject instanceof TList) |
|
599 | - foreach($row as $v) |
|
606 | + if($resultObject instanceof TList) { |
|
607 | + foreach($row as $v) |
|
600 | 608 | $resultObject[] = $v; |
601 | - else |
|
602 | - foreach($row as $k => $v) |
|
609 | + } else { |
|
610 | + foreach($row as $k => $v) |
|
603 | 611 | $resultObject[$k] = $v; |
612 | + } |
|
604 | 613 | return $resultObject; |
605 | 614 | } |
606 | 615 | |
@@ -617,8 +626,9 @@ discard block |
||
617 | 626 | foreach($row as $k=>$v) |
618 | 627 | { |
619 | 628 | $property = new TResultProperty; |
620 | - if(is_string($k) && strlen($k) > 0) |
|
621 | - $property->setColumn($k); |
|
629 | + if(is_string($k) && strlen($k) > 0) { |
|
630 | + $property->setColumn($k); |
|
631 | + } |
|
622 | 632 | $property->setColumnIndex(++$index); |
623 | 633 | $type = gettype(TPropertyAccess::get($resultObject,$k)); |
624 | 634 | $property->setType($type); |
@@ -641,18 +651,19 @@ discard block |
||
641 | 651 | $registry = $this->getManager()->getTypeHandlers(); |
642 | 652 | $resultMap = $resultMap->resolveSubMap($registry,$row); |
643 | 653 | |
644 | - if($resultObject===null) |
|
645 | - $resultObject = $resultMap->createInstanceOfResult($registry); |
|
654 | + if($resultObject===null) { |
|
655 | + $resultObject = $resultMap->createInstanceOfResult($registry); |
|
656 | + } |
|
646 | 657 | |
647 | 658 | if(is_object($resultObject)) |
648 | 659 | { |
649 | - if(strlen($resultMap->getGroupBy()) > 0) |
|
650 | - return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
|
651 | - else |
|
652 | - foreach($resultMap->getColumns() as $property) |
|
660 | + if(strlen($resultMap->getGroupBy()) > 0) { |
|
661 | + return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
|
662 | + } else { |
|
663 | + foreach($resultMap->getColumns() as $property) |
|
653 | 664 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
654 | - } |
|
655 | - else |
|
665 | + } |
|
666 | + } else |
|
656 | 667 | { |
657 | 668 | $resultObject = $this->fillDefaultResultMap($resultMap, $row, $resultObject); |
658 | 669 | } |
@@ -690,18 +701,20 @@ discard block |
||
690 | 701 | $groupKey = $this->getResultMapGroupKey($nestedMap, $row); |
691 | 702 | |
692 | 703 | //add the node reference first |
693 | - if(empty($parent)) |
|
694 | - $this->_groupBy->add($group, $groupKey, ''); |
|
704 | + if(empty($parent)) { |
|
705 | + $this->_groupBy->add($group, $groupKey, ''); |
|
706 | + } |
|
695 | 707 | |
696 | 708 | //get the nested result mapping value |
697 | 709 | $value = $this->fillResultMap($nested, $row, $groupKey); |
698 | 710 | |
699 | 711 | //add it to the object tree graph |
700 | 712 | $groupObject = array('object'=>$value, 'property' => $property->getProperty()); |
701 | - if(empty($parent)) |
|
702 | - $this->_groupBy->add($group, $groupKey, $groupObject); |
|
703 | - else |
|
704 | - $this->_groupBy->add($parent, $groupKey, $groupObject); |
|
713 | + if(empty($parent)) { |
|
714 | + $this->_groupBy->add($group, $groupKey, $groupObject); |
|
715 | + } else { |
|
716 | + $this->_groupBy->add($parent, $groupKey, $groupObject); |
|
717 | + } |
|
705 | 718 | } |
706 | 719 | } |
707 | 720 | return $resultObject; |
@@ -716,10 +729,11 @@ discard block |
||
716 | 729 | protected function getResultMapGroupKey($resultMap, $row) |
717 | 730 | { |
718 | 731 | $groupBy = $resultMap->getGroupBy(); |
719 | - if(isset($row[$groupBy])) |
|
720 | - return $resultMap->getID().$row[$groupBy]; |
|
721 | - else |
|
722 | - return $resultMap->getID().crc32(serialize($row)); |
|
732 | + if(isset($row[$groupBy])) { |
|
733 | + return $resultMap->getID().$row[$groupBy]; |
|
734 | + } else { |
|
735 | + return $resultMap->getID().crc32(serialize($row)); |
|
736 | + } |
|
723 | 737 | } |
724 | 738 | |
725 | 739 | /** |
@@ -732,19 +746,22 @@ discard block |
||
732 | 746 | */ |
733 | 747 | protected function fillDefaultResultMap($resultMap, $row, $resultObject) |
734 | 748 | { |
735 | - if($resultObject===null) |
|
736 | - $resultObject=''; |
|
749 | + if($resultObject===null) { |
|
750 | + $resultObject=''; |
|
751 | + } |
|
737 | 752 | |
738 | - if($resultMap!==null) |
|
739 | - $result = $this->fillArrayResultMap($resultMap, $row, $resultObject); |
|
740 | - else |
|
741 | - $result = $row; |
|
753 | + if($resultMap!==null) { |
|
754 | + $result = $this->fillArrayResultMap($resultMap, $row, $resultObject); |
|
755 | + } else { |
|
756 | + $result = $row; |
|
757 | + } |
|
742 | 758 | |
743 | 759 | //if scalar result types |
744 | - if(count($result) == 1 && ($type = gettype($resultObject))!= 'array') |
|
745 | - return $this->getScalarResult($result, $type); |
|
746 | - else |
|
747 | - return $result; |
|
760 | + if(count($result) == 1 && ($type = gettype($resultObject))!= 'array') { |
|
761 | + return $this->getScalarResult($result, $type); |
|
762 | + } else { |
|
763 | + return $result; |
|
764 | + } |
|
748 | 765 | } |
749 | 766 | |
750 | 767 | /** |
@@ -761,8 +778,9 @@ discard block |
||
761 | 778 | foreach($resultMap->getColumns() as $column) |
762 | 779 | { |
763 | 780 | if(($column->getType()===null) |
764 | - && ($resultObject!==null) && !is_object($resultObject)) |
|
765 | - $column->setType(gettype($resultObject)); |
|
781 | + && ($resultObject!==null) && !is_object($resultObject)) { |
|
782 | + $column->setType(gettype($resultObject)); |
|
783 | + } |
|
766 | 784 | $result[$column->getProperty()] = $column->getPropertyValue($registry,$row); |
767 | 785 | } |
768 | 786 | return $result; |
@@ -797,35 +815,34 @@ discard block |
||
797 | 815 | if($key === '') |
798 | 816 | { |
799 | 817 | $resultObject = $property->getPropertyValue($registry,$row); |
800 | - } |
|
801 | - else if(strlen($select) == 0 && ($nested===null)) |
|
818 | + } else if(strlen($select) == 0 && ($nested===null)) |
|
802 | 819 | { |
803 | 820 | $value = $property->getPropertyValue($registry,$row); |
804 | 821 | |
805 | 822 | $this->_IsRowDataFound = $this->_IsRowDataFound || ($value != null); |
806 | - if(is_array($resultObject) || is_object($resultObject)) |
|
807 | - TPropertyAccess::set($resultObject, $key, $value); |
|
808 | - else |
|
809 | - $resultObject = $value; |
|
810 | - } |
|
811 | - else if($nested!==null) |
|
823 | + if(is_array($resultObject) || is_object($resultObject)) { |
|
824 | + TPropertyAccess::set($resultObject, $key, $value); |
|
825 | + } else { |
|
826 | + $resultObject = $value; |
|
827 | + } |
|
828 | + } else if($nested!==null) |
|
812 | 829 | { |
813 | 830 | if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
814 | 831 | { |
815 | - if(strlen($resultMap->getGroupBy()) <= 0) |
|
816 | - throw new TSqlMapExecutionException( |
|
832 | + if(strlen($resultMap->getGroupBy()) <= 0) { |
|
833 | + throw new TSqlMapExecutionException( |
|
817 | 834 | 'sqlmap_non_groupby_array_list_type', $resultMap->getID(), |
818 | 835 | get_class($resultObject), $key); |
819 | - } |
|
820 | - else |
|
836 | + } |
|
837 | + } else |
|
821 | 838 | { |
822 | 839 | $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers()); |
823 | - if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
824 | - $obj = null; |
|
840 | + if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) { |
|
841 | + $obj = null; |
|
842 | + } |
|
825 | 843 | TPropertyAccess::set($resultObject, $key, $obj); |
826 | 844 | } |
827 | - } |
|
828 | - else //'select' ResultProperty |
|
845 | + } else //'select' ResultProperty |
|
829 | 846 | { |
830 | 847 | $this->enquequePostSelect($select, $resultMap, $property, $row, $resultObject); |
831 | 848 | } |
@@ -857,17 +874,18 @@ discard block |
||
857 | 874 | $values = TLazyLoadList::newInstance($statement, $key, |
858 | 875 | $resultObject, $property->getProperty()); |
859 | 876 | TPropertyAccess::set($resultObject, $property->getProperty(), $values); |
877 | + } else { |
|
878 | + $postSelect->setMethod(self::QUERY_FOR_LIST); |
|
860 | 879 | } |
861 | - else |
|
862 | - $postSelect->setMethod(self::QUERY_FOR_LIST); |
|
880 | + } else if($property->instanceOfArrayType($resultObject)) { |
|
881 | + $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
|
882 | + } else { |
|
883 | + $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
|
863 | 884 | } |
864 | - else if($property->instanceOfArrayType($resultObject)) |
|
865 | - $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
|
866 | - else |
|
867 | - $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
|
868 | 885 | |
869 | - if(!$property->getLazyLoad()) |
|
870 | - $this->_selectQueue[] = $postSelect; |
|
886 | + if(!$property->getLazyLoad()) { |
|
887 | + $this->_selectQueue[] = $postSelect; |
|
888 | + } |
|
871 | 889 | } |
872 | 890 | |
873 | 891 | /** |
@@ -889,8 +907,7 @@ discard block |
||
889 | 907 | $keys[trim($pair[0])] = $row[trim($pair[1])]; |
890 | 908 | } |
891 | 909 | return $keys; |
892 | - } |
|
893 | - else |
|
910 | + } else |
|
894 | 911 | { |
895 | 912 | $registry=$this->getManager()->getTypeHandlers(); |
896 | 913 | return $property->getPropertyValue($registry,$row); |
@@ -920,15 +937,23 @@ discard block |
||
920 | 937 | public function __wakeup() |
921 | 938 | { |
922 | 939 | parent::__wakeup(); |
923 | - if (is_null($this->_selectQueue)) $this->_selectQueue = array(); |
|
940 | + if (is_null($this->_selectQueue)) { |
|
941 | + $this->_selectQueue = array(); |
|
942 | + } |
|
924 | 943 | } |
925 | 944 | |
926 | 945 | public function __sleep() |
927 | 946 | { |
928 | 947 | $exprops = array(); $cn = __CLASS__; |
929 | - if (!count($this->_selectQueue)) $exprops[] = "\0$cn\0_selectQueue"; |
|
930 | - if (is_null($this->_groupBy)) $exprops[] = "\0$cn\0_groupBy"; |
|
931 | - if (!$this->_IsRowDataFound) $exprops[] = "\0$cn\0_IsRowDataFound"; |
|
948 | + if (!count($this->_selectQueue)) { |
|
949 | + $exprops[] = "\0$cn\0_selectQueue"; |
|
950 | + } |
|
951 | + if (is_null($this->_groupBy)) { |
|
952 | + $exprops[] = "\0$cn\0_groupBy"; |
|
953 | + } |
|
954 | + if (!$this->_IsRowDataFound) { |
|
955 | + $exprops[] = "\0$cn\0_IsRowDataFound"; |
|
956 | + } |
|
932 | 957 | return array_diff(parent::__sleep(),$exprops); |
933 | 958 | } |
934 | 959 | } |
@@ -1015,16 +1040,18 @@ discard block |
||
1015 | 1040 | $this->_entries[$node] = $object; |
1016 | 1041 | if(empty($parent)) |
1017 | 1042 | { |
1018 | - if(isset($this->_entries[$node])) |
|
1019 | - return; |
|
1043 | + if(isset($this->_entries[$node])) { |
|
1044 | + return; |
|
1045 | + } |
|
1020 | 1046 | $this->_tree[$node] = array(); |
1021 | 1047 | } |
1022 | 1048 | $found = $this->addNode($this->_tree, $parent, $node); |
1023 | 1049 | if(!$found && !empty($parent)) |
1024 | 1050 | { |
1025 | 1051 | $this->_tree[$parent] = array(); |
1026 | - if(!isset($this->_entries[$parent]) || $object !== '') |
|
1027 | - $this->_entries[$parent] = $object; |
|
1052 | + if(!isset($this->_entries[$parent]) || $object !== '') { |
|
1053 | + $this->_entries[$parent] = $object; |
|
1054 | + } |
|
1028 | 1055 | $this->addNode($this->_tree, $parent, $node); |
1029 | 1056 | } |
1030 | 1057 | } |
@@ -1048,8 +1075,7 @@ discard block |
||
1048 | 1075 | { |
1049 | 1076 | $found = true; |
1050 | 1077 | $childs[$key][$node] = array(); |
1051 | - } |
|
1052 | - else |
|
1078 | + } else |
|
1053 | 1079 | { |
1054 | 1080 | $found = $found || $this->addNode($childs[$key], $parent, $node); |
1055 | 1081 | } |
@@ -1062,8 +1088,9 @@ discard block |
||
1062 | 1088 | */ |
1063 | 1089 | public function collect() |
1064 | 1090 | { |
1065 | - while(count($this->_tree) > 0) |
|
1066 | - $this->collectChildren(null, $this->_tree); |
|
1091 | + while(count($this->_tree) > 0) { |
|
1092 | + $this->collectChildren(null, $this->_tree); |
|
1093 | + } |
|
1067 | 1094 | return $this->getCollection(); |
1068 | 1095 | } |
1069 | 1096 | |
@@ -1074,9 +1101,10 @@ discard block |
||
1074 | 1101 | protected function hasChildren(&$nodes) |
1075 | 1102 | { |
1076 | 1103 | $hasChildren = false; |
1077 | - foreach($nodes as $node) |
|
1078 | - if(count($node) != 0) |
|
1104 | + foreach($nodes as $node) { |
|
1105 | + if(count($node) != 0) |
|
1079 | 1106 | return true; |
1107 | + } |
|
1080 | 1108 | return $hasChildren; |
1081 | 1109 | } |
1082 | 1110 | |
@@ -1096,12 +1124,13 @@ discard block |
||
1096 | 1124 | { |
1097 | 1125 | $childs[] = $key; |
1098 | 1126 | unset($nodes[$key]); |
1127 | + } else { |
|
1128 | + $this->collectChildren($key, $nodes[$key]); |
|
1099 | 1129 | } |
1100 | - else |
|
1101 | - $this->collectChildren($key, $nodes[$key]); |
|
1102 | 1130 | } |
1103 | - if(count($childs) > 0) |
|
1104 | - $this->onChildNodesVisited($parent, $childs); |
|
1131 | + if(count($childs) > 0) { |
|
1132 | + $this->onChildNodesVisited($parent, $childs); |
|
1133 | + } |
|
1105 | 1134 | } |
1106 | 1135 | |
1107 | 1136 | /** |
@@ -1111,8 +1140,9 @@ discard block |
||
1111 | 1140 | */ |
1112 | 1141 | protected function onChildNodesVisited($parent, $nodes) |
1113 | 1142 | { |
1114 | - if(empty($parent) || empty($this->_entries[$parent])) |
|
1115 | - return; |
|
1143 | + if(empty($parent) || empty($this->_entries[$parent])) { |
|
1144 | + return; |
|
1145 | + } |
|
1116 | 1146 | |
1117 | 1147 | $parentObject = $this->_entries[$parent]['object']; |
1118 | 1148 | $property = $this->_entries[$nodes[0]]['property']; |
@@ -1121,20 +1151,23 @@ discard block |
||
1121 | 1151 | |
1122 | 1152 | foreach($nodes as $node) |
1123 | 1153 | { |
1124 | - if($list instanceof TList) |
|
1125 | - $parentObject->{$property}[] = $this->_entries[$node]['object']; |
|
1126 | - else if(is_array($list)) |
|
1127 | - $list[] = $this->_entries[$node]['object']; |
|
1128 | - else |
|
1129 | - throw new TSqlMapExecutionException( |
|
1154 | + if($list instanceof TList) { |
|
1155 | + $parentObject->{$property}[] = $this->_entries[$node]['object']; |
|
1156 | + } else if(is_array($list)) { |
|
1157 | + $list[] = $this->_entries[$node]['object']; |
|
1158 | + } else { |
|
1159 | + throw new TSqlMapExecutionException( |
|
1130 | 1160 | 'sqlmap_property_must_be_list'); |
1161 | + } |
|
1131 | 1162 | } |
1132 | 1163 | |
1133 | - if(is_array($list)) |
|
1134 | - TPropertyAccess::set($parentObject, $property, $list); |
|
1164 | + if(is_array($list)) { |
|
1165 | + TPropertyAccess::set($parentObject, $property, $list); |
|
1166 | + } |
|
1135 | 1167 | |
1136 | - if($this->_entries[$parent]['property'] === null) |
|
1137 | - $this->_list[] = $parentObject; |
|
1168 | + if($this->_entries[$parent]['property'] === null) { |
|
1169 | + $this->_list[] = $parentObject; |
|
1170 | + } |
|
1138 | 1171 | } |
1139 | 1172 | |
1140 | 1173 | /** |
@@ -1148,9 +1181,15 @@ discard block |
||
1148 | 1181 | public function __sleep() |
1149 | 1182 | { |
1150 | 1183 | $exprops = array(); $cn = __CLASS__; |
1151 | - if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree"; |
|
1152 | - if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries"; |
|
1153 | - if (!count($this->_list)) $exprops[] = "\0$cn\0_list"; |
|
1184 | + if (!count($this->_tree)) { |
|
1185 | + $exprops[] = "\0$cn\0_tree"; |
|
1186 | + } |
|
1187 | + if (!count($this->_entries)) { |
|
1188 | + $exprops[] = "\0$cn\0_entries"; |
|
1189 | + } |
|
1190 | + if (!count($this->_list)) { |
|
1191 | + $exprops[] = "\0$cn\0_list"; |
|
1192 | + } |
|
1154 | 1193 | return array_diff(parent::__sleep(),$exprops); |
1155 | 1194 | } |
1156 | 1195 | } |