@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | if (is_string($value)) |
66 | 66 | return strcasecmp($value, 'true') == 0 || $value != 0; |
67 | 67 | else |
68 | - return (boolean)$value; |
|
68 | + return (boolean) $value; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | if (TJavaScript::isJsLiteral($value)) |
81 | 81 | return $value; |
82 | 82 | if (is_bool($value)) |
83 | - return $value?'true':'false'; |
|
83 | + return $value ? 'true' : 'false'; |
|
84 | 84 | else |
85 | - return (string)$value; |
|
85 | + return (string) $value; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public static function ensureInteger($value) |
94 | 94 | { |
95 | - return (integer)$value; |
|
95 | + return (integer) $value; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public static function ensureFloat($value) |
104 | 104 | { |
105 | - return (float)$value; |
|
105 | + return (float) $value; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -116,20 +116,20 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public static function ensureArray($value) |
118 | 118 | { |
119 | - if(is_string($value)) |
|
119 | + if (is_string($value)) |
|
120 | 120 | { |
121 | 121 | $value = trim($value); |
122 | 122 | $len = strlen($value); |
123 | 123 | if ($len >= 2 && $value[0] == '(' && $value[$len - 1] == ')') |
124 | 124 | { |
125 | - eval('$array=array' . $value . ';'); |
|
125 | + eval('$array=array'.$value.';'); |
|
126 | 126 | return $array; |
127 | 127 | } |
128 | 128 | else |
129 | - return $len > 0?[$value]:[]; |
|
129 | + return $len > 0 ? [$value] : []; |
|
130 | 130 | } |
131 | 131 | else |
132 | - return (array)$value; |
|
132 | + return (array) $value; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public static function ensureObject($value) |
141 | 141 | { |
142 | - return (object)$value; |
|
142 | + return (object) $value; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -161,23 +161,23 @@ discard block |
||
161 | 161 | public static function ensureEnum($value, $enums) |
162 | 162 | { |
163 | 163 | static $types = []; |
164 | - if(func_num_args() === 2 && is_string($enums)) |
|
164 | + if (func_num_args() === 2 && is_string($enums)) |
|
165 | 165 | { |
166 | - if(!isset($types[$enums])) |
|
166 | + if (!isset($types[$enums])) |
|
167 | 167 | $types[$enums] = new \ReflectionClass($enums); |
168 | - if($types[$enums]->hasConstant($value)) |
|
168 | + if ($types[$enums]->hasConstant($value)) |
|
169 | 169 | return $value; |
170 | 170 | else |
171 | 171 | throw new TInvalidDataValueException( |
172 | 172 | 'propertyvalue_enumvalue_invalid', $value, |
173 | 173 | implode(' | ', $types[$enums]->getConstants())); |
174 | 174 | } |
175 | - elseif(!is_array($enums)) |
|
175 | + elseif (!is_array($enums)) |
|
176 | 176 | { |
177 | 177 | $enums = func_get_args(); |
178 | 178 | array_shift($enums); |
179 | 179 | } |
180 | - if(in_array($value, $enums, true)) |
|
180 | + if (in_array($value, $enums, true)) |
|
181 | 181 | return $value; |
182 | 182 | else |
183 | 183 | throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid', $value, implode(' | ', $enums)); |
@@ -190,6 +190,6 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public static function ensureNullIfEmpty($value) |
192 | 192 | { |
193 | - return empty($value)?null:$value; |
|
193 | + return empty($value) ?null:$value; |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | \ No newline at end of file |
@@ -62,10 +62,11 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public static function ensureBoolean($value) |
64 | 64 | { |
65 | - if (is_string($value)) |
|
66 | - return strcasecmp($value, 'true') == 0 || $value != 0; |
|
67 | - else |
|
68 | - return (boolean)$value; |
|
65 | + if (is_string($value)) { |
|
66 | + return strcasecmp($value, 'true') == 0 || $value != 0; |
|
67 | + } else { |
|
68 | + return (boolean)$value; |
|
69 | + } |
|
69 | 70 | } |
70 | 71 | |
71 | 72 | /** |
@@ -77,12 +78,14 @@ discard block |
||
77 | 78 | */ |
78 | 79 | public static function ensureString($value) |
79 | 80 | { |
80 | - if (TJavaScript::isJsLiteral($value)) |
|
81 | - return $value; |
|
82 | - if (is_bool($value)) |
|
83 | - return $value?'true':'false'; |
|
84 | - else |
|
85 | - return (string)$value; |
|
81 | + if (TJavaScript::isJsLiteral($value)) { |
|
82 | + return $value; |
|
83 | + } |
|
84 | + if (is_bool($value)) { |
|
85 | + return $value?'true':'false'; |
|
86 | + } else { |
|
87 | + return (string)$value; |
|
88 | + } |
|
86 | 89 | } |
87 | 90 | |
88 | 91 | /** |
@@ -124,12 +127,12 @@ discard block |
||
124 | 127 | { |
125 | 128 | eval('$array=array' . $value . ';'); |
126 | 129 | return $array; |
130 | + } else { |
|
131 | + return $len > 0?[$value]:[]; |
|
127 | 132 | } |
128 | - else |
|
129 | - return $len > 0?[$value]:[]; |
|
133 | + } else { |
|
134 | + return (array)$value; |
|
130 | 135 | } |
131 | - else |
|
132 | - return (array)$value; |
|
133 | 136 | } |
134 | 137 | |
135 | 138 | /** |
@@ -163,24 +166,26 @@ discard block |
||
163 | 166 | static $types = []; |
164 | 167 | if(func_num_args() === 2 && is_string($enums)) |
165 | 168 | { |
166 | - if(!isset($types[$enums])) |
|
167 | - $types[$enums] = new \ReflectionClass($enums); |
|
168 | - if($types[$enums]->hasConstant($value)) |
|
169 | - return $value; |
|
170 | - else |
|
171 | - throw new TInvalidDataValueException( |
|
169 | + if(!isset($types[$enums])) { |
|
170 | + $types[$enums] = new \ReflectionClass($enums); |
|
171 | + } |
|
172 | + if($types[$enums]->hasConstant($value)) { |
|
173 | + return $value; |
|
174 | + } else { |
|
175 | + throw new TInvalidDataValueException( |
|
172 | 176 | 'propertyvalue_enumvalue_invalid', $value, |
173 | 177 | implode(' | ', $types[$enums]->getConstants())); |
174 | - } |
|
175 | - elseif(!is_array($enums)) |
|
178 | + } |
|
179 | + } elseif(!is_array($enums)) |
|
176 | 180 | { |
177 | 181 | $enums = func_get_args(); |
178 | 182 | array_shift($enums); |
179 | 183 | } |
180 | - if(in_array($value, $enums, true)) |
|
181 | - return $value; |
|
182 | - else |
|
183 | - throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid', $value, implode(' | ', $enums)); |
|
184 | + if(in_array($value, $enums, true)) { |
|
185 | + return $value; |
|
186 | + } else { |
|
187 | + throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid', $value, implode(' | ', $enums)); |
|
188 | + } |
|
184 | 189 | } |
185 | 190 | |
186 | 191 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function bindColumn($column, &$value, $dataType = null) |
69 | 69 | { |
70 | - if($dataType === null) |
|
70 | + if ($dataType === null) |
|
71 | 71 | $this->_statement->bindColumn($column, $value); |
72 | 72 | else |
73 | 73 | $this->_statement->bindColumn($column, $value, $dataType); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | public function setFetchMode($mode) |
80 | 80 | { |
81 | 81 | $params = func_get_args(); |
82 | - call_user_func_array([$this->_statement,'setFetchMode'], $params); |
|
82 | + call_user_func_array([$this->_statement, 'setFetchMode'], $params); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function rewind() |
178 | 178 | { |
179 | - if($this->_index < 0) |
|
179 | + if ($this->_index < 0) |
|
180 | 180 | { |
181 | 181 | $this->_row = $this->_statement->fetch(); |
182 | 182 | $this->_index = 0; |
@@ -67,10 +67,11 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function bindColumn($column, &$value, $dataType = null) |
69 | 69 | { |
70 | - if($dataType === null) |
|
71 | - $this->_statement->bindColumn($column, $value); |
|
72 | - else |
|
73 | - $this->_statement->bindColumn($column, $value, $dataType); |
|
70 | + if($dataType === null) { |
|
71 | + $this->_statement->bindColumn($column, $value); |
|
72 | + } else { |
|
73 | + $this->_statement->bindColumn($column, $value, $dataType); |
|
74 | + } |
|
74 | 75 | } |
75 | 76 | |
76 | 77 | /** |
@@ -180,9 +181,9 @@ discard block |
||
180 | 181 | { |
181 | 182 | $this->_row = $this->_statement->fetch(); |
182 | 183 | $this->_index = 0; |
184 | + } else { |
|
185 | + throw new TDbException('dbdatareader_rewind_invalid'); |
|
183 | 186 | } |
184 | - else |
|
185 | - throw new TDbException('dbdatareader_rewind_invalid'); |
|
186 | 187 | } |
187 | 188 | |
188 | 189 | /** |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | public function __sleep() |
142 | 142 | { |
143 | 143 | // $this->close(); - DO NOT CLOSE the current connection as serializing doesn't neccessarily mean we don't this connection anymore in the current session |
144 | - return array_diff(parent::__sleep(), ["\0Prado\Data\TDbConnection\0_pdo","\0Prado\Data\TDbConnection\0_active"]); |
|
144 | + return array_diff(parent::__sleep(), ["\0Prado\Data\TDbConnection\0_pdo", "\0Prado\Data\TDbConnection\0_active"]); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | public function setActive($value) |
170 | 170 | { |
171 | 171 | $value = TPropertyValue::ensureBoolean($value); |
172 | - if($value !== $this->_active) |
|
172 | + if ($value !== $this->_active) |
|
173 | 173 | { |
174 | - if($value) |
|
174 | + if ($value) |
|
175 | 175 | $this->open(); |
176 | 176 | else |
177 | 177 | $this->close(); |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | */ |
185 | 185 | protected function open() |
186 | 186 | { |
187 | - if($this->_pdo === null) |
|
187 | + if ($this->_pdo === null) |
|
188 | 188 | { |
189 | 189 | try |
190 | 190 | { |
191 | - $this->_pdo = new PDO($this->getConnectionString(),$this->getUsername(), |
|
191 | + $this->_pdo = new PDO($this->getConnectionString(), $this->getUsername(), |
|
192 | 192 | $this->getPassword(), $this->_attributes); |
193 | 193 | // This attribute is only useful for PDO::MySql driver. |
194 | 194 | // Ignore the warning if a driver doesn't understand this. |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $this->_active = true; |
198 | 198 | $this->setConnectionCharset(); |
199 | 199 | } |
200 | - catch(PDOException $e) |
|
200 | + catch (PDOException $e) |
|
201 | 201 | { |
202 | 202 | throw new TDbException('dbconnection_open_failed', $e->getMessage()); |
203 | 203 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | /** |
291 | 291 | * @return string the charset used for database connection. Defaults to emtpy string. |
292 | 292 | */ |
293 | - public function getCharset () |
|
293 | + public function getCharset() |
|
294 | 294 | { |
295 | 295 | return $this->_charset; |
296 | 296 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | /** |
299 | 299 | * @param string the charset used for database connection |
300 | 300 | */ |
301 | - public function setCharset ($value) |
|
301 | + public function setCharset($value) |
|
302 | 302 | { |
303 | 303 | $this->_charset = $value; |
304 | 304 | $this->setConnectionCharset(); |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public function createCommand($sql) |
322 | 322 | { |
323 | - if($this->getActive()) |
|
323 | + if ($this->getActive()) |
|
324 | 324 | return new TDbCommand($this, $sql); |
325 | 325 | else |
326 | 326 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | */ |
332 | 332 | public function getCurrentTransaction() |
333 | 333 | { |
334 | - if($this->_transaction !== null) |
|
334 | + if ($this->_transaction !== null) |
|
335 | 335 | { |
336 | - if($this->_transaction->getActive()) |
|
336 | + if ($this->_transaction->getActive()) |
|
337 | 337 | return $this->_transaction; |
338 | 338 | } |
339 | 339 | return null; |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | */ |
347 | 347 | public function beginTransaction() |
348 | 348 | { |
349 | - if($this->getActive()) |
|
349 | + if ($this->getActive()) |
|
350 | 350 | { |
351 | 351 | $this->_pdo->beginTransaction(); |
352 | 352 | return $this->_transaction = Prado::createComponent($this->getTransactionClass(), $this); |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function setTransactionClass($value) |
373 | 373 | { |
374 | - $this->_transactionClass = (string)$value; |
|
374 | + $this->_transactionClass = (string) $value; |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | */ |
383 | 383 | public function getLastInsertID($sequenceName = '') |
384 | 384 | { |
385 | - if($this->getActive()) |
|
385 | + if ($this->getActive()) |
|
386 | 386 | return $this->_pdo->lastInsertId($sequenceName); |
387 | 387 | else |
388 | 388 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public function quoteString($str) |
398 | 398 | { |
399 | - if($this->getActive()) |
|
399 | + if ($this->getActive()) |
|
400 | 400 | return $this->_pdo->quote($str); |
401 | 401 | else |
402 | 402 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public function getDbMetaData() |
439 | 439 | { |
440 | - if($this->_dbMeta === null) |
|
440 | + if ($this->_dbMeta === null) |
|
441 | 441 | { |
442 | 442 | $this->_dbMeta = TDbMetaData::getInstance($this); |
443 | 443 | } |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | */ |
450 | 450 | public function getColumnCase() |
451 | 451 | { |
452 | - switch($this->getAttribute(PDO::ATTR_CASE)) |
|
452 | + switch ($this->getAttribute(PDO::ATTR_CASE)) |
|
453 | 453 | { |
454 | 454 | case PDO::CASE_NATURAL: |
455 | 455 | return TDbColumnCaseMode::Preserved; |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | */ |
466 | 466 | public function setColumnCase($value) |
467 | 467 | { |
468 | - switch(TPropertyValue::ensureEnum($value, 'Prado\\Data\\TDbColumnCaseMode')) |
|
468 | + switch (TPropertyValue::ensureEnum($value, 'Prado\\Data\\TDbColumnCaseMode')) |
|
469 | 469 | { |
470 | 470 | case TDbColumnCaseMode::Preserved: |
471 | 471 | $value = PDO::CASE_NATURAL; |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | */ |
486 | 486 | public function getNullConversion() |
487 | 487 | { |
488 | - switch($this->getAttribute(PDO::ATTR_ORACLE_NULLS)) |
|
488 | + switch ($this->getAttribute(PDO::ATTR_ORACLE_NULLS)) |
|
489 | 489 | { |
490 | 490 | case PDO::NULL_NATURAL: |
491 | 491 | return TDbNullConversionMode::Preserved; |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | */ |
502 | 502 | public function setNullConversion($value) |
503 | 503 | { |
504 | - switch(TPropertyValue::ensureEnum($value, 'Prado\\Data\\TDbNullConversionMode')) |
|
504 | + switch (TPropertyValue::ensureEnum($value, 'Prado\\Data\\TDbNullConversionMode')) |
|
505 | 505 | { |
506 | 506 | case TDbNullConversionMode::Preserved: |
507 | 507 | $value = PDO::NULL_NATURAL; |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | */ |
618 | 618 | public function getAttribute($name) |
619 | 619 | { |
620 | - if($this->getActive()) |
|
620 | + if ($this->getActive()) |
|
621 | 621 | return $this->_pdo->getAttribute($name); |
622 | 622 | else |
623 | 623 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | */ |
632 | 632 | public function setAttribute($name, $value) |
633 | 633 | { |
634 | - if($this->_pdo instanceof PDO) |
|
634 | + if ($this->_pdo instanceof PDO) |
|
635 | 635 | $this->_pdo->setAttribute($name, $value); |
636 | 636 | else |
637 | 637 | $this->_attributes[$name] = $value; |
@@ -171,10 +171,11 @@ discard block |
||
171 | 171 | $value = TPropertyValue::ensureBoolean($value); |
172 | 172 | if($value !== $this->_active) |
173 | 173 | { |
174 | - if($value) |
|
175 | - $this->open(); |
|
176 | - else |
|
177 | - $this->close(); |
|
174 | + if($value) { |
|
175 | + $this->open(); |
|
176 | + } else { |
|
177 | + $this->close(); |
|
178 | + } |
|
178 | 179 | } |
179 | 180 | } |
180 | 181 | |
@@ -196,8 +197,7 @@ discard block |
||
196 | 197 | $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
197 | 198 | $this->_active = true; |
198 | 199 | $this->setConnectionCharset(); |
199 | - } |
|
200 | - catch(PDOException $e) |
|
200 | + } catch(PDOException $e) |
|
201 | 201 | { |
202 | 202 | throw new TDbException('dbconnection_open_failed', $e->getMessage()); |
203 | 203 | } |
@@ -221,8 +221,9 @@ discard block |
||
221 | 221 | */ |
222 | 222 | protected function setConnectionCharset() |
223 | 223 | { |
224 | - if ($this->_charset === '' || $this->_active === false) |
|
225 | - return; |
|
224 | + if ($this->_charset === '' || $this->_active === false) { |
|
225 | + return; |
|
226 | + } |
|
226 | 227 | switch ($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) |
227 | 228 | { |
228 | 229 | case 'mysql': |
@@ -320,10 +321,11 @@ discard block |
||
320 | 321 | */ |
321 | 322 | public function createCommand($sql) |
322 | 323 | { |
323 | - if($this->getActive()) |
|
324 | - return new TDbCommand($this, $sql); |
|
325 | - else |
|
326 | - throw new TDbException('dbconnection_connection_inactive'); |
|
324 | + if($this->getActive()) { |
|
325 | + return new TDbCommand($this, $sql); |
|
326 | + } else { |
|
327 | + throw new TDbException('dbconnection_connection_inactive'); |
|
328 | + } |
|
327 | 329 | } |
328 | 330 | |
329 | 331 | /** |
@@ -333,8 +335,9 @@ discard block |
||
333 | 335 | { |
334 | 336 | if($this->_transaction !== null) |
335 | 337 | { |
336 | - if($this->_transaction->getActive()) |
|
337 | - return $this->_transaction; |
|
338 | + if($this->_transaction->getActive()) { |
|
339 | + return $this->_transaction; |
|
340 | + } |
|
338 | 341 | } |
339 | 342 | return null; |
340 | 343 | } |
@@ -350,9 +353,9 @@ discard block |
||
350 | 353 | { |
351 | 354 | $this->_pdo->beginTransaction(); |
352 | 355 | return $this->_transaction = Prado::createComponent($this->getTransactionClass(), $this); |
356 | + } else { |
|
357 | + throw new TDbException('dbconnection_connection_inactive'); |
|
353 | 358 | } |
354 | - else |
|
355 | - throw new TDbException('dbconnection_connection_inactive'); |
|
356 | 359 | } |
357 | 360 | |
358 | 361 | /** |
@@ -382,10 +385,11 @@ discard block |
||
382 | 385 | */ |
383 | 386 | public function getLastInsertID($sequenceName = '') |
384 | 387 | { |
385 | - if($this->getActive()) |
|
386 | - return $this->_pdo->lastInsertId($sequenceName); |
|
387 | - else |
|
388 | - throw new TDbException('dbconnection_connection_inactive'); |
|
388 | + if($this->getActive()) { |
|
389 | + return $this->_pdo->lastInsertId($sequenceName); |
|
390 | + } else { |
|
391 | + throw new TDbException('dbconnection_connection_inactive'); |
|
392 | + } |
|
389 | 393 | } |
390 | 394 | |
391 | 395 | /** |
@@ -396,10 +400,11 @@ discard block |
||
396 | 400 | */ |
397 | 401 | public function quoteString($str) |
398 | 402 | { |
399 | - if($this->getActive()) |
|
400 | - return $this->_pdo->quote($str); |
|
401 | - else |
|
402 | - throw new TDbException('dbconnection_connection_inactive'); |
|
403 | + if($this->getActive()) { |
|
404 | + return $this->_pdo->quote($str); |
|
405 | + } else { |
|
406 | + throw new TDbException('dbconnection_connection_inactive'); |
|
407 | + } |
|
403 | 408 | } |
404 | 409 | |
405 | 410 | /** |
@@ -617,10 +622,11 @@ discard block |
||
617 | 622 | */ |
618 | 623 | public function getAttribute($name) |
619 | 624 | { |
620 | - if($this->getActive()) |
|
621 | - return $this->_pdo->getAttribute($name); |
|
622 | - else |
|
623 | - throw new TDbException('dbconnection_connection_inactive'); |
|
625 | + if($this->getActive()) { |
|
626 | + return $this->_pdo->getAttribute($name); |
|
627 | + } else { |
|
628 | + throw new TDbException('dbconnection_connection_inactive'); |
|
629 | + } |
|
624 | 630 | } |
625 | 631 | |
626 | 632 | /** |
@@ -631,9 +637,10 @@ discard block |
||
631 | 637 | */ |
632 | 638 | public function setAttribute($name, $value) |
633 | 639 | { |
634 | - if($this->_pdo instanceof PDO) |
|
635 | - $this->_pdo->setAttribute($name, $value); |
|
636 | - else |
|
637 | - $this->_attributes[$name] = $value; |
|
640 | + if($this->_pdo instanceof PDO) { |
|
641 | + $this->_pdo->setAttribute($name, $value); |
|
642 | + } else { |
|
643 | + $this->_attributes[$name] = $value; |
|
644 | + } |
|
638 | 645 | } |
639 | 646 | } |
640 | 647 | \ No newline at end of file |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function commit() |
66 | 66 | { |
67 | - if($this->_active && $this->_connection->getActive()) |
|
67 | + if ($this->_active && $this->_connection->getActive()) |
|
68 | 68 | { |
69 | 69 | $this->_connection->getPdoInstance()->commit(); |
70 | 70 | $this->_active = false; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function rollback() |
81 | 81 | { |
82 | - if($this->_active && $this->_connection->getActive()) |
|
82 | + if ($this->_active && $this->_connection->getActive()) |
|
83 | 83 | { |
84 | 84 | $this->_connection->getPdoInstance()->rollBack(); |
85 | 85 | $this->_active = false; |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | { |
69 | 69 | $this->_connection->getPdoInstance()->commit(); |
70 | 70 | $this->_active = false; |
71 | + } else { |
|
72 | + throw new TDbException('dbtransaction_transaction_inactive'); |
|
71 | 73 | } |
72 | - else |
|
73 | - throw new TDbException('dbtransaction_transaction_inactive'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | { |
84 | 84 | $this->_connection->getPdoInstance()->rollBack(); |
85 | 85 | $this->_active = false; |
86 | + } else { |
|
87 | + throw new TDbException('dbtransaction_transaction_inactive'); |
|
86 | 88 | } |
87 | - else |
|
88 | - throw new TDbException('dbtransaction_transaction_inactive'); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -112,13 +112,13 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function prepare() |
114 | 114 | { |
115 | - if($this->_statement == null) |
|
115 | + if ($this->_statement == null) |
|
116 | 116 | { |
117 | 117 | try |
118 | 118 | { |
119 | 119 | $this->_statement = $this->getConnection()->getPdoInstance()->prepare($this->getText()); |
120 | 120 | } |
121 | - catch(Exception $e) |
|
121 | + catch (Exception $e) |
|
122 | 122 | { |
123 | 123 | throw new TDbException('dbcommand_prepare_failed', $e->getMessage(), $this->getText()); |
124 | 124 | } |
@@ -149,9 +149,9 @@ discard block |
||
149 | 149 | public function bindParameter($name, &$value, $dataType = null, $length = null) |
150 | 150 | { |
151 | 151 | $this->prepare(); |
152 | - if($dataType === null) |
|
152 | + if ($dataType === null) |
|
153 | 153 | $this->_statement->bindParam($name, $value); |
154 | - elseif($length === null) |
|
154 | + elseif ($length === null) |
|
155 | 155 | $this->_statement->bindParam($name, $value, $dataType); |
156 | 156 | else |
157 | 157 | $this->_statement->bindParam($name, $value, $dataType, $length); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | public function bindValue($name, $value, $dataType = null) |
171 | 171 | { |
172 | 172 | $this->prepare(); |
173 | - if($dataType === null) |
|
173 | + if ($dataType === null) |
|
174 | 174 | $this->_statement->bindValue($name, $value); |
175 | 175 | else |
176 | 176 | $this->_statement->bindValue($name, $value, $dataType); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | { |
190 | 190 | // Do not trace because it will remain even in Performance mode |
191 | 191 | // Prado::trace('Execute Command: '.$this->getDebugStatementText(), 'Prado\Data'); |
192 | - if($this->_statement instanceof PDOStatement) |
|
192 | + if ($this->_statement instanceof PDOStatement) |
|
193 | 193 | { |
194 | 194 | $this->_statement->execute(); |
195 | 195 | return $this->_statement->rowCount(); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | else |
198 | 198 | return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
199 | 199 | } |
200 | - catch(Exception $e) |
|
200 | + catch (Exception $e) |
|
201 | 201 | { |
202 | 202 | throw new TDbException('dbcommand_execute_failed', $e->getMessage(), $this->getDebugStatementText()); |
203 | 203 | } |
@@ -225,13 +225,13 @@ discard block |
||
225 | 225 | try |
226 | 226 | { |
227 | 227 | // Prado::trace('Query: '.$this->getDebugStatementText(), 'Prado\Data'); |
228 | - if($this->_statement instanceof PDOStatement) |
|
228 | + if ($this->_statement instanceof PDOStatement) |
|
229 | 229 | $this->_statement->execute(); |
230 | 230 | else |
231 | 231 | $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
232 | 232 | return new TDbDataReader($this); |
233 | 233 | } |
234 | - catch(Exception $e) |
|
234 | + catch (Exception $e) |
|
235 | 235 | { |
236 | 236 | throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
237 | 237 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | try |
251 | 251 | { |
252 | 252 | // Prado::trace('Query Row: '.$this->getDebugStatementText(), 'Prado\Data'); |
253 | - if($this->_statement instanceof PDOStatement) |
|
253 | + if ($this->_statement instanceof PDOStatement) |
|
254 | 254 | $this->_statement->execute(); |
255 | 255 | else |
256 | 256 | $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $this->_statement->closeCursor(); |
259 | 259 | return $result; |
260 | 260 | } |
261 | - catch(Exception $e) |
|
261 | + catch (Exception $e) |
|
262 | 262 | { |
263 | 263 | throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
264 | 264 | } |
@@ -276,18 +276,18 @@ discard block |
||
276 | 276 | try |
277 | 277 | { |
278 | 278 | // Prado::trace('Query Scalar: '.$this->getDebugStatementText(), 'Prado\Data'); |
279 | - if($this->_statement instanceof PDOStatement) |
|
279 | + if ($this->_statement instanceof PDOStatement) |
|
280 | 280 | $this->_statement->execute(); |
281 | 281 | else |
282 | 282 | $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
283 | 283 | $result = $this->_statement->fetchColumn(); |
284 | 284 | $this->_statement->closeCursor(); |
285 | - if(is_resource($result) && get_resource_type($result) === 'stream') |
|
285 | + if (is_resource($result) && get_resource_type($result) === 'stream') |
|
286 | 286 | return stream_get_contents($result); |
287 | 287 | else |
288 | 288 | return $result; |
289 | 289 | } |
290 | - catch(Exception $e) |
|
290 | + catch (Exception $e) |
|
291 | 291 | { |
292 | 292 | throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
293 | 293 | } |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | { |
306 | 306 | $rows = $this->query()->readAll(); |
307 | 307 | $column = []; |
308 | - foreach($rows as $row) |
|
308 | + foreach ($rows as $row) |
|
309 | 309 | $column[] = current($row); |
310 | 310 | return $column; |
311 | 311 | } |
@@ -117,8 +117,7 @@ discard block |
||
117 | 117 | try |
118 | 118 | { |
119 | 119 | $this->_statement = $this->getConnection()->getPdoInstance()->prepare($this->getText()); |
120 | - } |
|
121 | - catch(Exception $e) |
|
120 | + } catch(Exception $e) |
|
122 | 121 | { |
123 | 122 | throw new TDbException('dbcommand_prepare_failed', $e->getMessage(), $this->getText()); |
124 | 123 | } |
@@ -149,12 +148,13 @@ discard block |
||
149 | 148 | public function bindParameter($name, &$value, $dataType = null, $length = null) |
150 | 149 | { |
151 | 150 | $this->prepare(); |
152 | - if($dataType === null) |
|
153 | - $this->_statement->bindParam($name, $value); |
|
154 | - elseif($length === null) |
|
155 | - $this->_statement->bindParam($name, $value, $dataType); |
|
156 | - else |
|
157 | - $this->_statement->bindParam($name, $value, $dataType, $length); |
|
151 | + if($dataType === null) { |
|
152 | + $this->_statement->bindParam($name, $value); |
|
153 | + } elseif($length === null) { |
|
154 | + $this->_statement->bindParam($name, $value, $dataType); |
|
155 | + } else { |
|
156 | + $this->_statement->bindParam($name, $value, $dataType, $length); |
|
157 | + } |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -170,10 +170,11 @@ discard block |
||
170 | 170 | public function bindValue($name, $value, $dataType = null) |
171 | 171 | { |
172 | 172 | $this->prepare(); |
173 | - if($dataType === null) |
|
174 | - $this->_statement->bindValue($name, $value); |
|
175 | - else |
|
176 | - $this->_statement->bindValue($name, $value, $dataType); |
|
173 | + if($dataType === null) { |
|
174 | + $this->_statement->bindValue($name, $value); |
|
175 | + } else { |
|
176 | + $this->_statement->bindValue($name, $value, $dataType); |
|
177 | + } |
|
177 | 178 | } |
178 | 179 | |
179 | 180 | /** |
@@ -193,11 +194,10 @@ discard block |
||
193 | 194 | { |
194 | 195 | $this->_statement->execute(); |
195 | 196 | return $this->_statement->rowCount(); |
197 | + } else { |
|
198 | + return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
|
196 | 199 | } |
197 | - else |
|
198 | - return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
|
199 | - } |
|
200 | - catch(Exception $e) |
|
200 | + } catch(Exception $e) |
|
201 | 201 | { |
202 | 202 | throw new TDbException('dbcommand_execute_failed', $e->getMessage(), $this->getDebugStatementText()); |
203 | 203 | } |
@@ -225,13 +225,13 @@ discard block |
||
225 | 225 | try |
226 | 226 | { |
227 | 227 | // Prado::trace('Query: '.$this->getDebugStatementText(), 'Prado\Data'); |
228 | - if($this->_statement instanceof PDOStatement) |
|
229 | - $this->_statement->execute(); |
|
230 | - else |
|
231 | - $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
228 | + if($this->_statement instanceof PDOStatement) { |
|
229 | + $this->_statement->execute(); |
|
230 | + } else { |
|
231 | + $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
232 | + } |
|
232 | 233 | return new TDbDataReader($this); |
233 | - } |
|
234 | - catch(Exception $e) |
|
234 | + } catch(Exception $e) |
|
235 | 235 | { |
236 | 236 | throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
237 | 237 | } |
@@ -250,15 +250,15 @@ discard block |
||
250 | 250 | try |
251 | 251 | { |
252 | 252 | // Prado::trace('Query Row: '.$this->getDebugStatementText(), 'Prado\Data'); |
253 | - if($this->_statement instanceof PDOStatement) |
|
254 | - $this->_statement->execute(); |
|
255 | - else |
|
256 | - $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
253 | + if($this->_statement instanceof PDOStatement) { |
|
254 | + $this->_statement->execute(); |
|
255 | + } else { |
|
256 | + $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
257 | + } |
|
257 | 258 | $result = $this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
258 | 259 | $this->_statement->closeCursor(); |
259 | 260 | return $result; |
260 | - } |
|
261 | - catch(Exception $e) |
|
261 | + } catch(Exception $e) |
|
262 | 262 | { |
263 | 263 | throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
264 | 264 | } |
@@ -276,18 +276,19 @@ discard block |
||
276 | 276 | try |
277 | 277 | { |
278 | 278 | // Prado::trace('Query Scalar: '.$this->getDebugStatementText(), 'Prado\Data'); |
279 | - if($this->_statement instanceof PDOStatement) |
|
280 | - $this->_statement->execute(); |
|
281 | - else |
|
282 | - $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
279 | + if($this->_statement instanceof PDOStatement) { |
|
280 | + $this->_statement->execute(); |
|
281 | + } else { |
|
282 | + $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
283 | + } |
|
283 | 284 | $result = $this->_statement->fetchColumn(); |
284 | 285 | $this->_statement->closeCursor(); |
285 | - if(is_resource($result) && get_resource_type($result) === 'stream') |
|
286 | - return stream_get_contents($result); |
|
287 | - else |
|
288 | - return $result; |
|
289 | - } |
|
290 | - catch(Exception $e) |
|
286 | + if(is_resource($result) && get_resource_type($result) === 'stream') { |
|
287 | + return stream_get_contents($result); |
|
288 | + } else { |
|
289 | + return $result; |
|
290 | + } |
|
291 | + } catch(Exception $e) |
|
291 | 292 | { |
292 | 293 | throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
293 | 294 | } |
@@ -305,8 +306,9 @@ discard block |
||
305 | 306 | { |
306 | 307 | $rows = $this->query()->readAll(); |
307 | 308 | $column = []; |
308 | - foreach($rows as $row) |
|
309 | - $column[] = current($row); |
|
309 | + foreach($rows as $row) { |
|
310 | + $column[] = current($row); |
|
311 | + } |
|
310 | 312 | return $column; |
311 | 313 | } |
312 | 314 | } |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function __construct($condition = null, $parameters = []) |
55 | 55 | { |
56 | - if(!is_array($parameters) && func_num_args() > 1) |
|
56 | + if (!is_array($parameters) && func_num_args() > 1) |
|
57 | 57 | $parameters = array_slice(func_get_args(), 1); |
58 | 58 | $this->_parameters = new TAttributeCollection; |
59 | 59 | $this->_parameters->setCaseSensitive(true); |
60 | - $this->_parameters->copyFrom((array)$parameters); |
|
60 | + $this->_parameters->copyFrom((array) $parameters); |
|
61 | 61 | $this->_ordersBy = new TAttributeCollection; |
62 | 62 | $this->_ordersBy->setCaseSensitive(true); |
63 | 63 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function setCondition($value) |
134 | 134 | { |
135 | - if(empty($value)) { |
|
135 | + if (empty($value)) { |
|
136 | 136 | // reset the condition |
137 | 137 | $this->_condition = null; |
138 | 138 | return; |
@@ -144,32 +144,32 @@ discard block |
||
144 | 144 | // [LIMIT {[offset,] row_count | row_count OFFSET offset}] |
145 | 145 | // See: http://dev.mysql.com/doc/refman/5.0/en/select.html |
146 | 146 | |
147 | - if(preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) { |
|
147 | + if (preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) { |
|
148 | 148 | // condition contains ORDER BY |
149 | 149 | $value = str_replace($matches[0], '', $value); |
150 | - if(strlen($matches[1]) > 0) { |
|
150 | + if (strlen($matches[1]) > 0) { |
|
151 | 151 | $this->setOrdersBy($matches[1]); |
152 | - } elseif(strlen($matches[2]) > 0) { |
|
152 | + } elseif (strlen($matches[2]) > 0) { |
|
153 | 153 | $this->setOrdersBy($matches[2]); |
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - if(preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) { |
|
157 | + if (preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) { |
|
158 | 158 | // condition contains limit |
159 | 159 | $value = str_replace($matches[0], '', $value); // remove limit from query |
160 | - if(strpos($matches[1], ',')) { // both offset and limit given |
|
160 | + if (strpos($matches[1], ',')) { // both offset and limit given |
|
161 | 161 | list($offset, $limit) = explode(',', $matches[1]); |
162 | - $this->_limit = (int)$limit; |
|
163 | - $this->_offset = (int)$offset; |
|
162 | + $this->_limit = (int) $limit; |
|
163 | + $this->_offset = (int) $offset; |
|
164 | 164 | } else { // only limit given |
165 | - $this->_limit = (int)$matches[1]; |
|
165 | + $this->_limit = (int) $matches[1]; |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - if(preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) { |
|
169 | + if (preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) { |
|
170 | 170 | // condition contains offset |
171 | 171 | $value = str_replace($matches[0], '', $value); // remove offset from query |
172 | - $this->_offset = (int)$matches[1]; // set offset in criteria |
|
172 | + $this->_offset = (int) $matches[1]; // set offset in criteria |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $this->_condition = trim($value); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function setParameters($value) |
190 | 190 | { |
191 | - if(!(is_array($value) || $value instanceof \ArrayAccess)) |
|
191 | + if (!(is_array($value) || $value instanceof \ArrayAccess)) |
|
192 | 192 | throw new TException('value must be array or \ArrayAccess'); |
193 | 193 | $this->_parameters->copyFrom($value); |
194 | 194 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function getIsNamedParameters() |
200 | 200 | { |
201 | - foreach($this->getParameters() as $k => $v) |
|
201 | + foreach ($this->getParameters() as $k => $v) |
|
202 | 202 | return is_string($k); |
203 | 203 | } |
204 | 204 | |
@@ -215,16 +215,16 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function setOrdersBy($value) |
217 | 217 | { |
218 | - if(is_array($value) || $value instanceof Traversable) |
|
218 | + if (is_array($value) || $value instanceof Traversable) |
|
219 | 219 | $this->_ordersBy->copyFrom($value); |
220 | 220 | else |
221 | 221 | { |
222 | - $value = trim(preg_replace('/\s+/', ' ', (string)$value)); |
|
222 | + $value = trim(preg_replace('/\s+/', ' ', (string) $value)); |
|
223 | 223 | $orderBys = []; |
224 | - foreach(explode(',', $value) as $orderBy) |
|
224 | + foreach (explode(',', $value) as $orderBy) |
|
225 | 225 | { |
226 | 226 | $vs = explode(' ', trim($orderBy)); |
227 | - $orderBys[$vs[0]] = isset($vs[1])?$vs[1]:'asc'; |
|
227 | + $orderBys[$vs[0]] = isset($vs[1]) ? $vs[1] : 'asc'; |
|
228 | 228 | } |
229 | 229 | $this->_ordersBy->copyFrom($orderBys); |
230 | 230 | } |
@@ -268,22 +268,22 @@ discard block |
||
268 | 268 | public function __toString() |
269 | 269 | { |
270 | 270 | $str = ''; |
271 | - if(strlen((string)$this->getCondition()) > 0) |
|
272 | - $str .= '"' . (string)$this->getCondition() . '"'; |
|
271 | + if (strlen((string) $this->getCondition()) > 0) |
|
272 | + $str .= '"'.(string) $this->getCondition().'"'; |
|
273 | 273 | $params = []; |
274 | - foreach($this->getParameters() as $k => $v) |
|
274 | + foreach ($this->getParameters() as $k => $v) |
|
275 | 275 | $params[] = "{$k} => ${v}"; |
276 | - if(count($params) > 0) |
|
277 | - $str .= ', "' . implode(', ', $params) . '"'; |
|
276 | + if (count($params) > 0) |
|
277 | + $str .= ', "'.implode(', ', $params).'"'; |
|
278 | 278 | $orders = []; |
279 | - foreach($this->getOrdersBy() as $k => $v) |
|
279 | + foreach ($this->getOrdersBy() as $k => $v) |
|
280 | 280 | $orders[] = "{$k} => ${v}"; |
281 | - if(count($orders) > 0) |
|
282 | - $str .= ', "' . implode(', ', $orders) . '"'; |
|
283 | - if($this->_limit !== null) |
|
284 | - $str .= ', ' . $this->_limit; |
|
285 | - if($this->_offset !== null) |
|
286 | - $str .= ', ' . $this->_offset; |
|
281 | + if (count($orders) > 0) |
|
282 | + $str .= ', "'.implode(', ', $orders).'"'; |
|
283 | + if ($this->_limit !== null) |
|
284 | + $str .= ', '.$this->_limit; |
|
285 | + if ($this->_offset !== null) |
|
286 | + $str .= ', '.$this->_offset; |
|
287 | 287 | return $str; |
288 | 288 | } |
289 | 289 | } |
@@ -53,8 +53,9 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function __construct($condition = null, $parameters = []) |
55 | 55 | { |
56 | - if(!is_array($parameters) && func_num_args() > 1) |
|
57 | - $parameters = array_slice(func_get_args(), 1); |
|
56 | + if(!is_array($parameters) && func_num_args() > 1) { |
|
57 | + $parameters = array_slice(func_get_args(), 1); |
|
58 | + } |
|
58 | 59 | $this->_parameters = new TAttributeCollection; |
59 | 60 | $this->_parameters->setCaseSensitive(true); |
60 | 61 | $this->_parameters->copyFrom((array)$parameters); |
@@ -188,8 +189,9 @@ discard block |
||
188 | 189 | */ |
189 | 190 | public function setParameters($value) |
190 | 191 | { |
191 | - if(!(is_array($value) || $value instanceof \ArrayAccess)) |
|
192 | - throw new TException('value must be array or \ArrayAccess'); |
|
192 | + if(!(is_array($value) || $value instanceof \ArrayAccess)) { |
|
193 | + throw new TException('value must be array or \ArrayAccess'); |
|
194 | + } |
|
193 | 195 | $this->_parameters->copyFrom($value); |
194 | 196 | } |
195 | 197 | |
@@ -198,8 +200,9 @@ discard block |
||
198 | 200 | */ |
199 | 201 | public function getIsNamedParameters() |
200 | 202 | { |
201 | - foreach($this->getParameters() as $k => $v) |
|
202 | - return is_string($k); |
|
203 | + foreach($this->getParameters() as $k => $v) { |
|
204 | + return is_string($k); |
|
205 | + } |
|
203 | 206 | } |
204 | 207 | |
205 | 208 | /** |
@@ -215,9 +218,9 @@ discard block |
||
215 | 218 | */ |
216 | 219 | public function setOrdersBy($value) |
217 | 220 | { |
218 | - if(is_array($value) || $value instanceof Traversable) |
|
219 | - $this->_ordersBy->copyFrom($value); |
|
220 | - else |
|
221 | + if(is_array($value) || $value instanceof Traversable) { |
|
222 | + $this->_ordersBy->copyFrom($value); |
|
223 | + } else |
|
221 | 224 | { |
222 | 225 | $value = trim(preg_replace('/\s+/', ' ', (string)$value)); |
223 | 226 | $orderBys = []; |
@@ -268,22 +271,29 @@ discard block |
||
268 | 271 | public function __toString() |
269 | 272 | { |
270 | 273 | $str = ''; |
271 | - if(strlen((string)$this->getCondition()) > 0) |
|
272 | - $str .= '"' . (string)$this->getCondition() . '"'; |
|
274 | + if(strlen((string)$this->getCondition()) > 0) { |
|
275 | + $str .= '"' . (string)$this->getCondition() . '"'; |
|
276 | + } |
|
273 | 277 | $params = []; |
274 | - foreach($this->getParameters() as $k => $v) |
|
275 | - $params[] = "{$k} => ${v}"; |
|
276 | - if(count($params) > 0) |
|
277 | - $str .= ', "' . implode(', ', $params) . '"'; |
|
278 | + foreach($this->getParameters() as $k => $v) { |
|
279 | + $params[] = "{$k} => ${v}"; |
|
280 | + } |
|
281 | + if(count($params) > 0) { |
|
282 | + $str .= ', "' . implode(', ', $params) . '"'; |
|
283 | + } |
|
278 | 284 | $orders = []; |
279 | - foreach($this->getOrdersBy() as $k => $v) |
|
280 | - $orders[] = "{$k} => ${v}"; |
|
281 | - if(count($orders) > 0) |
|
282 | - $str .= ', "' . implode(', ', $orders) . '"'; |
|
283 | - if($this->_limit !== null) |
|
284 | - $str .= ', ' . $this->_limit; |
|
285 | - if($this->_offset !== null) |
|
286 | - $str .= ', ' . $this->_offset; |
|
285 | + foreach($this->getOrdersBy() as $k => $v) { |
|
286 | + $orders[] = "{$k} => ${v}"; |
|
287 | + } |
|
288 | + if(count($orders) > 0) { |
|
289 | + $str .= ', "' . implode(', ', $orders) . '"'; |
|
290 | + } |
|
291 | + if($this->_limit !== null) { |
|
292 | + $str .= ', ' . $this->_limit; |
|
293 | + } |
|
294 | + if($this->_offset !== null) { |
|
295 | + $str .= ', ' . $this->_offset; |
|
296 | + } |
|
287 | 297 | return $str; |
288 | 298 | } |
289 | 299 | } |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | public function __construct($table, $connection) |
94 | 94 | { |
95 | 95 | $this->_connection = $connection; |
96 | - if(is_string($table)) |
|
96 | + if (is_string($table)) |
|
97 | 97 | $this->setTableName($table); |
98 | - elseif($table instanceof TDbTableInfo) |
|
98 | + elseif ($table instanceof TDbTableInfo) |
|
99 | 99 | $this->setTableInfo($table); |
100 | 100 | else |
101 | 101 | throw new TDbException('dbtablegateway_invalid_table_info'); |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | public function findAll($criteria = null, $parameters = []) |
243 | 243 | { |
244 | 244 | $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
245 | - if($criteria !== null) |
|
245 | + if ($criteria !== null) |
|
246 | 246 | $criteria = $this->getCriteria($criteria, $parameters, $args); |
247 | 247 | return $this->getCommand()->findAll($criteria); |
248 | 248 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function findByPk($keys) |
263 | 263 | { |
264 | - if(func_num_args() > 1) |
|
264 | + if (func_num_args() > 1) |
|
265 | 265 | $keys = func_get_args(); |
266 | 266 | return $this->getCommand()->findByPk($keys); |
267 | 267 | } |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public function findAllByPks($keys) |
287 | 287 | { |
288 | - if(func_num_args() > 1) |
|
288 | + if (func_num_args() > 1) |
|
289 | 289 | $keys = func_get_args(); |
290 | 290 | return $this->getCommand()->findAllByPk($keys); |
291 | 291 | } |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | */ |
334 | 334 | public function deleteByPk($keys) |
335 | 335 | { |
336 | - if(func_num_args() > 1) |
|
336 | + if (func_num_args() > 1) |
|
337 | 337 | $keys = func_get_args(); |
338 | 338 | return $this->getCommand()->deleteByPk($keys); |
339 | 339 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | */ |
344 | 344 | public function deleteAllByPks($keys) |
345 | 345 | { |
346 | - if(func_num_args() > 1) |
|
346 | + if (func_num_args() > 1) |
|
347 | 347 | $keys = func_get_args(); |
348 | 348 | return $this->deleteByPk($keys); |
349 | 349 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | public function count($criteria = null, $parameters = []) |
358 | 358 | { |
359 | 359 | $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
360 | - if($criteria !== null) |
|
360 | + if ($criteria !== null) |
|
361 | 361 | $criteria = $this->getCriteria($criteria, $parameters, $args); |
362 | 362 | return $this->getCommand()->count($criteria); |
363 | 363 | } |
@@ -414,12 +414,12 @@ discard block |
||
414 | 414 | */ |
415 | 415 | protected function getCriteria($criteria, $parameters, $args) |
416 | 416 | { |
417 | - if(is_string($criteria)) |
|
417 | + if (is_string($criteria)) |
|
418 | 418 | { |
419 | 419 | $useArgs = !is_array($parameters) && is_array($args); |
420 | 420 | return new TSqlCriteria($criteria, $useArgs ? $args : $parameters); |
421 | 421 | } |
422 | - elseif($criteria instanceof TSqlCriteria) |
|
422 | + elseif ($criteria instanceof TSqlCriteria) |
|
423 | 423 | return $criteria; |
424 | 424 | else |
425 | 425 | throw new TDbException('dbtablegateway_invalid_criteria'); |
@@ -457,19 +457,19 @@ discard block |
||
457 | 457 | public function __call($method, $args) |
458 | 458 | { |
459 | 459 | $delete = false; |
460 | - if($findOne = substr(strtolower($method), 0, 6) === 'findby') |
|
460 | + if ($findOne = substr(strtolower($method), 0, 6) === 'findby') |
|
461 | 461 | $condition = $method[6] === '_' ? substr($method, 7) : substr($method, 6); |
462 | - elseif(substr(strtolower($method), 0, 9) === 'findallby') |
|
462 | + elseif (substr(strtolower($method), 0, 9) === 'findallby') |
|
463 | 463 | $condition = $method[9] === '_' ? substr($method, 10) : substr($method, 9); |
464 | - elseif($delete = substr(strtolower($method), 0, 8) === 'deleteby') |
|
464 | + elseif ($delete = substr(strtolower($method), 0, 8) === 'deleteby') |
|
465 | 465 | $condition = $method[8] === '_' ? substr($method, 9) : substr($method, 8); |
466 | - elseif($delete = substr(strtolower($method), 0, 11) === 'deleteallby') |
|
466 | + elseif ($delete = substr(strtolower($method), 0, 11) === 'deleteallby') |
|
467 | 467 | $condition = $method[11] === '_' ? substr($method, 12) : substr($method, 11); |
468 | 468 | else |
469 | 469 | return null; |
470 | 470 | |
471 | 471 | $criteria = $this->getCommand()->createCriteriaFromString($method, $condition, $args); |
472 | - if($delete) |
|
472 | + if ($delete) |
|
473 | 473 | return $this->deleteAll($criteria); |
474 | 474 | else |
475 | 475 | return $findOne ? $this->find($criteria) : $this->findAll($criteria); |
@@ -93,12 +93,13 @@ discard block |
||
93 | 93 | public function __construct($table, $connection) |
94 | 94 | { |
95 | 95 | $this->_connection = $connection; |
96 | - if(is_string($table)) |
|
97 | - $this->setTableName($table); |
|
98 | - elseif($table instanceof TDbTableInfo) |
|
99 | - $this->setTableInfo($table); |
|
100 | - else |
|
101 | - throw new TDbException('dbtablegateway_invalid_table_info'); |
|
96 | + if(is_string($table)) { |
|
97 | + $this->setTableName($table); |
|
98 | + } elseif($table instanceof TDbTableInfo) { |
|
99 | + $this->setTableInfo($table); |
|
100 | + } else { |
|
101 | + throw new TDbException('dbtablegateway_invalid_table_info'); |
|
102 | + } |
|
102 | 103 | } |
103 | 104 | |
104 | 105 | /** |
@@ -242,8 +243,9 @@ discard block |
||
242 | 243 | public function findAll($criteria = null, $parameters = []) |
243 | 244 | { |
244 | 245 | $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
245 | - if($criteria !== null) |
|
246 | - $criteria = $this->getCriteria($criteria, $parameters, $args); |
|
246 | + if($criteria !== null) { |
|
247 | + $criteria = $this->getCriteria($criteria, $parameters, $args); |
|
248 | + } |
|
247 | 249 | return $this->getCommand()->findAll($criteria); |
248 | 250 | } |
249 | 251 | |
@@ -261,8 +263,9 @@ discard block |
||
261 | 263 | */ |
262 | 264 | public function findByPk($keys) |
263 | 265 | { |
264 | - if(func_num_args() > 1) |
|
265 | - $keys = func_get_args(); |
|
266 | + if(func_num_args() > 1) { |
|
267 | + $keys = func_get_args(); |
|
268 | + } |
|
266 | 269 | return $this->getCommand()->findByPk($keys); |
267 | 270 | } |
268 | 271 | |
@@ -285,8 +288,9 @@ discard block |
||
285 | 288 | */ |
286 | 289 | public function findAllByPks($keys) |
287 | 290 | { |
288 | - if(func_num_args() > 1) |
|
289 | - $keys = func_get_args(); |
|
291 | + if(func_num_args() > 1) { |
|
292 | + $keys = func_get_args(); |
|
293 | + } |
|
290 | 294 | return $this->getCommand()->findAllByPk($keys); |
291 | 295 | } |
292 | 296 | |
@@ -333,8 +337,9 @@ discard block |
||
333 | 337 | */ |
334 | 338 | public function deleteByPk($keys) |
335 | 339 | { |
336 | - if(func_num_args() > 1) |
|
337 | - $keys = func_get_args(); |
|
340 | + if(func_num_args() > 1) { |
|
341 | + $keys = func_get_args(); |
|
342 | + } |
|
338 | 343 | return $this->getCommand()->deleteByPk($keys); |
339 | 344 | } |
340 | 345 | |
@@ -343,8 +348,9 @@ discard block |
||
343 | 348 | */ |
344 | 349 | public function deleteAllByPks($keys) |
345 | 350 | { |
346 | - if(func_num_args() > 1) |
|
347 | - $keys = func_get_args(); |
|
351 | + if(func_num_args() > 1) { |
|
352 | + $keys = func_get_args(); |
|
353 | + } |
|
348 | 354 | return $this->deleteByPk($keys); |
349 | 355 | } |
350 | 356 | |
@@ -357,8 +363,9 @@ discard block |
||
357 | 363 | public function count($criteria = null, $parameters = []) |
358 | 364 | { |
359 | 365 | $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
360 | - if($criteria !== null) |
|
361 | - $criteria = $this->getCriteria($criteria, $parameters, $args); |
|
366 | + if($criteria !== null) { |
|
367 | + $criteria = $this->getCriteria($criteria, $parameters, $args); |
|
368 | + } |
|
362 | 369 | return $this->getCommand()->count($criteria); |
363 | 370 | } |
364 | 371 | |
@@ -418,11 +425,11 @@ discard block |
||
418 | 425 | { |
419 | 426 | $useArgs = !is_array($parameters) && is_array($args); |
420 | 427 | return new TSqlCriteria($criteria, $useArgs ? $args : $parameters); |
428 | + } elseif($criteria instanceof TSqlCriteria) { |
|
429 | + return $criteria; |
|
430 | + } else { |
|
431 | + throw new TDbException('dbtablegateway_invalid_criteria'); |
|
421 | 432 | } |
422 | - elseif($criteria instanceof TSqlCriteria) |
|
423 | - return $criteria; |
|
424 | - else |
|
425 | - throw new TDbException('dbtablegateway_invalid_criteria'); |
|
426 | 433 | } |
427 | 434 | |
428 | 435 | /** |
@@ -457,22 +464,24 @@ discard block |
||
457 | 464 | public function __call($method, $args) |
458 | 465 | { |
459 | 466 | $delete = false; |
460 | - if($findOne = substr(strtolower($method), 0, 6) === 'findby') |
|
461 | - $condition = $method[6] === '_' ? substr($method, 7) : substr($method, 6); |
|
462 | - elseif(substr(strtolower($method), 0, 9) === 'findallby') |
|
463 | - $condition = $method[9] === '_' ? substr($method, 10) : substr($method, 9); |
|
464 | - elseif($delete = substr(strtolower($method), 0, 8) === 'deleteby') |
|
465 | - $condition = $method[8] === '_' ? substr($method, 9) : substr($method, 8); |
|
466 | - elseif($delete = substr(strtolower($method), 0, 11) === 'deleteallby') |
|
467 | - $condition = $method[11] === '_' ? substr($method, 12) : substr($method, 11); |
|
468 | - else |
|
469 | - return null; |
|
467 | + if($findOne = substr(strtolower($method), 0, 6) === 'findby') { |
|
468 | + $condition = $method[6] === '_' ? substr($method, 7) : substr($method, 6); |
|
469 | + } elseif(substr(strtolower($method), 0, 9) === 'findallby') { |
|
470 | + $condition = $method[9] === '_' ? substr($method, 10) : substr($method, 9); |
|
471 | + } elseif($delete = substr(strtolower($method), 0, 8) === 'deleteby') { |
|
472 | + $condition = $method[8] === '_' ? substr($method, 9) : substr($method, 8); |
|
473 | + } elseif($delete = substr(strtolower($method), 0, 11) === 'deleteallby') { |
|
474 | + $condition = $method[11] === '_' ? substr($method, 12) : substr($method, 11); |
|
475 | + } else { |
|
476 | + return null; |
|
477 | + } |
|
470 | 478 | |
471 | 479 | $criteria = $this->getCommand()->createCriteriaFromString($method, $condition, $args); |
472 | - if($delete) |
|
473 | - return $this->deleteAll($criteria); |
|
474 | - else |
|
475 | - return $findOne ? $this->find($criteria) : $this->findAll($criteria); |
|
480 | + if($delete) { |
|
481 | + return $this->deleteAll($criteria); |
|
482 | + } else { |
|
483 | + return $findOne ? $this->find($criteria) : $this->findAll($criteria); |
|
484 | + } |
|
476 | 485 | } |
477 | 486 | } |
478 | 487 |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function updateByPk($data, $keys) |
105 | 105 | { |
106 | - list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); |
|
106 | + list($where, $parameters) = $this->getPrimaryKeyCondition((array) $keys); |
|
107 | 107 | return $this->update($data, new TSqlCriteria($where, $parameters)); |
108 | 108 | } |
109 | 109 | /** |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function getFindCommand($criteria) |
135 | 135 | { |
136 | - if($criteria === null) |
|
136 | + if ($criteria === null) |
|
137 | 137 | return $this->getBuilder()->createFindCommand(); |
138 | 138 | $where = $criteria->getCondition(); |
139 | 139 | $parameters = $criteria->getParameters()->toArray(); |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function findByPk($keys) |
153 | 153 | { |
154 | - if($keys === null) |
|
154 | + if ($keys === null) |
|
155 | 155 | return null; |
156 | - list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); |
|
156 | + list($where, $parameters) = $this->getPrimaryKeyCondition((array) $keys); |
|
157 | 157 | $command = $this->getBuilder()->createFindCommand($where, $parameters); |
158 | 158 | $this->onCreateCommand($command, new TSqlCriteria($where, $parameters)); |
159 | 159 | return $this->onExecuteCommand($command, $command->queryRow()); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function findAllByPk($keys) |
166 | 166 | { |
167 | - $where = $this->getCompositeKeyCondition((array)$keys); |
|
167 | + $where = $this->getCompositeKeyCondition((array) $keys); |
|
168 | 168 | $command = $this->getBuilder()->createFindCommand($where); |
169 | 169 | $this->onCreateCommand($command, new TSqlCriteria($where, $keys)); |
170 | 170 | return $this->onExecuteCommand($command, $command->query()); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | public function findAllByIndex($criteria, $fields, $values) |
173 | 173 | { |
174 | 174 | $index = $this->getIndexKeyCondition($this->getTableInfo(), $fields, $values); |
175 | - if(strlen($where = $criteria->getCondition()) > 0) |
|
175 | + if (strlen($where = $criteria->getCondition()) > 0) |
|
176 | 176 | $criteria->setCondition("({$index}) AND ({$where})"); |
177 | 177 | else |
178 | 178 | $criteria->setCondition($index); |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function deleteByPk($keys) |
189 | 189 | { |
190 | - if(count($keys) == 0) |
|
190 | + if (count($keys) == 0) |
|
191 | 191 | return 0; |
192 | - $where = $this->getCompositeKeyCondition((array)$keys); |
|
192 | + $where = $this->getCompositeKeyCondition((array) $keys); |
|
193 | 193 | $command = $this->getBuilder()->createDeleteCommand($where); |
194 | 194 | $this->onCreateCommand($command, new TSqlCriteria($where, $keys)); |
195 | 195 | $command->prepare(); |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | return 'FALSE'; |
203 | 203 | $columns = []; |
204 | 204 | $tableName = $table->getTableFullName(); |
205 | - foreach($fields as $field) |
|
206 | - $columns[] = $tableName . '.' . $table->getColumn($field)->getColumnName(); |
|
207 | - return '(' . implode(', ', $columns) . ') IN ' . $this->quoteTuple($values); |
|
205 | + foreach ($fields as $field) |
|
206 | + $columns[] = $tableName.'.'.$table->getColumn($field)->getColumnName(); |
|
207 | + return '('.implode(', ', $columns).') IN '.$this->quoteTuple($values); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -216,19 +216,19 @@ discard block |
||
216 | 216 | { |
217 | 217 | $primary = $this->getTableInfo()->getPrimaryKeys(); |
218 | 218 | $count = count($primary); |
219 | - if($count === 0) |
|
219 | + if ($count === 0) |
|
220 | 220 | { |
221 | 221 | throw new TDbException('dbtablegateway_no_primary_key_found', |
222 | 222 | $this->getTableInfo()->getTableFullName()); |
223 | 223 | } |
224 | - if(!is_array($values) || count($values) === 0) |
|
224 | + if (!is_array($values) || count($values) === 0) |
|
225 | 225 | { |
226 | 226 | throw new TDbException('dbtablegateway_missing_pk_values', |
227 | 227 | $this->getTableInfo()->getTableFullName()); |
228 | 228 | } |
229 | - if($count > 1 && (!isset($values[0]) || !is_array($values[0]))) |
|
229 | + if ($count > 1 && (!isset($values[0]) || !is_array($values[0]))) |
|
230 | 230 | $values = [$values]; |
231 | - if($count > 1 && count($values[0]) !== $count) |
|
231 | + if ($count > 1 && count($values[0]) !== $count) |
|
232 | 232 | { |
233 | 233 | throw new TDbException('dbtablegateway_pk_value_count_mismatch', |
234 | 234 | $this->getTableInfo()->getTableFullName()); |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | { |
246 | 246 | $conn = $this->getDbConnection(); |
247 | 247 | $data = []; |
248 | - foreach($array as $k => $v) |
|
248 | + foreach ($array as $k => $v) |
|
249 | 249 | $data[] = is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v); |
250 | - return '(' . implode(', ', $data) . ')'; |
|
250 | + return '('.implode(', ', $data).')'; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | protected function getPrimaryKeyCondition($values) |
259 | 259 | { |
260 | 260 | $primary = $this->getTableInfo()->getPrimaryKeys(); |
261 | - if(count($primary) === 0) |
|
261 | + if (count($primary) === 0) |
|
262 | 262 | { |
263 | 263 | throw new TDbException('dbtablegateway_no_primary_key_found', |
264 | 264 | $this->getTableInfo()->getTableFullName()); |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | $criteria = []; |
267 | 267 | $bindings = []; |
268 | 268 | $i = 0; |
269 | - foreach($primary as $key) |
|
269 | + foreach ($primary as $key) |
|
270 | 270 | { |
271 | 271 | $column = $this->getTableInfo()->getColumn($key)->getColumnName(); |
272 | - $criteria[] = $column . ' = :' . $key; |
|
273 | - $bindings[$key] = isset($values[$key])?$values[$key]:$values[$i++]; |
|
272 | + $criteria[] = $column.' = :'.$key; |
|
273 | + $bindings[$key] = isset($values[$key]) ? $values[$key] : $values[$i++]; |
|
274 | 274 | } |
275 | 275 | return [implode(' AND ', $criteria), $bindings]; |
276 | 276 | } |
@@ -308,9 +308,9 @@ discard block |
||
308 | 308 | $ordering = $criteria->getOrdersBy(); |
309 | 309 | $limit = $criteria->getLimit(); |
310 | 310 | $offset = $criteria->getOffset(); |
311 | - if(count($ordering) > 0) |
|
311 | + if (count($ordering) > 0) |
|
312 | 312 | $sql = $this->getBuilder()->applyOrdering($sql, $ordering); |
313 | - if($limit >= 0 || $offset >= 0) |
|
313 | + if ($limit >= 0 || $offset >= 0) |
|
314 | 314 | $sql = $this->getBuilder()->applyLimitOffset($sql, $limit, $offset); |
315 | 315 | $command = $this->getBuilder()->createCommand($sql); |
316 | 316 | $this->getBuilder()->bindArrayValues($command, $criteria->getParameters()->toArray()); |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | */ |
325 | 325 | public function count($criteria) |
326 | 326 | { |
327 | - if($criteria === null) |
|
328 | - return (int)$this->getBuilder()->createCountCommand()->queryScalar(); |
|
327 | + if ($criteria === null) |
|
328 | + return (int) $this->getBuilder()->createCountCommand()->queryScalar(); |
|
329 | 329 | $where = $criteria->getCondition(); |
330 | 330 | $parameters = $criteria->getParameters()->toArray(); |
331 | 331 | $ordering = $criteria->getOrdersBy(); |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | $offset = $criteria->getOffset(); |
334 | 334 | $command = $this->getBuilder()->createCountCommand($where, $parameters, $ordering, $limit, $offset); |
335 | 335 | $this->onCreateCommand($command, $criteria); |
336 | - return $this->onExecuteCommand($command, (int)$command->queryScalar()); |
|
336 | + return $this->onExecuteCommand($command, (int) $command->queryScalar()); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $command = $this->getBuilder()->createInsertCommand($data); |
349 | 349 | $this->onCreateCommand($command, new TSqlCriteria(null, $data)); |
350 | 350 | $command->prepare(); |
351 | - if($this->onExecuteCommand($command, $command->execute()) > 0) |
|
351 | + if ($this->onExecuteCommand($command, $command->execute()) > 0) |
|
352 | 352 | { |
353 | 353 | $value = $this->getLastInsertId(); |
354 | 354 | return $value !== null ? $value : true; |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | { |
377 | 377 | $fields = $this->extractMatchingConditions($method, $condition); |
378 | 378 | $args = count($args) === 1 && is_array($args[0]) ? $args[0] : $args; |
379 | - if(count($fields) > count($args)) |
|
379 | + if (count($fields) > count($args)) |
|
380 | 380 | { |
381 | 381 | throw new TDbException('dbtablegateway_mismatch_args_exception', |
382 | 382 | $method, count($fields), count($args)); |
@@ -395,21 +395,21 @@ discard block |
||
395 | 395 | { |
396 | 396 | $table = $this->getTableInfo(); |
397 | 397 | $columns = $table->getLowerCaseColumnNames(); |
398 | - $regexp = '/(' . implode('|', array_keys($columns)) . ')(and|_and_|or|_or_)?/i'; |
|
398 | + $regexp = '/('.implode('|', array_keys($columns)).')(and|_and_|or|_or_)?/i'; |
|
399 | 399 | $matches = []; |
400 | - if(!preg_match_all($regexp, strtolower($condition), $matches, PREG_SET_ORDER)) |
|
400 | + if (!preg_match_all($regexp, strtolower($condition), $matches, PREG_SET_ORDER)) |
|
401 | 401 | { |
402 | 402 | throw new TDbException('dbtablegateway_mismatch_column_name', |
403 | 403 | $method, implode(', ', $columns), $table->getTableFullName()); |
404 | 404 | } |
405 | 405 | |
406 | 406 | $fields = []; |
407 | - foreach($matches as $match) |
|
407 | + foreach ($matches as $match) |
|
408 | 408 | { |
409 | 409 | $key = $columns[$match[1]]; |
410 | 410 | $column = $table->getColumn($key)->getColumnName(); |
411 | - $sql = $column . ' = ? '; |
|
412 | - if(count($match) > 2) |
|
411 | + $sql = $column.' = ? '; |
|
412 | + if (count($match) > 2) |
|
413 | 413 | $sql .= strtoupper(str_replace('_', '', $match[2])); |
414 | 414 | $fields[] = $sql; |
415 | 415 | } |
@@ -133,8 +133,9 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function getFindCommand($criteria) |
135 | 135 | { |
136 | - if($criteria === null) |
|
137 | - return $this->getBuilder()->createFindCommand(); |
|
136 | + if($criteria === null) { |
|
137 | + return $this->getBuilder()->createFindCommand(); |
|
138 | + } |
|
138 | 139 | $where = $criteria->getCondition(); |
139 | 140 | $parameters = $criteria->getParameters()->toArray(); |
140 | 141 | $ordering = $criteria->getOrdersBy(); |
@@ -151,8 +152,9 @@ discard block |
||
151 | 152 | */ |
152 | 153 | public function findByPk($keys) |
153 | 154 | { |
154 | - if($keys === null) |
|
155 | - return null; |
|
155 | + if($keys === null) { |
|
156 | + return null; |
|
157 | + } |
|
156 | 158 | list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); |
157 | 159 | $command = $this->getBuilder()->createFindCommand($where, $parameters); |
158 | 160 | $this->onCreateCommand($command, new TSqlCriteria($where, $parameters)); |
@@ -172,10 +174,11 @@ discard block |
||
172 | 174 | public function findAllByIndex($criteria, $fields, $values) |
173 | 175 | { |
174 | 176 | $index = $this->getIndexKeyCondition($this->getTableInfo(), $fields, $values); |
175 | - if(strlen($where = $criteria->getCondition()) > 0) |
|
176 | - $criteria->setCondition("({$index}) AND ({$where})"); |
|
177 | - else |
|
178 | - $criteria->setCondition($index); |
|
177 | + if(strlen($where = $criteria->getCondition()) > 0) { |
|
178 | + $criteria->setCondition("({$index}) AND ({$where})"); |
|
179 | + } else { |
|
180 | + $criteria->setCondition($index); |
|
181 | + } |
|
179 | 182 | $command = $this->getFindCommand($criteria); |
180 | 183 | $this->onCreateCommand($command, $criteria); |
181 | 184 | return $this->onExecuteCommand($command, $command->query()); |
@@ -187,8 +190,9 @@ discard block |
||
187 | 190 | */ |
188 | 191 | public function deleteByPk($keys) |
189 | 192 | { |
190 | - if(count($keys) == 0) |
|
191 | - return 0; |
|
193 | + if(count($keys) == 0) { |
|
194 | + return 0; |
|
195 | + } |
|
192 | 196 | $where = $this->getCompositeKeyCondition((array)$keys); |
193 | 197 | $command = $this->getBuilder()->createDeleteCommand($where); |
194 | 198 | $this->onCreateCommand($command, new TSqlCriteria($where, $keys)); |
@@ -198,12 +202,14 @@ discard block |
||
198 | 202 | |
199 | 203 | public function getIndexKeyCondition($table, $fields, $values) |
200 | 204 | { |
201 | - if (!count($values)) |
|
202 | - return 'FALSE'; |
|
205 | + if (!count($values)) { |
|
206 | + return 'FALSE'; |
|
207 | + } |
|
203 | 208 | $columns = []; |
204 | 209 | $tableName = $table->getTableFullName(); |
205 | - foreach($fields as $field) |
|
206 | - $columns[] = $tableName . '.' . $table->getColumn($field)->getColumnName(); |
|
210 | + foreach($fields as $field) { |
|
211 | + $columns[] = $tableName . '.' . $table->getColumn($field)->getColumnName(); |
|
212 | + } |
|
207 | 213 | return '(' . implode(', ', $columns) . ') IN ' . $this->quoteTuple($values); |
208 | 214 | } |
209 | 215 | |
@@ -226,8 +232,9 @@ discard block |
||
226 | 232 | throw new TDbException('dbtablegateway_missing_pk_values', |
227 | 233 | $this->getTableInfo()->getTableFullName()); |
228 | 234 | } |
229 | - if($count > 1 && (!isset($values[0]) || !is_array($values[0]))) |
|
230 | - $values = [$values]; |
|
235 | + if($count > 1 && (!isset($values[0]) || !is_array($values[0]))) { |
|
236 | + $values = [$values]; |
|
237 | + } |
|
231 | 238 | if($count > 1 && count($values[0]) !== $count) |
232 | 239 | { |
233 | 240 | throw new TDbException('dbtablegateway_pk_value_count_mismatch', |
@@ -245,8 +252,9 @@ discard block |
||
245 | 252 | { |
246 | 253 | $conn = $this->getDbConnection(); |
247 | 254 | $data = []; |
248 | - foreach($array as $k => $v) |
|
249 | - $data[] = is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v); |
|
255 | + foreach($array as $k => $v) { |
|
256 | + $data[] = is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v); |
|
257 | + } |
|
250 | 258 | return '(' . implode(', ', $data) . ')'; |
251 | 259 | } |
252 | 260 | |
@@ -308,10 +316,12 @@ discard block |
||
308 | 316 | $ordering = $criteria->getOrdersBy(); |
309 | 317 | $limit = $criteria->getLimit(); |
310 | 318 | $offset = $criteria->getOffset(); |
311 | - if(count($ordering) > 0) |
|
312 | - $sql = $this->getBuilder()->applyOrdering($sql, $ordering); |
|
313 | - if($limit >= 0 || $offset >= 0) |
|
314 | - $sql = $this->getBuilder()->applyLimitOffset($sql, $limit, $offset); |
|
319 | + if(count($ordering) > 0) { |
|
320 | + $sql = $this->getBuilder()->applyOrdering($sql, $ordering); |
|
321 | + } |
|
322 | + if($limit >= 0 || $offset >= 0) { |
|
323 | + $sql = $this->getBuilder()->applyLimitOffset($sql, $limit, $offset); |
|
324 | + } |
|
315 | 325 | $command = $this->getBuilder()->createCommand($sql); |
316 | 326 | $this->getBuilder()->bindArrayValues($command, $criteria->getParameters()->toArray()); |
317 | 327 | $this->onCreateCommand($command, $criteria); |
@@ -324,8 +334,9 @@ discard block |
||
324 | 334 | */ |
325 | 335 | public function count($criteria) |
326 | 336 | { |
327 | - if($criteria === null) |
|
328 | - return (int)$this->getBuilder()->createCountCommand()->queryScalar(); |
|
337 | + if($criteria === null) { |
|
338 | + return (int)$this->getBuilder()->createCountCommand()->queryScalar(); |
|
339 | + } |
|
329 | 340 | $where = $criteria->getCondition(); |
330 | 341 | $parameters = $criteria->getParameters()->toArray(); |
331 | 342 | $ordering = $criteria->getOrdersBy(); |
@@ -409,8 +420,9 @@ discard block |
||
409 | 420 | $key = $columns[$match[1]]; |
410 | 421 | $column = $table->getColumn($key)->getColumnName(); |
411 | 422 | $sql = $column . ' = ? '; |
412 | - if(count($match) > 2) |
|
413 | - $sql .= strtoupper(str_replace('_', '', $match[2])); |
|
423 | + if(count($match) > 2) { |
|
424 | + $sql .= strtoupper(str_replace('_', '', $match[2])); |
|
425 | + } |
|
414 | 426 | $fields[] = $sql; |
415 | 427 | } |
416 | 428 | return $fields; |
@@ -60,21 +60,21 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function init($xml) |
62 | 62 | { |
63 | - if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
63 | + if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
64 | 64 | { |
65 | - if(isset($xml['database']) && is_array($xml['database'])) |
|
65 | + if (isset($xml['database']) && is_array($xml['database'])) |
|
66 | 66 | { |
67 | 67 | $db = $this->getDbConnection(); |
68 | - foreach($xml['database'] as $name => $value) |
|
68 | + foreach ($xml['database'] as $name => $value) |
|
69 | 69 | $db->setSubProperty($name, $value); |
70 | 70 | } |
71 | 71 | } |
72 | 72 | else |
73 | 73 | { |
74 | - if($prop = $xml->getElementByTagName('database')) |
|
74 | + if ($prop = $xml->getElementByTagName('database')) |
|
75 | 75 | { |
76 | 76 | $db = $this->getDbConnection(); |
77 | - foreach($prop->getAttributes() as $name => $value) |
|
77 | + foreach ($prop->getAttributes() as $name => $value) |
|
78 | 78 | $db->setSubproperty($name, $value); |
79 | 79 | } |
80 | 80 | } |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function getDbConnection() |
109 | 109 | { |
110 | - if($this->_conn === null) |
|
110 | + if ($this->_conn === null) |
|
111 | 111 | { |
112 | - if($this->_connID !== '') |
|
112 | + if ($this->_connID !== '') |
|
113 | 113 | $this->_conn = $this->findConnectionByID($this->getConnectionID()); |
114 | 114 | else |
115 | 115 | $this->_conn = Prado::createComponent($this->getConnectionClass()); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function setConnectionClass($value) |
147 | 147 | { |
148 | - if($this->_conn !== null) |
|
148 | + if ($this->_conn !== null) |
|
149 | 149 | throw new TConfigurationException('datasource_dbconnection_exists', $value); |
150 | 150 | $this->_connClass = $value; |
151 | 151 | } |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | protected function findConnectionByID($id) |
160 | 160 | { |
161 | 161 | $conn = $this->getApplication()->getModule($id); |
162 | - if($conn instanceof TDbConnection) |
|
162 | + if ($conn instanceof TDbConnection) |
|
163 | 163 | return $conn; |
164 | - elseif($conn instanceof TDataSourceConfig) |
|
164 | + elseif ($conn instanceof TDataSourceConfig) |
|
165 | 165 | return $conn->getDbConnection(); |
166 | 166 | else |
167 | 167 | throw new TConfigurationException('datasource_dbconnection_invalid', $id); |
@@ -65,17 +65,18 @@ discard block |
||
65 | 65 | if(isset($xml['database']) && is_array($xml['database'])) |
66 | 66 | { |
67 | 67 | $db = $this->getDbConnection(); |
68 | - foreach($xml['database'] as $name => $value) |
|
69 | - $db->setSubProperty($name, $value); |
|
68 | + foreach($xml['database'] as $name => $value) { |
|
69 | + $db->setSubProperty($name, $value); |
|
70 | + } |
|
70 | 71 | } |
71 | - } |
|
72 | - else |
|
72 | + } else |
|
73 | 73 | { |
74 | 74 | if($prop = $xml->getElementByTagName('database')) |
75 | 75 | { |
76 | 76 | $db = $this->getDbConnection(); |
77 | - foreach($prop->getAttributes() as $name => $value) |
|
78 | - $db->setSubproperty($name, $value); |
|
77 | + foreach($prop->getAttributes() as $name => $value) { |
|
78 | + $db->setSubproperty($name, $value); |
|
79 | + } |
|
79 | 80 | } |
80 | 81 | } |
81 | 82 | } |
@@ -109,10 +110,11 @@ discard block |
||
109 | 110 | { |
110 | 111 | if($this->_conn === null) |
111 | 112 | { |
112 | - if($this->_connID !== '') |
|
113 | - $this->_conn = $this->findConnectionByID($this->getConnectionID()); |
|
114 | - else |
|
115 | - $this->_conn = Prado::createComponent($this->getConnectionClass()); |
|
113 | + if($this->_connID !== '') { |
|
114 | + $this->_conn = $this->findConnectionByID($this->getConnectionID()); |
|
115 | + } else { |
|
116 | + $this->_conn = Prado::createComponent($this->getConnectionClass()); |
|
117 | + } |
|
116 | 118 | } |
117 | 119 | return $this->_conn; |
118 | 120 | } |
@@ -145,8 +147,9 @@ discard block |
||
145 | 147 | */ |
146 | 148 | public function setConnectionClass($value) |
147 | 149 | { |
148 | - if($this->_conn !== null) |
|
149 | - throw new TConfigurationException('datasource_dbconnection_exists', $value); |
|
150 | + if($this->_conn !== null) { |
|
151 | + throw new TConfigurationException('datasource_dbconnection_exists', $value); |
|
152 | + } |
|
150 | 153 | $this->_connClass = $value; |
151 | 154 | } |
152 | 155 | |
@@ -159,11 +162,12 @@ discard block |
||
159 | 162 | protected function findConnectionByID($id) |
160 | 163 | { |
161 | 164 | $conn = $this->getApplication()->getModule($id); |
162 | - if($conn instanceof TDbConnection) |
|
163 | - return $conn; |
|
164 | - elseif($conn instanceof TDataSourceConfig) |
|
165 | - return $conn->getDbConnection(); |
|
166 | - else |
|
167 | - throw new TConfigurationException('datasource_dbconnection_invalid', $id); |
|
165 | + if($conn instanceof TDbConnection) { |
|
166 | + return $conn; |
|
167 | + } elseif($conn instanceof TDataSourceConfig) { |
|
168 | + return $conn->getDbConnection(); |
|
169 | + } else { |
|
170 | + throw new TConfigurationException('datasource_dbconnection_invalid', $id); |
|
171 | + } |
|
168 | 172 | } |
169 | 173 | } |