@@ -38,7 +38,6 @@ discard block |
||
38 | 38 | |
39 | 39 | use RedBeanPHP\Logger as Logger; |
40 | 40 | use RedBeanPHP\RedException as RedException; |
41 | -use RedBeanPHP\RedException\Security as Security; |
|
42 | 41 | |
43 | 42 | /** |
44 | 43 | * Logger. Provides a basic logging function for RedBeanPHP. |
@@ -172,8 +171,6 @@ discard block |
||
172 | 171 | |
173 | 172 | use RedBeanPHP\Logger as Logger; |
174 | 173 | use RedBeanPHP\Logger\RDefault as RDefault; |
175 | -use RedBeanPHP\RedException as RedException; |
|
176 | -use RedBeanPHP\RedException\Security as Security; |
|
177 | 174 | |
178 | 175 | /** |
179 | 176 | * Debug logger. |
@@ -524,7 +521,6 @@ discard block |
||
524 | 521 | use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter; |
525 | 522 | use RedBeanPHP\RedException\SQL as SQL; |
526 | 523 | use RedBeanPHP\Logger\RDefault as RDefault; |
527 | -use RedBeanPHP\PDOCompatible as PDOCompatible; |
|
528 | 524 | use RedBeanPHP\Cursor\PDOCursor as PDOCursor; |
529 | 525 | |
530 | 526 | /** |
@@ -4151,7 +4147,6 @@ discard block |
||
4151 | 4147 | use RedBeanPHP\Adapter\DBAdapter as DBAdapter; |
4152 | 4148 | use RedBeanPHP\RedException as RedException; |
4153 | 4149 | use RedBeanPHP\QueryWriter as QueryWriter; |
4154 | -use RedBeanPHP\OODBBean as OODBBean; |
|
4155 | 4150 | use RedBeanPHP\RedException\SQL as SQLException; |
4156 | 4151 | |
4157 | 4152 | /** |
@@ -6594,17 +6589,13 @@ discard block |
||
6594 | 6589 | namespace RedBeanPHP { |
6595 | 6590 | |
6596 | 6591 | use RedBeanPHP\OODBBean as OODBBean; |
6597 | -use RedBeanPHP\Observable as Observable; |
|
6598 | 6592 | use RedBeanPHP\Adapter\DBAdapter as DBAdapter; |
6599 | -use RedBeanPHP\BeanHelper\FacadeBeanHelper as FacadeBeanHelper; |
|
6600 | 6593 | use RedBeanPHP\QueryWriter as QueryWriter; |
6601 | 6594 | use RedBeanPHP\RedException\Security as Security; |
6602 | 6595 | use RedBeanPHP\SimpleModel as SimpleModel; |
6603 | -use RedBeanPHP\BeanHelper as BeanHelper; |
|
6604 | 6596 | use RedBeanPHP\RedException\SQL as SQLException; |
6605 | 6597 | use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter; |
6606 | 6598 | use RedBeanPHP\OODB as OODB; |
6607 | -use RedBeanPHP\Cursor as Cursor; |
|
6608 | 6599 | use RedBeanPHP\Cursor\NullCursor as NullCursor; |
6609 | 6600 | |
6610 | 6601 | /** |
@@ -7205,16 +7196,10 @@ discard block |
||
7205 | 7196 | namespace RedBeanPHP\Repository { |
7206 | 7197 | |
7207 | 7198 | use RedBeanPHP\OODBBean as OODBBean; |
7208 | -use RedBeanPHP\Observable as Observable; |
|
7209 | -use RedBeanPHP\Adapter\DBAdapter as DBAdapter; |
|
7210 | -use RedBeanPHP\BeanHelper\FacadeBeanHelper as FacadeBeanHelper; |
|
7211 | 7199 | use RedBeanPHP\QueryWriter as QueryWriter; |
7212 | 7200 | use RedBeanPHP\RedException as RedException; |
7213 | 7201 | use RedBeanPHP\RedException\Security as Security; |
7214 | -use RedBeanPHP\SimpleModel as SimpleModel; |
|
7215 | -use RedBeanPHP\BeanHelper as BeanHelper; |
|
7216 | 7202 | use RedBeanPHP\RedException\SQL as SQLException; |
7217 | -use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter; |
|
7218 | 7203 | use RedBeanPHP\Repository as Repository; |
7219 | 7204 | |
7220 | 7205 | /** |
@@ -7530,16 +7515,10 @@ discard block |
||
7530 | 7515 | namespace RedBeanPHP\Repository { |
7531 | 7516 | |
7532 | 7517 | use RedBeanPHP\OODBBean as OODBBean; |
7533 | -use RedBeanPHP\Observable as Observable; |
|
7534 | -use RedBeanPHP\Adapter\DBAdapter as DBAdapter; |
|
7535 | -use RedBeanPHP\BeanHelper\FacadeBeanHelper as FacadeBeanHelper; |
|
7536 | 7518 | use RedBeanPHP\QueryWriter as QueryWriter; |
7537 | 7519 | use RedBeanPHP\RedException as RedException; |
7538 | 7520 | use RedBeanPHP\RedException\Security as Security; |
7539 | -use RedBeanPHP\SimpleModel as SimpleModel; |
|
7540 | -use RedBeanPHP\BeanHelper as BeanHelper; |
|
7541 | 7521 | use RedBeanPHP\RedException\SQL as SQLException; |
7542 | -use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter; |
|
7543 | 7522 | use RedBeanPHP\Repository as Repository; |
7544 | 7523 | |
7545 | 7524 | /** |
@@ -9184,7 +9163,6 @@ discard block |
||
9184 | 9163 | use RedBeanPHP\BeanHelper as BeanHelper; |
9185 | 9164 | use RedBeanPHP\Facade as Facade; |
9186 | 9165 | use RedBeanPHP\OODBBean as OODBBean; |
9187 | -use RedBeanPHP\SimpleModelHelper as SimpleModelHelper; |
|
9188 | 9166 | |
9189 | 9167 | /** |
9190 | 9168 | * Bean Helper. |
@@ -9410,7 +9388,6 @@ discard block |
||
9410 | 9388 | namespace RedBeanPHP { |
9411 | 9389 | |
9412 | 9390 | use RedBeanPHP\Observer as Observer; |
9413 | -use RedBeanPHP\OODBBean as OODBBean; |
|
9414 | 9391 | use RedBeanPHP\Observable as Observable; |
9415 | 9392 | |
9416 | 9393 | /** |
@@ -82,25 +82,25 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function log() |
84 | 84 | { |
85 | - if ( func_num_args() < 1 ) return; |
|
85 | + if (func_num_args() < 1) return; |
|
86 | 86 | |
87 | - foreach ( func_get_args() as $argument ) { |
|
88 | - if ( is_array( $argument ) ) { |
|
89 | - $log = print_r( $argument, TRUE ); |
|
90 | - if ( $this->mode === self::C_LOGGER_ECHO ) { |
|
87 | + foreach (func_get_args() as $argument) { |
|
88 | + if (is_array($argument)) { |
|
89 | + $log = print_r($argument, TRUE); |
|
90 | + if ($this->mode === self::C_LOGGER_ECHO) { |
|
91 | 91 | echo $log; |
92 | 92 | } else { |
93 | 93 | $this->logs[] = $log; |
94 | 94 | } |
95 | 95 | } else { |
96 | - if ( $this->mode === self::C_LOGGER_ECHO ) { |
|
96 | + if ($this->mode === self::C_LOGGER_ECHO) { |
|
97 | 97 | echo $argument; |
98 | 98 | } else { |
99 | 99 | $this->logs[] = $argument; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - if ( $this->mode === self::C_LOGGER_ECHO ) echo "<br>\n"; |
|
103 | + if ($this->mode === self::C_LOGGER_ECHO) echo "<br>\n"; |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return self |
140 | 140 | */ |
141 | - public function setMode( $mode ) |
|
141 | + public function setMode($mode) |
|
142 | 142 | { |
143 | - if ($mode !== self::C_LOGGER_ARRAY && $mode !== self::C_LOGGER_ECHO ) { |
|
144 | - throw new RedException( 'Invalid mode selected for logger, use C_LOGGER_ARRAY or C_LOGGER_ECHO.' ); |
|
143 | + if ($mode !== self::C_LOGGER_ARRAY && $mode !== self::C_LOGGER_ECHO) { |
|
144 | + throw new RedException('Invalid mode selected for logger, use C_LOGGER_ARRAY or C_LOGGER_ECHO.'); |
|
145 | 145 | } |
146 | 146 | $this->mode = $mode; |
147 | 147 | return $this; |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return array |
159 | 159 | */ |
160 | - public function grep( $needle ) |
|
160 | + public function grep($needle) |
|
161 | 161 | { |
162 | 162 | $found = array(); |
163 | - foreach( $this->logs as $logEntry ) { |
|
164 | - if ( strpos( $logEntry, $needle ) !== FALSE ) $found[] = $logEntry; |
|
163 | + foreach ($this->logs as $logEntry) { |
|
164 | + if (strpos($logEntry, $needle) !== FALSE) $found[] = $logEntry; |
|
165 | 165 | } |
166 | 166 | return $found; |
167 | 167 | } |
@@ -205,17 +205,17 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @return string |
207 | 207 | */ |
208 | - private function writeQuery( $newSql, $newBindings ) |
|
208 | + private function writeQuery($newSql, $newBindings) |
|
209 | 209 | { |
210 | 210 | //avoid str_replace collisions: slot1 and slot10 (issue 407). |
211 | - uksort( $newBindings, function( $a, $b ) { |
|
212 | - return ( strlen( $b ) - strlen( $a ) ); |
|
211 | + uksort($newBindings, function($a, $b) { |
|
212 | + return (strlen($b) - strlen($a)); |
|
213 | 213 | } ); |
214 | 214 | |
215 | 215 | $newStr = $newSql; |
216 | - foreach( $newBindings as $slot => $value ) { |
|
217 | - if ( strpos( $slot, ':' ) === 0 ) { |
|
218 | - $newStr = str_replace( $slot, $this->fillInValue( $value ), $newStr ); |
|
216 | + foreach ($newBindings as $slot => $value) { |
|
217 | + if (strpos($slot, ':') === 0) { |
|
218 | + $newStr = str_replace($slot, $this->fillInValue($value), $newStr); |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | return $newStr; |
@@ -229,17 +229,17 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return string |
231 | 231 | */ |
232 | - protected function fillInValue( $value ) |
|
232 | + protected function fillInValue($value) |
|
233 | 233 | { |
234 | - if ( is_null( $value ) ) $value = 'NULL'; |
|
234 | + if (is_null($value)) $value = 'NULL'; |
|
235 | 235 | |
236 | - $value = strval( $value ); |
|
237 | - if ( strlen( $value ) > ( $this->strLen ) ) { |
|
238 | - $value = substr( $value, 0, ( $this->strLen ) ).'... '; |
|
236 | + $value = strval($value); |
|
237 | + if (strlen($value) > ($this->strLen)) { |
|
238 | + $value = substr($value, 0, ($this->strLen)) . '... '; |
|
239 | 239 | } |
240 | 240 | |
241 | - if ( !is_numeric( $value ) && $value !== 'NULL') { |
|
242 | - $value = '\''.$value.'\''; |
|
241 | + if (!is_numeric($value) && $value !== 'NULL') { |
|
242 | + $value = '\'' . $value . '\''; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | return $value; |
@@ -254,10 +254,10 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @return void |
256 | 256 | */ |
257 | - protected function output( $str ) |
|
257 | + protected function output($str) |
|
258 | 258 | { |
259 | 259 | $this->logs[] = $str; |
260 | - if ( !$this->mode ) echo $str .'<br />'; |
|
260 | + if (!$this->mode) echo $str . '<br />'; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @return string |
270 | 270 | */ |
271 | - protected function normalizeSlots( $sql ) |
|
271 | + protected function normalizeSlots($sql) |
|
272 | 272 | { |
273 | 273 | $i = 0; |
274 | 274 | $newSql = $sql; |
275 | - while($i < 20 && strpos($newSql, '?') !== FALSE ){ |
|
276 | - $pos = strpos( $newSql, '?' ); |
|
277 | - $slot = ':slot'.$i; |
|
278 | - $begin = substr( $newSql, 0, $pos ); |
|
279 | - $end = substr( $newSql, $pos+1 ); |
|
275 | + while ($i < 20 && strpos($newSql, '?') !== FALSE) { |
|
276 | + $pos = strpos($newSql, '?'); |
|
277 | + $slot = ':slot' . $i; |
|
278 | + $begin = substr($newSql, 0, $pos); |
|
279 | + $end = substr($newSql, $pos + 1); |
|
280 | 280 | $newSql = $begin . $slot . $end; |
281 | 281 | $i++; |
282 | 282 | } |
@@ -291,13 +291,13 @@ discard block |
||
291 | 291 | * |
292 | 292 | * @return array |
293 | 293 | */ |
294 | - protected function normalizeBindings( $bindings ) |
|
294 | + protected function normalizeBindings($bindings) |
|
295 | 295 | { |
296 | 296 | $i = 0; |
297 | 297 | $newBindings = array(); |
298 | - foreach( $bindings as $key => $value ) { |
|
299 | - if ( is_numeric($key) ) { |
|
300 | - $newKey = ':slot'.$i; |
|
298 | + foreach ($bindings as $key => $value) { |
|
299 | + if (is_numeric($key)) { |
|
300 | + $newKey = ':slot' . $i; |
|
301 | 301 | $newBindings[$newKey] = $value; |
302 | 302 | $i++; |
303 | 303 | } else { |
@@ -317,24 +317,24 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function log() |
319 | 319 | { |
320 | - if ( func_num_args() < 1 ) return; |
|
320 | + if (func_num_args() < 1) return; |
|
321 | 321 | |
322 | - $sql = func_get_arg( 0 ); |
|
322 | + $sql = func_get_arg(0); |
|
323 | 323 | |
324 | - if ( func_num_args() < 2) { |
|
324 | + if (func_num_args() < 2) { |
|
325 | 325 | $bindings = array(); |
326 | 326 | } else { |
327 | - $bindings = func_get_arg( 1 ); |
|
327 | + $bindings = func_get_arg(1); |
|
328 | 328 | } |
329 | 329 | |
330 | - if ( !is_array( $bindings ) ) { |
|
331 | - return $this->output( $sql ); |
|
330 | + if (!is_array($bindings)) { |
|
331 | + return $this->output($sql); |
|
332 | 332 | } |
333 | 333 | |
334 | - $newSql = $this->normalizeSlots( $sql ); |
|
335 | - $newBindings = $this->normalizeBindings( $bindings ); |
|
336 | - $newStr = $this->writeQuery( $newSql, $newBindings ); |
|
337 | - $this->output( $newStr ); |
|
334 | + $newSql = $this->normalizeSlots($sql); |
|
335 | + $newBindings = $this->normalizeBindings($bindings); |
|
336 | + $newStr = $this->writeQuery($newSql, $newBindings); |
|
337 | + $this->output($newStr); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * |
347 | 347 | * @return self |
348 | 348 | */ |
349 | - public function setParamStringLength( $len = 20 ) |
|
349 | + public function setParamStringLength($len = 20) |
|
350 | 350 | { |
351 | 351 | $this->strLen = max(0, $len); |
352 | 352 | return $this; |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * |
381 | 381 | * @return array |
382 | 382 | */ |
383 | - public function GetAll( $sql, $bindings = array() ); |
|
383 | + public function GetAll($sql, $bindings = array()); |
|
384 | 384 | |
385 | 385 | /** |
386 | 386 | * Runs a query and fetches results as a column. |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @return array |
392 | 392 | */ |
393 | - public function GetCol( $sql, $bindings = array() ); |
|
393 | + public function GetCol($sql, $bindings = array()); |
|
394 | 394 | |
395 | 395 | /** |
396 | 396 | * Runs a query and returns results as a single cell. |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * |
401 | 401 | * @return mixed |
402 | 402 | */ |
403 | - public function GetOne( $sql, $bindings = array() ); |
|
403 | + public function GetOne($sql, $bindings = array()); |
|
404 | 404 | |
405 | 405 | /** |
406 | 406 | * Runs a query and returns results as an associative array |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @return mixed |
413 | 413 | */ |
414 | - public function GetAssocRow( $sql, $bindings = array() ); |
|
414 | + public function GetAssocRow($sql, $bindings = array()); |
|
415 | 415 | |
416 | 416 | /** |
417 | 417 | * Runs a query and returns a flat array containing the values of |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @return array |
424 | 424 | */ |
425 | - public function GetRow( $sql, $bindings = array() ); |
|
425 | + public function GetRow($sql, $bindings = array()); |
|
426 | 426 | |
427 | 427 | /** |
428 | 428 | * Executes SQL code and allows key-value binding. |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | * |
440 | 440 | * @return array Affected Rows |
441 | 441 | */ |
442 | - public function Execute( $sql, $bindings = array() ); |
|
442 | + public function Execute($sql, $bindings = array()); |
|
443 | 443 | |
444 | 444 | /** |
445 | 445 | * Returns the latest insert ID if driver does support this |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | * |
466 | 466 | * @return mixed |
467 | 467 | */ |
468 | - public function GetCursor( $sql, $bindings = array() ); |
|
468 | + public function GetCursor($sql, $bindings = array()); |
|
469 | 469 | |
470 | 470 | /** |
471 | 471 | * Toggles debug mode. In debug mode the driver will print all |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | * |
479 | 479 | * @return void |
480 | 480 | */ |
481 | - public function setDebugMode( $tf ); |
|
481 | + public function setDebugMode($tf); |
|
482 | 482 | |
483 | 483 | /** |
484 | 484 | * Starts a transaction. |
@@ -614,24 +614,24 @@ discard block |
||
614 | 614 | * |
615 | 615 | * @return void |
616 | 616 | */ |
617 | - protected function bindParams( $statement, $bindings ) |
|
617 | + protected function bindParams($statement, $bindings) |
|
618 | 618 | { |
619 | - foreach ( $bindings as $key => &$value ) { |
|
620 | - if ( is_integer( $key ) ) { |
|
621 | - if ( is_null( $value ) ) { |
|
622 | - $statement->bindValue( $key + 1, NULL, \PDO::PARAM_NULL ); |
|
623 | - } elseif ( !$this->flagUseStringOnlyBinding && AQueryWriter::canBeTreatedAsInt( $value ) && abs( $value ) <= $this->max ) { |
|
624 | - $statement->bindParam( $key + 1, $value, \PDO::PARAM_INT ); |
|
619 | + foreach ($bindings as $key => &$value) { |
|
620 | + if (is_integer($key)) { |
|
621 | + if (is_null($value)) { |
|
622 | + $statement->bindValue($key + 1, NULL, \PDO::PARAM_NULL); |
|
623 | + } elseif (!$this->flagUseStringOnlyBinding && AQueryWriter::canBeTreatedAsInt($value) && abs($value) <= $this->max) { |
|
624 | + $statement->bindParam($key + 1, $value, \PDO::PARAM_INT); |
|
625 | 625 | } else { |
626 | - $statement->bindParam( $key + 1, $value, \PDO::PARAM_STR ); |
|
626 | + $statement->bindParam($key + 1, $value, \PDO::PARAM_STR); |
|
627 | 627 | } |
628 | 628 | } else { |
629 | - if ( is_null( $value ) ) { |
|
630 | - $statement->bindValue( $key, NULL, \PDO::PARAM_NULL ); |
|
631 | - } elseif ( !$this->flagUseStringOnlyBinding && AQueryWriter::canBeTreatedAsInt( $value ) && abs( $value ) <= $this->max ) { |
|
632 | - $statement->bindParam( $key, $value, \PDO::PARAM_INT ); |
|
629 | + if (is_null($value)) { |
|
630 | + $statement->bindValue($key, NULL, \PDO::PARAM_NULL); |
|
631 | + } elseif (!$this->flagUseStringOnlyBinding && AQueryWriter::canBeTreatedAsInt($value) && abs($value) <= $this->max) { |
|
632 | + $statement->bindParam($key, $value, \PDO::PARAM_INT); |
|
633 | 633 | } else { |
634 | - $statement->bindParam( $key, $value, \PDO::PARAM_STR ); |
|
634 | + $statement->bindParam($key, $value, \PDO::PARAM_STR); |
|
635 | 635 | } |
636 | 636 | } |
637 | 637 | } |
@@ -651,42 +651,42 @@ discard block |
||
651 | 651 | * |
652 | 652 | * @throws SQL |
653 | 653 | */ |
654 | - protected function runQuery( $sql, $bindings, $options = array() ) |
|
654 | + protected function runQuery($sql, $bindings, $options = array()) |
|
655 | 655 | { |
656 | 656 | $this->connect(); |
657 | - if ( $this->loggingEnabled && $this->logger ) { |
|
658 | - $this->logger->log( $sql, $bindings ); |
|
657 | + if ($this->loggingEnabled && $this->logger) { |
|
658 | + $this->logger->log($sql, $bindings); |
|
659 | 659 | } |
660 | 660 | try { |
661 | - if ( strpos( 'pgsql', $this->dsn ) === 0 ) { |
|
662 | - $statement = $this->pdo->prepare( $sql, array( \PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => TRUE ) ); |
|
661 | + if (strpos('pgsql', $this->dsn) === 0) { |
|
662 | + $statement = $this->pdo->prepare($sql, array(\PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => TRUE)); |
|
663 | 663 | } else { |
664 | - $statement = $this->pdo->prepare( $sql ); |
|
664 | + $statement = $this->pdo->prepare($sql); |
|
665 | 665 | } |
666 | - $this->bindParams( $statement, $bindings ); |
|
666 | + $this->bindParams($statement, $bindings); |
|
667 | 667 | $statement->execute(); |
668 | - $this->queryCounter ++; |
|
668 | + $this->queryCounter++; |
|
669 | 669 | $this->affectedRows = $statement->rowCount(); |
670 | - if ( $statement->columnCount() ) { |
|
671 | - $fetchStyle = ( isset( $options['fetchStyle'] ) ) ? $options['fetchStyle'] : NULL; |
|
672 | - if ( isset( $options['noFetch'] ) && $options['noFetch'] ) { |
|
670 | + if ($statement->columnCount()) { |
|
671 | + $fetchStyle = (isset($options['fetchStyle'])) ? $options['fetchStyle'] : NULL; |
|
672 | + if (isset($options['noFetch']) && $options['noFetch']) { |
|
673 | 673 | $this->resultArray = array(); |
674 | 674 | return $statement; |
675 | 675 | } |
676 | - $this->resultArray = $statement->fetchAll( $fetchStyle ); |
|
677 | - if ( $this->loggingEnabled && $this->logger ) { |
|
678 | - $this->logger->log( 'resultset: ' . count( $this->resultArray ) . ' rows' ); |
|
676 | + $this->resultArray = $statement->fetchAll($fetchStyle); |
|
677 | + if ($this->loggingEnabled && $this->logger) { |
|
678 | + $this->logger->log('resultset: ' . count($this->resultArray) . ' rows'); |
|
679 | 679 | } |
680 | 680 | } else { |
681 | 681 | $this->resultArray = array(); |
682 | 682 | } |
683 | - } catch (\PDOException $e ) { |
|
683 | + } catch (\PDOException $e) { |
|
684 | 684 | //Unfortunately the code field is supposed to be int by default (php) |
685 | 685 | //So we need a property to convey the SQL State code. |
686 | 686 | $err = $e->getMessage(); |
687 | - if ( $this->loggingEnabled && $this->logger ) $this->logger->log( 'An error occurred: ' . $err ); |
|
688 | - $exception = new SQL( $err, 0 ); |
|
689 | - $exception->setSQLState( $e->getCode() ); |
|
687 | + if ($this->loggingEnabled && $this->logger) $this->logger->log('An error occurred: ' . $err); |
|
688 | + $exception = new SQL($err, 0); |
|
689 | + $exception->setSQLState($e->getCode()); |
|
690 | 690 | throw $exception; |
691 | 691 | } |
692 | 692 | } |
@@ -699,12 +699,12 @@ discard block |
||
699 | 699 | */ |
700 | 700 | protected function setEncoding() |
701 | 701 | { |
702 | - $driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME ); |
|
703 | - $version = floatval( $this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION ) ); |
|
702 | + $driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME); |
|
703 | + $version = floatval($this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION)); |
|
704 | 704 | if ($driver === 'mysql') { |
705 | 705 | $encoding = ($version >= 5.5) ? 'utf8mb4' : 'utf8'; |
706 | - $this->pdo->setAttribute(\PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES '.$encoding ); //on every re-connect |
|
707 | - $this->pdo->exec(' SET NAMES '. $encoding); //also for current connection |
|
706 | + $this->pdo->setAttribute(\PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES ' . $encoding); //on every re-connect |
|
707 | + $this->pdo->exec(' SET NAMES ' . $encoding); //also for current connection |
|
708 | 708 | $this->mysqlEncoding = $encoding; |
709 | 709 | } |
710 | 710 | } |
@@ -722,25 +722,25 @@ discard block |
||
722 | 722 | * @param string $pass optional, password for connection login |
723 | 723 | * |
724 | 724 | */ |
725 | - public function __construct( $dsn, $user = NULL, $pass = NULL ) |
|
725 | + public function __construct($dsn, $user = NULL, $pass = NULL) |
|
726 | 726 | { |
727 | - if ( is_object( $dsn ) ) { |
|
727 | + if (is_object($dsn)) { |
|
728 | 728 | $this->pdo = $dsn; |
729 | 729 | $this->isConnected = TRUE; |
730 | 730 | $this->setEncoding(); |
731 | - $this->pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION ); |
|
732 | - $this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE,\PDO::FETCH_ASSOC ); |
|
731 | + $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
|
732 | + $this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC); |
|
733 | 733 | // make sure that the dsn at least contains the type |
734 | 734 | $this->dsn = $this->getDatabaseType(); |
735 | 735 | } else { |
736 | 736 | $this->dsn = $dsn; |
737 | - $this->connectInfo = array( 'pass' => $pass, 'user' => $user ); |
|
737 | + $this->connectInfo = array('pass' => $pass, 'user' => $user); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | //PHP 5.3 PDO SQLite has a bug with large numbers: |
741 | - if ( ( strpos( $this->dsn, 'sqlite' ) === 0 && PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION === 3 ) || $this->dsn === 'test-sqlite-53' ) { |
|
741 | + if ((strpos($this->dsn, 'sqlite') === 0 && PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION === 3) || $this->dsn === 'test-sqlite-53') { |
|
742 | 742 | $this->max = 2147483647; //otherwise you get -2147483648 ?! demonstrated in build #603 on Travis. |
743 | - } elseif ( strpos( $this->dsn, 'cubrid' ) === 0 ) { |
|
743 | + } elseif (strpos($this->dsn, 'cubrid') === 0) { |
|
744 | 744 | $this->max = 2147483647; //bindParam in pdo_cubrid also fails... |
745 | 745 | } else { |
746 | 746 | $this->max = PHP_INT_MAX; //the normal value of course (makes it possible to use large numbers in LIMIT clause) |
@@ -766,7 +766,7 @@ discard block |
||
766 | 766 | * |
767 | 767 | * @return void |
768 | 768 | */ |
769 | - public function setUseStringOnlyBinding( $yesNo ) |
|
769 | + public function setUseStringOnlyBinding($yesNo) |
|
770 | 770 | { |
771 | 771 | $this->flagUseStringOnlyBinding = (boolean) $yesNo; |
772 | 772 | } |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | */ |
785 | 785 | public function connect() |
786 | 786 | { |
787 | - if ( $this->isConnected ) return; |
|
787 | + if ($this->isConnected) return; |
|
788 | 788 | try { |
789 | 789 | $user = $this->connectInfo['user']; |
790 | 790 | $pass = $this->connectInfo['pass']; |
@@ -794,15 +794,15 @@ discard block |
||
794 | 794 | $pass |
795 | 795 | ); |
796 | 796 | $this->setEncoding(); |
797 | - $this->pdo->setAttribute( \PDO::ATTR_STRINGIFY_FETCHES, TRUE ); |
|
797 | + $this->pdo->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, TRUE); |
|
798 | 798 | //cant pass these as argument to constructor, CUBRID driver does not understand... |
799 | - $this->pdo->setAttribute( \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION ); |
|
800 | - $this->pdo->setAttribute( \PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC ); |
|
799 | + $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
|
800 | + $this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC); |
|
801 | 801 | $this->isConnected = TRUE; |
802 | - } catch ( \PDOException $exception ) { |
|
802 | + } catch (\PDOException $exception) { |
|
803 | 803 | $matches = array(); |
804 | - $dbname = ( preg_match( '/dbname=(\w+)/', $this->dsn, $matches ) ) ? $matches[1] : '?'; |
|
805 | - throw new \PDOException( 'Could not connect to database (' . $dbname . ').', $exception->getCode() ); |
|
804 | + $dbname = (preg_match('/dbname=(\w+)/', $this->dsn, $matches)) ? $matches[1] : '?'; |
|
805 | + throw new \PDOException('Could not connect to database (' . $dbname . ').', $exception->getCode()); |
|
806 | 806 | } |
807 | 807 | } |
808 | 808 | |
@@ -817,25 +817,25 @@ discard block |
||
817 | 817 | * |
818 | 818 | * @return void |
819 | 819 | */ |
820 | - public function setPDO( \PDO $pdo ) { |
|
820 | + public function setPDO(\PDO $pdo) { |
|
821 | 821 | $this->pdo = $pdo; |
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
825 | 825 | * @see Driver::GetAll |
826 | 826 | */ |
827 | - public function GetAll( $sql, $bindings = array() ) |
|
827 | + public function GetAll($sql, $bindings = array()) |
|
828 | 828 | { |
829 | - $this->runQuery( $sql, $bindings ); |
|
829 | + $this->runQuery($sql, $bindings); |
|
830 | 830 | return $this->resultArray; |
831 | 831 | } |
832 | 832 | |
833 | 833 | /** |
834 | 834 | * @see Driver::GetAssocRow |
835 | 835 | */ |
836 | - public function GetAssocRow( $sql, $bindings = array() ) |
|
836 | + public function GetAssocRow($sql, $bindings = array()) |
|
837 | 837 | { |
838 | - $this->runQuery( $sql, $bindings, array( |
|
838 | + $this->runQuery($sql, $bindings, array( |
|
839 | 839 | 'fetchStyle' => \PDO::FETCH_ASSOC |
840 | 840 | ) |
841 | 841 | ); |
@@ -845,13 +845,13 @@ discard block |
||
845 | 845 | /** |
846 | 846 | * @see Driver::GetCol |
847 | 847 | */ |
848 | - public function GetCol( $sql, $bindings = array() ) |
|
848 | + public function GetCol($sql, $bindings = array()) |
|
849 | 849 | { |
850 | - $rows = $this->GetAll( $sql, $bindings ); |
|
850 | + $rows = $this->GetAll($sql, $bindings); |
|
851 | 851 | $cols = array(); |
852 | - if ( $rows && is_array( $rows ) && count( $rows ) > 0 ) { |
|
853 | - foreach ( $rows as $row ) { |
|
854 | - $cols[] = array_shift( $row ); |
|
852 | + if ($rows && is_array($rows) && count($rows) > 0) { |
|
853 | + foreach ($rows as $row) { |
|
854 | + $cols[] = array_shift($row); |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | |
@@ -861,16 +861,16 @@ discard block |
||
861 | 861 | /** |
862 | 862 | * @see Driver::GetOne |
863 | 863 | */ |
864 | - public function GetOne( $sql, $bindings = array() ) |
|
864 | + public function GetOne($sql, $bindings = array()) |
|
865 | 865 | { |
866 | - $arr = $this->GetAll( $sql, $bindings ); |
|
866 | + $arr = $this->GetAll($sql, $bindings); |
|
867 | 867 | $res = NULL; |
868 | - if ( !is_array( $arr ) ) return NULL; |
|
869 | - if ( count( $arr ) === 0 ) return NULL; |
|
870 | - $row1 = array_shift( $arr ); |
|
871 | - if ( !is_array( $row1 ) ) return NULL; |
|
872 | - if ( count( $row1 ) === 0 ) return NULL; |
|
873 | - $col1 = array_shift( $row1 ); |
|
868 | + if (!is_array($arr)) return NULL; |
|
869 | + if (count($arr) === 0) return NULL; |
|
870 | + $row1 = array_shift($arr); |
|
871 | + if (!is_array($row1)) return NULL; |
|
872 | + if (count($row1) === 0) return NULL; |
|
873 | + $col1 = array_shift($row1); |
|
874 | 874 | return $col1; |
875 | 875 | } |
876 | 876 | |
@@ -883,26 +883,26 @@ discard block |
||
883 | 883 | * |
884 | 884 | * @return mixed |
885 | 885 | */ |
886 | - public function GetCell( $sql, $bindings = array() ) |
|
886 | + public function GetCell($sql, $bindings = array()) |
|
887 | 887 | { |
888 | - return $this->GetOne( $sql, $bindings ); |
|
888 | + return $this->GetOne($sql, $bindings); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
892 | 892 | * @see Driver::GetRow |
893 | 893 | */ |
894 | - public function GetRow( $sql, $bindings = array() ) |
|
894 | + public function GetRow($sql, $bindings = array()) |
|
895 | 895 | { |
896 | - $arr = $this->GetAll( $sql, $bindings ); |
|
897 | - return array_shift( $arr ); |
|
896 | + $arr = $this->GetAll($sql, $bindings); |
|
897 | + return array_shift($arr); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
901 | 901 | * @see Driver::Excecute |
902 | 902 | */ |
903 | - public function Execute( $sql, $bindings = array() ) |
|
903 | + public function Execute($sql, $bindings = array()) |
|
904 | 904 | { |
905 | - $this->runQuery( $sql, $bindings ); |
|
905 | + $this->runQuery($sql, $bindings); |
|
906 | 906 | return $this->affectedRows; |
907 | 907 | } |
908 | 908 | |
@@ -919,10 +919,10 @@ discard block |
||
919 | 919 | /** |
920 | 920 | * @see Driver::GetCursor |
921 | 921 | */ |
922 | - public function GetCursor( $sql, $bindings = array() ) |
|
922 | + public function GetCursor($sql, $bindings = array()) |
|
923 | 923 | { |
924 | - $statement = $this->runQuery( $sql, $bindings, array( 'noFetch' => TRUE ) ); |
|
925 | - $cursor = new PDOCursor( $statement, \PDO::FETCH_ASSOC ); |
|
924 | + $statement = $this->runQuery($sql, $bindings, array('noFetch' => TRUE)); |
|
925 | + $cursor = new PDOCursor($statement, \PDO::FETCH_ASSOC); |
|
926 | 926 | return $cursor; |
927 | 927 | } |
928 | 928 | |
@@ -945,14 +945,14 @@ discard block |
||
945 | 945 | * |
946 | 946 | * @return void |
947 | 947 | */ |
948 | - public function setDebugMode( $tf, $logger = NULL ) |
|
948 | + public function setDebugMode($tf, $logger = NULL) |
|
949 | 949 | { |
950 | 950 | $this->connect(); |
951 | 951 | $this->loggingEnabled = (bool) $tf; |
952 | - if ( $this->loggingEnabled and !$logger ) { |
|
952 | + if ($this->loggingEnabled and !$logger) { |
|
953 | 953 | $logger = new RDefault(); |
954 | 954 | } |
955 | - $this->setLogger( $logger ); |
|
955 | + $this->setLogger($logger); |
|
956 | 956 | } |
957 | 957 | |
958 | 958 | /** |
@@ -963,7 +963,7 @@ discard block |
||
963 | 963 | * |
964 | 964 | * @return void |
965 | 965 | */ |
966 | - public function setLogger( Logger $logger ) |
|
966 | + public function setLogger(Logger $logger) |
|
967 | 967 | { |
968 | 968 | $this->logger = $logger; |
969 | 969 | } |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | { |
1018 | 1018 | $this->connect(); |
1019 | 1019 | |
1020 | - return $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME ); |
|
1020 | + return $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME); |
|
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | /** |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | public function getDatabaseVersion() |
1029 | 1029 | { |
1030 | 1030 | $this->connect(); |
1031 | - return $this->pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION ); |
|
1031 | + return $this->pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | /** |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | * |
1071 | 1071 | * @return self |
1072 | 1072 | */ |
1073 | - public function setEnableLogging( $enable ) |
|
1073 | + public function setEnableLogging($enable) |
|
1074 | 1074 | { |
1075 | 1075 | $this->loggingEnabled = (boolean) $enable; |
1076 | 1076 | } |
@@ -1137,7 +1137,7 @@ discard block |
||
1137 | 1137 | * This source file is subject to the BSD/GPLv2 License that is bundled |
1138 | 1138 | * with this source code in the file license.txt. |
1139 | 1139 | */ |
1140 | -class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable |
|
1140 | +class OODBBean implements\IteratorAggregate, \ArrayAccess, \Countable |
|
1141 | 1141 | { |
1142 | 1142 | /** |
1143 | 1143 | * FUSE error modes. |
@@ -1205,15 +1205,15 @@ discard block |
||
1205 | 1205 | && $mode !== self::C_ERR_EXCEPTION |
1206 | 1206 | && $mode !== self::C_ERR_FUNC |
1207 | 1207 | && $mode !== self::C_ERR_FATAL |
1208 | - ) throw new \Exception( 'Invalid error mode selected' ); |
|
1208 | + ) throw new \Exception('Invalid error mode selected'); |
|
1209 | 1209 | |
1210 | - if ( $mode === self::C_ERR_FUNC && !is_callable( $func ) ) { |
|
1211 | - throw new \Exception( 'Invalid error handler' ); |
|
1210 | + if ($mode === self::C_ERR_FUNC && !is_callable($func)) { |
|
1211 | + throw new \Exception('Invalid error handler'); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | - $old = array( self::$errorHandlingFUSE, self::$errorHandler ); |
|
1214 | + $old = array(self::$errorHandlingFUSE, self::$errorHandler); |
|
1215 | 1215 | self::$errorHandlingFUSE = $mode; |
1216 | - if ( is_callable( $func ) ) { |
|
1216 | + if (is_callable($func)) { |
|
1217 | 1217 | self::$errorHandler = $func; |
1218 | 1218 | } else { |
1219 | 1219 | self::$errorHandler = NULL; |
@@ -1228,7 +1228,7 @@ discard block |
||
1228 | 1228 | * |
1229 | 1229 | * @return void |
1230 | 1230 | */ |
1231 | - public static function aliases( $list ) |
|
1231 | + public static function aliases($list) |
|
1232 | 1232 | { |
1233 | 1233 | self::$aliases = $list; |
1234 | 1234 | } |
@@ -1243,7 +1243,7 @@ discard block |
||
1243 | 1243 | * |
1244 | 1244 | * @return void |
1245 | 1245 | */ |
1246 | - public static function setAutoResolve( $automatic = TRUE ) |
|
1246 | + public static function setAutoResolve($automatic = TRUE) |
|
1247 | 1247 | { |
1248 | 1248 | self::$autoResolve = (boolean) $automatic; |
1249 | 1249 | } |
@@ -1319,10 +1319,10 @@ discard block |
||
1319 | 1319 | * |
1320 | 1320 | * @return array |
1321 | 1321 | */ |
1322 | - public static function setMetaAll( $beans, $property, $value ) |
|
1322 | + public static function setMetaAll($beans, $property, $value) |
|
1323 | 1323 | { |
1324 | - foreach( $beans as $bean ) { |
|
1325 | - if ( $bean instanceof OODBBean ) $bean->__info[ $property ] = $value; |
|
1324 | + foreach ($beans as $bean) { |
|
1325 | + if ($bean instanceof OODBBean) $bean->__info[$property] = $value; |
|
1326 | 1326 | } |
1327 | 1327 | |
1328 | 1328 | return $beans; |
@@ -1346,24 +1346,24 @@ discard block |
||
1346 | 1346 | * |
1347 | 1347 | * @return string $joinSql |
1348 | 1348 | */ |
1349 | - private function parseJoin( $type ) |
|
1349 | + private function parseJoin($type) |
|
1350 | 1350 | { |
1351 | 1351 | $joinSql = ''; |
1352 | 1352 | $joins = array(); |
1353 | - if ( strpos($this->withSql, '@joined.' ) !== FALSE ) { |
|
1353 | + if (strpos($this->withSql, '@joined.') !== FALSE) { |
|
1354 | 1354 | $writer = $this->beanHelper->getToolBox()->getWriter(); |
1355 | - $oldParts = $parts = explode( '@joined.', $this->withSql ); |
|
1356 | - array_shift( $parts ); |
|
1357 | - foreach($parts as $part) { |
|
1358 | - $explosion = explode( '.', $part ); |
|
1359 | - $joinInfo = array_shift( $explosion ); |
|
1355 | + $oldParts = $parts = explode('@joined.', $this->withSql); |
|
1356 | + array_shift($parts); |
|
1357 | + foreach ($parts as $part) { |
|
1358 | + $explosion = explode('.', $part); |
|
1359 | + $joinInfo = array_shift($explosion); |
|
1360 | 1360 | //Dont join more than once.. |
1361 | - if ( !isset( $joins[$joinInfo] ) ) { |
|
1362 | - $joins[ $joinInfo ] = true; |
|
1363 | - $joinSql .= $writer->writeJoin( $type, $joinInfo, 'LEFT' ); |
|
1361 | + if (!isset($joins[$joinInfo])) { |
|
1362 | + $joins[$joinInfo] = true; |
|
1363 | + $joinSql .= $writer->writeJoin($type, $joinInfo, 'LEFT'); |
|
1364 | 1364 | } |
1365 | 1365 | } |
1366 | - $this->withSql = implode( '', $oldParts ); |
|
1366 | + $this->withSql = implode('', $oldParts); |
|
1367 | 1367 | $joinSql .= ' WHERE '; |
1368 | 1368 | } |
1369 | 1369 | return $joinSql; |
@@ -1377,24 +1377,24 @@ discard block |
||
1377 | 1377 | * |
1378 | 1378 | * @return array |
1379 | 1379 | */ |
1380 | - private function getSharedList( $type, $redbean, $toolbox ) |
|
1380 | + private function getSharedList($type, $redbean, $toolbox) |
|
1381 | 1381 | { |
1382 | 1382 | $writer = $toolbox->getWriter(); |
1383 | 1383 | |
1384 | - if ( $this->via ) { |
|
1385 | - $oldName = $writer->getAssocTable( array( $this->__info['type'], $type ) ); |
|
1386 | - if ( $oldName !== $this->via ) { |
|
1384 | + if ($this->via) { |
|
1385 | + $oldName = $writer->getAssocTable(array($this->__info['type'], $type)); |
|
1386 | + if ($oldName !== $this->via) { |
|
1387 | 1387 | //set the new renaming rule |
1388 | - $writer->renameAssocTable( $oldName, $this->via ); |
|
1388 | + $writer->renameAssocTable($oldName, $this->via); |
|
1389 | 1389 | } |
1390 | 1390 | $this->via = NULL; |
1391 | 1391 | } |
1392 | 1392 | |
1393 | 1393 | $beans = array(); |
1394 | 1394 | if ($this->getID()) { |
1395 | - $type = $this->beau( $type ); |
|
1395 | + $type = $this->beau($type); |
|
1396 | 1396 | $assocManager = $redbean->getAssociationManager(); |
1397 | - $beans = $assocManager->related( $this, $type, $this->withSql, $this->withParams ); |
|
1397 | + $beans = $assocManager->related($this, $type, $this->withSql, $this->withParams); |
|
1398 | 1398 | } |
1399 | 1399 | |
1400 | 1400 | $this->withSql = ''; |
@@ -1412,11 +1412,11 @@ discard block |
||
1412 | 1412 | * |
1413 | 1413 | * @return array |
1414 | 1414 | */ |
1415 | - private function getOwnList( $type, $redbean ) |
|
1415 | + private function getOwnList($type, $redbean) |
|
1416 | 1416 | { |
1417 | - $type = $this->beau( $type ); |
|
1417 | + $type = $this->beau($type); |
|
1418 | 1418 | |
1419 | - if ( $this->aliasName ) { |
|
1419 | + if ($this->aliasName) { |
|
1420 | 1420 | $parentField = $this->aliasName; |
1421 | 1421 | $myFieldLink = $parentField . '_id'; |
1422 | 1422 | |
@@ -1430,33 +1430,33 @@ discard block |
||
1430 | 1430 | |
1431 | 1431 | $beans = array(); |
1432 | 1432 | |
1433 | - if ( $this->getID() ) { |
|
1433 | + if ($this->getID()) { |
|
1434 | 1434 | |
1435 | 1435 | $firstKey = NULL; |
1436 | - if ( count( $this->withParams ) > 0 ) { |
|
1437 | - reset( $this->withParams ); |
|
1436 | + if (count($this->withParams) > 0) { |
|
1437 | + reset($this->withParams); |
|
1438 | 1438 | |
1439 | - $firstKey = key( $this->withParams ); |
|
1439 | + $firstKey = key($this->withParams); |
|
1440 | 1440 | } |
1441 | 1441 | |
1442 | - $joinSql = $this->parseJoin( $type ); |
|
1442 | + $joinSql = $this->parseJoin($type); |
|
1443 | 1443 | |
1444 | - if ( !is_numeric( $firstKey ) || $firstKey === NULL ) { |
|
1444 | + if (!is_numeric($firstKey) || $firstKey === NULL) { |
|
1445 | 1445 | $bindings = $this->withParams; |
1446 | 1446 | $bindings[':slot0'] = $this->getID(); |
1447 | 1447 | |
1448 | - $beans = $redbean->find( $type, array(), " {$joinSql} $myFieldLink = :slot0 " . $this->withSql, $bindings ); |
|
1448 | + $beans = $redbean->find($type, array(), " {$joinSql} $myFieldLink = :slot0 " . $this->withSql, $bindings); |
|
1449 | 1449 | } else { |
1450 | - $bindings = array_merge( array( $this->getID() ), $this->withParams ); |
|
1450 | + $bindings = array_merge(array($this->getID()), $this->withParams); |
|
1451 | 1451 | |
1452 | - $beans = $redbean->find( $type, array(), " {$joinSql} $myFieldLink = ? " . $this->withSql, $bindings ); |
|
1452 | + $beans = $redbean->find($type, array(), " {$joinSql} $myFieldLink = ? " . $this->withSql, $bindings); |
|
1453 | 1453 | } |
1454 | 1454 | } |
1455 | 1455 | |
1456 | 1456 | $this->withSql = ''; |
1457 | 1457 | $this->withParams = array(); |
1458 | 1458 | |
1459 | - foreach ( $beans as $beanFromList ) { |
|
1459 | + foreach ($beans as $beanFromList) { |
|
1460 | 1460 | $beanFromList->__info['sys.parentcache.' . $parentField] = $this; |
1461 | 1461 | } |
1462 | 1462 | |
@@ -1474,12 +1474,12 @@ discard block |
||
1474 | 1474 | * |
1475 | 1475 | * @return void |
1476 | 1476 | */ |
1477 | - public function initializeForDispense( $type, BeanHelper $beanhelper ) |
|
1477 | + public function initializeForDispense($type, BeanHelper $beanhelper) |
|
1478 | 1478 | { |
1479 | 1479 | $this->beanHelper = $beanhelper; |
1480 | 1480 | $this->__info['type'] = $type; |
1481 | 1481 | $this->__info['sys.id'] = 'id'; |
1482 | - $this->__info['sys.orig'] = array( 'id' => 0 ); |
|
1482 | + $this->__info['sys.orig'] = array('id' => 0); |
|
1483 | 1483 | $this->__info['tainted'] = TRUE; |
1484 | 1484 | $this->__info['changed'] = TRUE; |
1485 | 1485 | $this->properties['id'] = 0; |
@@ -1496,7 +1496,7 @@ discard block |
||
1496 | 1496 | * |
1497 | 1497 | * @return void |
1498 | 1498 | */ |
1499 | - public function setBeanHelper( BeanHelper $helper ) |
|
1499 | + public function setBeanHelper(BeanHelper $helper) |
|
1500 | 1500 | { |
1501 | 1501 | $this->beanHelper = $helper; |
1502 | 1502 | } |
@@ -1515,7 +1515,7 @@ discard block |
||
1515 | 1515 | */ |
1516 | 1516 | public function getIterator() |
1517 | 1517 | { |
1518 | - return new\ArrayIterator( $this->properties ); |
|
1518 | + return new\ArrayIterator($this->properties); |
|
1519 | 1519 | } |
1520 | 1520 | |
1521 | 1521 | /** |
@@ -1532,35 +1532,35 @@ discard block |
||
1532 | 1532 | * |
1533 | 1533 | * @return OODBBean |
1534 | 1534 | */ |
1535 | - public function import( $array, $selection = FALSE, $notrim = FALSE ) |
|
1535 | + public function import($array, $selection = FALSE, $notrim = FALSE) |
|
1536 | 1536 | { |
1537 | - if ( is_string( $selection ) ) { |
|
1538 | - $selection = explode( ',', $selection ); |
|
1537 | + if (is_string($selection)) { |
|
1538 | + $selection = explode(',', $selection); |
|
1539 | 1539 | } |
1540 | 1540 | |
1541 | - if ( !$notrim && is_array( $selection ) ) { |
|
1542 | - foreach ( $selection as $key => $selected ) { |
|
1543 | - $selection[$key] = trim( $selected ); |
|
1541 | + if (!$notrim && is_array($selection)) { |
|
1542 | + foreach ($selection as $key => $selected) { |
|
1543 | + $selection[$key] = trim($selected); |
|
1544 | 1544 | } |
1545 | 1545 | } |
1546 | 1546 | |
1547 | - foreach ( $array as $key => $value ) { |
|
1548 | - if ( $key != '__info' ) { |
|
1549 | - if ( !$selection || ( $selection && in_array( $key, $selection ) ) ) { |
|
1550 | - if ( is_array($value ) ) { |
|
1551 | - if ( isset( $value['_type'] ) ) { |
|
1552 | - $bean = $this->beanHelper->getToolbox()->getRedBean()->dispense( $value['_type'] ); |
|
1553 | - unset( $value['_type'] ); |
|
1547 | + foreach ($array as $key => $value) { |
|
1548 | + if ($key != '__info') { |
|
1549 | + if (!$selection || ($selection && in_array($key, $selection))) { |
|
1550 | + if (is_array($value)) { |
|
1551 | + if (isset($value['_type'])) { |
|
1552 | + $bean = $this->beanHelper->getToolbox()->getRedBean()->dispense($value['_type']); |
|
1553 | + unset($value['_type']); |
|
1554 | 1554 | $bean->import($value); |
1555 | 1555 | $this->$key = $bean; |
1556 | 1556 | } else { |
1557 | 1557 | $listBeans = array(); |
1558 | - foreach( $value as $listKey => $listItem ) { |
|
1559 | - $bean = $this->beanHelper->getToolbox()->getRedBean()->dispense( $listItem['_type'] ); |
|
1560 | - unset( $listItem['_type'] ); |
|
1558 | + foreach ($value as $listKey => $listItem) { |
|
1559 | + $bean = $this->beanHelper->getToolbox()->getRedBean()->dispense($listItem['_type']); |
|
1560 | + unset($listItem['_type']); |
|
1561 | 1561 | $bean->import($listItem); |
1562 | 1562 | $list = &$this->$key; |
1563 | - $list[ $listKey ] = $bean; |
|
1563 | + $list[$listKey] = $bean; |
|
1564 | 1564 | } |
1565 | 1565 | } |
1566 | 1566 | } else { |
@@ -1581,7 +1581,7 @@ discard block |
||
1581 | 1581 | * |
1582 | 1582 | * @return self |
1583 | 1583 | */ |
1584 | - public function importRow( $row ) |
|
1584 | + public function importRow($row) |
|
1585 | 1585 | { |
1586 | 1586 | $this->properties = $row; |
1587 | 1587 | $this->__info['sys.orig'] = $row; |
@@ -1598,7 +1598,7 @@ discard block |
||
1598 | 1598 | * |
1599 | 1599 | * @return OODBBean |
1600 | 1600 | */ |
1601 | - public function importFrom( OODBBean $sourceBean ) |
|
1601 | + public function importFrom(OODBBean $sourceBean) |
|
1602 | 1602 | { |
1603 | 1603 | $this->__info['tainted'] = TRUE; |
1604 | 1604 | $this->__info['changed'] = TRUE; |
@@ -1616,11 +1616,11 @@ discard block |
||
1616 | 1616 | * |
1617 | 1617 | * @return OODBBean |
1618 | 1618 | */ |
1619 | - public function inject( OODBBean $otherBean ) |
|
1619 | + public function inject(OODBBean $otherBean) |
|
1620 | 1620 | { |
1621 | 1621 | $myID = $this->properties['id']; |
1622 | 1622 | |
1623 | - $this->import( $otherBean->export() ); |
|
1623 | + $this->import($otherBean->export()); |
|
1624 | 1624 | |
1625 | 1625 | $this->id = $myID; |
1626 | 1626 | |
@@ -1639,42 +1639,42 @@ discard block |
||
1639 | 1639 | * |
1640 | 1640 | * @return array |
1641 | 1641 | */ |
1642 | - public function export( $meta = FALSE, $parents = FALSE, $onlyMe = FALSE, $filters = array() ) |
|
1642 | + public function export($meta = FALSE, $parents = FALSE, $onlyMe = FALSE, $filters = array()) |
|
1643 | 1643 | { |
1644 | 1644 | $arr = array(); |
1645 | 1645 | |
1646 | - if ( $parents ) { |
|
1647 | - foreach ( $this as $key => $value ) { |
|
1648 | - if ( substr( $key, -3 ) != '_id' ) continue; |
|
1646 | + if ($parents) { |
|
1647 | + foreach ($this as $key => $value) { |
|
1648 | + if (substr($key, -3) != '_id') continue; |
|
1649 | 1649 | |
1650 | - $prop = substr( $key, 0, strlen( $key ) - 3 ); |
|
1650 | + $prop = substr($key, 0, strlen($key) - 3); |
|
1651 | 1651 | $this->$prop; |
1652 | 1652 | } |
1653 | 1653 | } |
1654 | 1654 | |
1655 | - $hasFilters = is_array( $filters ) && count( $filters ); |
|
1655 | + $hasFilters = is_array($filters) && count($filters); |
|
1656 | 1656 | |
1657 | - foreach ( $this as $key => $value ) { |
|
1658 | - if ( !$onlyMe && is_array( $value ) ) { |
|
1657 | + foreach ($this as $key => $value) { |
|
1658 | + if (!$onlyMe && is_array($value)) { |
|
1659 | 1659 | $vn = array(); |
1660 | 1660 | |
1661 | - foreach ( $value as $i => $b ) { |
|
1662 | - if ( !( $b instanceof OODBBean ) ) continue; |
|
1663 | - $vn[] = $b->export( $meta, FALSE, FALSE, $filters ); |
|
1661 | + foreach ($value as $i => $b) { |
|
1662 | + if (!($b instanceof OODBBean)) continue; |
|
1663 | + $vn[] = $b->export($meta, FALSE, FALSE, $filters); |
|
1664 | 1664 | $value = $vn; |
1665 | 1665 | } |
1666 | - } elseif ( $value instanceof OODBBean ) { |
|
1667 | - if ( $hasFilters ) { |
|
1668 | - if ( !in_array( strtolower( $value->getMeta( 'type' ) ), $filters ) ) continue; |
|
1666 | + } elseif ($value instanceof OODBBean) { |
|
1667 | + if ($hasFilters) { |
|
1668 | + if (!in_array(strtolower($value->getMeta('type')), $filters)) continue; |
|
1669 | 1669 | } |
1670 | 1670 | |
1671 | - $value = $value->export( $meta, $parents, FALSE, $filters ); |
|
1671 | + $value = $value->export($meta, $parents, FALSE, $filters); |
|
1672 | 1672 | } |
1673 | 1673 | |
1674 | 1674 | $arr[$key] = $value; |
1675 | 1675 | } |
1676 | 1676 | |
1677 | - if ( $meta ) { |
|
1677 | + if ($meta) { |
|
1678 | 1678 | $arr['__info'] = $this->__info; |
1679 | 1679 | } |
1680 | 1680 | |
@@ -1688,14 +1688,14 @@ discard block |
||
1688 | 1688 | * |
1689 | 1689 | * @return boolean |
1690 | 1690 | */ |
1691 | - public function __isset( $property ) |
|
1691 | + public function __isset($property) |
|
1692 | 1692 | { |
1693 | - $property = $this->beau( $property ); |
|
1693 | + $property = $this->beau($property); |
|
1694 | 1694 | |
1695 | - if ( strpos( $property, 'xown' ) === 0 && ctype_upper( substr( $property, 4, 1 ) ) ) { |
|
1695 | + if (strpos($property, 'xown') === 0 && ctype_upper(substr($property, 4, 1))) { |
|
1696 | 1696 | $property = substr($property, 1); |
1697 | 1697 | } |
1698 | - return isset( $this->properties[$property] ); |
|
1698 | + return isset($this->properties[$property]); |
|
1699 | 1699 | } |
1700 | 1700 | |
1701 | 1701 | /** |
@@ -1705,7 +1705,7 @@ discard block |
||
1705 | 1705 | */ |
1706 | 1706 | public function getID() |
1707 | 1707 | { |
1708 | - return ( isset( $this->properties['id'] ) ) ? (string) $this->properties['id'] : NULL; |
|
1708 | + return (isset($this->properties['id'])) ? (string) $this->properties['id'] : NULL; |
|
1709 | 1709 | } |
1710 | 1710 | |
1711 | 1711 | /** |
@@ -1717,18 +1717,18 @@ discard block |
||
1717 | 1717 | * |
1718 | 1718 | * @return void |
1719 | 1719 | */ |
1720 | - public function __unset( $property ) |
|
1720 | + public function __unset($property) |
|
1721 | 1721 | { |
1722 | - $property = $this->beau( $property ); |
|
1722 | + $property = $this->beau($property); |
|
1723 | 1723 | |
1724 | - if ( strpos( $property, 'xown' ) === 0 && ctype_upper( substr( $property, 4, 1 ) ) ) { |
|
1724 | + if (strpos($property, 'xown') === 0 && ctype_upper(substr($property, 4, 1))) { |
|
1725 | 1725 | $property = substr($property, 1); |
1726 | 1726 | } |
1727 | 1727 | |
1728 | - unset( $this->properties[$property] ); |
|
1728 | + unset($this->properties[$property]); |
|
1729 | 1729 | |
1730 | - $shadowKey = 'sys.shadow.'.$property; |
|
1731 | - if ( isset( $this->__info[ $shadowKey ] ) ) unset( $this->__info[$shadowKey] ); |
|
1730 | + $shadowKey = 'sys.shadow.' . $property; |
|
1731 | + if (isset($this->__info[$shadowKey])) unset($this->__info[$shadowKey]); |
|
1732 | 1732 | |
1733 | 1733 | //also clear modifiers |
1734 | 1734 | $this->withSql = ''; |
@@ -1758,7 +1758,7 @@ discard block |
||
1758 | 1758 | * |
1759 | 1759 | * @return OODBBean |
1760 | 1760 | */ |
1761 | - public function with( $sql, $bindings = array() ) |
|
1761 | + public function with($sql, $bindings = array()) |
|
1762 | 1762 | { |
1763 | 1763 | $this->withSql = $sql; |
1764 | 1764 | $this->withParams = $bindings; |
@@ -1780,7 +1780,7 @@ discard block |
||
1780 | 1780 | * |
1781 | 1781 | * @return OODBBean |
1782 | 1782 | */ |
1783 | - public function withCondition( $sql, $bindings = array() ) |
|
1783 | + public function withCondition($sql, $bindings = array()) |
|
1784 | 1784 | { |
1785 | 1785 | $this->withSql = ' AND ' . $sql; |
1786 | 1786 | $this->withParams = $bindings; |
@@ -1843,9 +1843,9 @@ discard block |
||
1843 | 1843 | * |
1844 | 1844 | * @return OODBBean |
1845 | 1845 | */ |
1846 | - public function alias( $aliasName ) |
|
1846 | + public function alias($aliasName) |
|
1847 | 1847 | { |
1848 | - $this->aliasName = $this->beau( $aliasName ); |
|
1848 | + $this->aliasName = $this->beau($aliasName); |
|
1849 | 1849 | |
1850 | 1850 | return $this; |
1851 | 1851 | } |
@@ -1875,7 +1875,7 @@ discard block |
||
1875 | 1875 | */ |
1876 | 1876 | public function getPropertiesAndType() |
1877 | 1877 | { |
1878 | - return array( $this->properties, $this->__info['type'] ); |
|
1878 | + return array($this->properties, $this->__info['type']); |
|
1879 | 1879 | } |
1880 | 1880 | |
1881 | 1881 | /** |
@@ -1891,24 +1891,24 @@ discard block |
||
1891 | 1891 | * |
1892 | 1892 | * @return string |
1893 | 1893 | */ |
1894 | - public function beau( $property ) |
|
1894 | + public function beau($property) |
|
1895 | 1895 | { |
1896 | 1896 | static $beautifulColumns = array(); |
1897 | 1897 | |
1898 | - if ( ctype_lower( $property ) ) return $property; |
|
1898 | + if (ctype_lower($property)) return $property; |
|
1899 | 1899 | |
1900 | 1900 | if ( |
1901 | - ( strpos( $property, 'own' ) === 0 && ctype_upper( substr( $property, 3, 1 ) ) ) |
|
1902 | - || ( strpos( $property, 'xown' ) === 0 && ctype_upper( substr( $property, 4, 1 ) ) ) |
|
1903 | - || ( strpos( $property, 'shared' ) === 0 && ctype_upper( substr( $property, 6, 1 ) ) ) |
|
1901 | + (strpos($property, 'own') === 0 && ctype_upper(substr($property, 3, 1))) |
|
1902 | + || (strpos($property, 'xown') === 0 && ctype_upper(substr($property, 4, 1))) |
|
1903 | + || (strpos($property, 'shared') === 0 && ctype_upper(substr($property, 6, 1))) |
|
1904 | 1904 | ) { |
1905 | 1905 | |
1906 | - $property = preg_replace( '/List$/', '', $property ); |
|
1906 | + $property = preg_replace('/List$/', '', $property); |
|
1907 | 1907 | return $property; |
1908 | 1908 | } |
1909 | 1909 | |
1910 | - if ( !isset( $beautifulColumns[$property] ) ) { |
|
1911 | - $beautifulColumns[$property] = AQueryWriter::camelsSnake( $property ); |
|
1910 | + if (!isset($beautifulColumns[$property])) { |
|
1911 | + $beautifulColumns[$property] = AQueryWriter::camelsSnake($property); |
|
1912 | 1912 | } |
1913 | 1913 | |
1914 | 1914 | return $beautifulColumns[$property]; |
@@ -1940,17 +1940,17 @@ discard block |
||
1940 | 1940 | * |
1941 | 1941 | * @return boolean |
1942 | 1942 | */ |
1943 | - public function isListInExclusiveMode( $listName ) |
|
1943 | + public function isListInExclusiveMode($listName) |
|
1944 | 1944 | { |
1945 | - $listName = $this->beau( $listName ); |
|
1945 | + $listName = $this->beau($listName); |
|
1946 | 1946 | |
1947 | - if ( strpos( $listName, 'xown' ) === 0 && ctype_upper( substr( $listName, 4, 1 ) ) ) { |
|
1947 | + if (strpos($listName, 'xown') === 0 && ctype_upper(substr($listName, 4, 1))) { |
|
1948 | 1948 | $listName = substr($listName, 1); |
1949 | 1949 | } |
1950 | 1950 | |
1951 | - $listName = lcfirst( substr( $listName, 3 ) ); |
|
1951 | + $listName = lcfirst(substr($listName, 3)); |
|
1952 | 1952 | |
1953 | - return ( isset( $this->__info['sys.exclusive-'.$listName] ) && $this->__info['sys.exclusive-'.$listName] ); |
|
1953 | + return (isset($this->__info['sys.exclusive-' . $listName]) && $this->__info['sys.exclusive-' . $listName]); |
|
1954 | 1954 | } |
1955 | 1955 | |
1956 | 1956 | /** |
@@ -1964,33 +1964,33 @@ discard block |
||
1964 | 1964 | * |
1965 | 1965 | * @return mixed |
1966 | 1966 | */ |
1967 | - public function &__get( $property ) |
|
1967 | + public function &__get($property) |
|
1968 | 1968 | { |
1969 | 1969 | $isEx = FALSE; |
1970 | 1970 | $isOwn = FALSE; |
1971 | 1971 | $isShared = FALSE; |
1972 | 1972 | |
1973 | - if ( !ctype_lower( $property ) ) { |
|
1974 | - $property = $this->beau( $property ); |
|
1975 | - if ( strpos( $property, 'xown' ) === 0 && ctype_upper( substr( $property, 4, 1 ) ) ) { |
|
1973 | + if (!ctype_lower($property)) { |
|
1974 | + $property = $this->beau($property); |
|
1975 | + if (strpos($property, 'xown') === 0 && ctype_upper(substr($property, 4, 1))) { |
|
1976 | 1976 | $property = substr($property, 1); |
1977 | - $listName = lcfirst( substr( $property, 3 ) ); |
|
1977 | + $listName = lcfirst(substr($property, 3)); |
|
1978 | 1978 | $isEx = TRUE; |
1979 | 1979 | $isOwn = TRUE; |
1980 | - $this->__info['sys.exclusive-'.$listName] = TRUE; |
|
1981 | - } elseif ( strpos( $property, 'own' ) === 0 && ctype_upper( substr( $property, 3, 1 ) ) ) { |
|
1980 | + $this->__info['sys.exclusive-' . $listName] = TRUE; |
|
1981 | + } elseif (strpos($property, 'own') === 0 && ctype_upper(substr($property, 3, 1))) { |
|
1982 | 1982 | $isOwn = TRUE; |
1983 | - $listName = lcfirst( substr( $property, 3 ) ); |
|
1984 | - } elseif ( strpos( $property, 'shared' ) === 0 && ctype_upper( substr( $property, 6, 1 ) ) ) { |
|
1983 | + $listName = lcfirst(substr($property, 3)); |
|
1984 | + } elseif (strpos($property, 'shared') === 0 && ctype_upper(substr($property, 6, 1))) { |
|
1985 | 1985 | $isShared = TRUE; |
1986 | 1986 | } |
1987 | 1987 | } |
1988 | 1988 | |
1989 | 1989 | $fieldLink = $property . '_id'; |
1990 | - $exists = isset( $this->properties[$property] ); |
|
1990 | + $exists = isset($this->properties[$property]); |
|
1991 | 1991 | |
1992 | 1992 | //If not exists and no field link and no list, bail out. |
1993 | - if ( !$exists && !isset($this->$fieldLink) && (!$isOwn && !$isShared )) { |
|
1993 | + if (!$exists && !isset($this->$fieldLink) && (!$isOwn && !$isShared)) { |
|
1994 | 1994 | |
1995 | 1995 | $this->withSql = ''; |
1996 | 1996 | $this->withParams = array(); |
@@ -2005,13 +2005,13 @@ discard block |
||
2005 | 2005 | } |
2006 | 2006 | |
2007 | 2007 | $hasAlias = (!is_null($this->aliasName)); |
2008 | - $differentAlias = ($hasAlias && $isOwn && isset($this->__info['sys.alias.'.$listName])) ? |
|
2009 | - ($this->__info['sys.alias.'.$listName] !== $this->aliasName) : FALSE; |
|
2008 | + $differentAlias = ($hasAlias && $isOwn && isset($this->__info['sys.alias.' . $listName])) ? |
|
2009 | + ($this->__info['sys.alias.' . $listName] !== $this->aliasName) : FALSE; |
|
2010 | 2010 | $hasSQL = ($this->withSql !== '' || $this->via !== NULL); |
2011 | 2011 | $hasAll = (boolean) ($this->all); |
2012 | 2012 | |
2013 | 2013 | //If exists and no list or exits and list not changed, bail out. |
2014 | - if ( $exists && ((!$isOwn && !$isShared ) || (!$hasSQL && !$differentAlias && !$hasAll)) ) { |
|
2014 | + if ($exists && ((!$isOwn && !$isShared) || (!$hasSQL && !$differentAlias && !$hasAll))) { |
|
2015 | 2015 | |
2016 | 2016 | $this->withSql = ''; |
2017 | 2017 | $this->withParams = array(); |
@@ -2024,30 +2024,30 @@ discard block |
||
2024 | 2024 | } |
2025 | 2025 | |
2026 | 2026 | |
2027 | - list( $redbean, , , $toolbox ) = $this->beanHelper->getExtractedToolbox(); |
|
2027 | + list($redbean,,, $toolbox) = $this->beanHelper->getExtractedToolbox(); |
|
2028 | 2028 | |
2029 | - if ( isset( $this->$fieldLink ) ) { |
|
2029 | + if (isset($this->$fieldLink)) { |
|
2030 | 2030 | $this->__info['tainted'] = TRUE; |
2031 | 2031 | |
2032 | - if ( isset( $this->__info["sys.parentcache.$property"] ) ) { |
|
2032 | + if (isset($this->__info["sys.parentcache.$property"])) { |
|
2033 | 2033 | $bean = $this->__info["sys.parentcache.$property"]; |
2034 | 2034 | } else { |
2035 | - if ( isset( self::$aliases[$property] ) ) { |
|
2035 | + if (isset(self::$aliases[$property])) { |
|
2036 | 2036 | $type = self::$aliases[$property]; |
2037 | - } elseif ( $this->fetchType ) { |
|
2037 | + } elseif ($this->fetchType) { |
|
2038 | 2038 | $type = $this->fetchType; |
2039 | 2039 | $this->fetchType = NULL; |
2040 | 2040 | } else { |
2041 | 2041 | $type = $property; |
2042 | 2042 | } |
2043 | 2043 | $bean = NULL; |
2044 | - if ( !is_null( $this->properties[$fieldLink] ) ) { |
|
2045 | - $bean = $redbean->load( $type, $this->properties[$fieldLink] ); |
|
2044 | + if (!is_null($this->properties[$fieldLink])) { |
|
2045 | + $bean = $redbean->load($type, $this->properties[$fieldLink]); |
|
2046 | 2046 | //If the IDs dont match, we failed to load, so try autoresolv in that case... |
2047 | - if ( $bean->id !== $this->properties[$fieldLink] && self::$autoResolve ) { |
|
2048 | - $type = $this->beanHelper->getToolbox()->getWriter()->inferFetchType( $this->__info['type'], $property ); |
|
2049 | - if ( !is_null( $type) ) { |
|
2050 | - $bean = $redbean->load( $type, $this->properties[$fieldLink] ); |
|
2047 | + if ($bean->id !== $this->properties[$fieldLink] && self::$autoResolve) { |
|
2048 | + $type = $this->beanHelper->getToolbox()->getWriter()->inferFetchType($this->__info['type'], $property); |
|
2049 | + if (!is_null($type)) { |
|
2050 | + $bean = $redbean->load($type, $this->properties[$fieldLink]); |
|
2051 | 2051 | $this->__info["sys.autoresolved.{$property}"] = $type; |
2052 | 2052 | } |
2053 | 2053 | } |
@@ -2067,12 +2067,12 @@ discard block |
||
2067 | 2067 | |
2068 | 2068 | } |
2069 | 2069 | //Implicit: elseif ( $isOwn || $isShared ) { |
2070 | - if ( $this->noLoad ) { |
|
2070 | + if ($this->noLoad) { |
|
2071 | 2071 | $beans = array(); |
2072 | - } elseif ( $isOwn ) { |
|
2073 | - $beans = $this->getOwnList( $listName, $redbean ); |
|
2072 | + } elseif ($isOwn) { |
|
2073 | + $beans = $this->getOwnList($listName, $redbean); |
|
2074 | 2074 | } else { |
2075 | - $beans = $this->getSharedList( lcfirst( substr( $property, 6 ) ), $redbean, $toolbox ); |
|
2075 | + $beans = $this->getSharedList(lcfirst(substr($property, 6)), $redbean, $toolbox); |
|
2076 | 2076 | } |
2077 | 2077 | |
2078 | 2078 | $this->properties[$property] = $beans; |
@@ -2104,43 +2104,43 @@ discard block |
||
2104 | 2104 | * |
2105 | 2105 | * @throws Security |
2106 | 2106 | */ |
2107 | - public function __set( $property, $value ) |
|
2107 | + public function __set($property, $value) |
|
2108 | 2108 | { |
2109 | 2109 | $isEx = FALSE; |
2110 | 2110 | $isOwn = FALSE; |
2111 | 2111 | $isShared = FALSE; |
2112 | 2112 | |
2113 | - if ( !ctype_lower( $property ) ) { |
|
2114 | - $property = $this->beau( $property ); |
|
2115 | - if ( strpos( $property, 'xown' ) === 0 && ctype_upper( substr( $property, 4, 1 ) ) ) { |
|
2113 | + if (!ctype_lower($property)) { |
|
2114 | + $property = $this->beau($property); |
|
2115 | + if (strpos($property, 'xown') === 0 && ctype_upper(substr($property, 4, 1))) { |
|
2116 | 2116 | $property = substr($property, 1); |
2117 | - $listName = lcfirst( substr( $property, 3 ) ); |
|
2117 | + $listName = lcfirst(substr($property, 3)); |
|
2118 | 2118 | $isEx = TRUE; |
2119 | 2119 | $isOwn = TRUE; |
2120 | - $this->__info['sys.exclusive-'.$listName] = TRUE; |
|
2121 | - } elseif ( strpos( $property, 'own' ) === 0 && ctype_upper( substr( $property, 3, 1 ) ) ) { |
|
2120 | + $this->__info['sys.exclusive-' . $listName] = TRUE; |
|
2121 | + } elseif (strpos($property, 'own') === 0 && ctype_upper(substr($property, 3, 1))) { |
|
2122 | 2122 | $isOwn = TRUE; |
2123 | - $listName = lcfirst( substr( $property, 3 ) ); |
|
2124 | - } elseif ( strpos( $property, 'shared' ) === 0 && ctype_upper( substr( $property, 6, 1 ) ) ) { |
|
2123 | + $listName = lcfirst(substr($property, 3)); |
|
2124 | + } elseif (strpos($property, 'shared') === 0 && ctype_upper(substr($property, 6, 1))) { |
|
2125 | 2125 | $isShared = TRUE; |
2126 | 2126 | } |
2127 | 2127 | } |
2128 | 2128 | |
2129 | 2129 | $hasAlias = (!is_null($this->aliasName)); |
2130 | - $differentAlias = ($hasAlias && $isOwn && isset($this->__info['sys.alias.'.$listName])) ? |
|
2131 | - ($this->__info['sys.alias.'.$listName] !== $this->aliasName) : FALSE; |
|
2130 | + $differentAlias = ($hasAlias && $isOwn && isset($this->__info['sys.alias.' . $listName])) ? |
|
2131 | + ($this->__info['sys.alias.' . $listName] !== $this->aliasName) : FALSE; |
|
2132 | 2132 | $hasSQL = ($this->withSql !== '' || $this->via !== NULL); |
2133 | - $exists = isset( $this->properties[$property] ); |
|
2133 | + $exists = isset($this->properties[$property]); |
|
2134 | 2134 | $fieldLink = $property . '_id'; |
2135 | 2135 | |
2136 | - if ( ($isOwn || $isShared) && (!$exists || $hasSQL || $differentAlias) ) { |
|
2136 | + if (($isOwn || $isShared) && (!$exists || $hasSQL || $differentAlias)) { |
|
2137 | 2137 | |
2138 | - if ( !$this->noLoad ) { |
|
2139 | - list( $redbean, , , $toolbox ) = $this->beanHelper->getExtractedToolbox(); |
|
2140 | - if ( $isOwn ) { |
|
2141 | - $beans = $this->getOwnList( $listName, $redbean ); |
|
2138 | + if (!$this->noLoad) { |
|
2139 | + list($redbean,,, $toolbox) = $this->beanHelper->getExtractedToolbox(); |
|
2140 | + if ($isOwn) { |
|
2141 | + $beans = $this->getOwnList($listName, $redbean); |
|
2142 | 2142 | } else { |
2143 | - $beans = $this->getSharedList( lcfirst( substr( $property, 6 ) ), $redbean, $toolbox ); |
|
2143 | + $beans = $this->getSharedList(lcfirst(substr($property, 6)), $redbean, $toolbox); |
|
2144 | 2144 | } |
2145 | 2145 | $this->__info["sys.shadow.$property"] = $beans; |
2146 | 2146 | } |
@@ -2157,24 +2157,24 @@ discard block |
||
2157 | 2157 | $this->__info['tainted'] = TRUE; |
2158 | 2158 | $this->__info['changed'] = TRUE; |
2159 | 2159 | |
2160 | - if ( array_key_exists( $fieldLink, $this->properties ) && !( $value instanceof OODBBean ) ) { |
|
2161 | - if ( is_null( $value ) || $value === FALSE ) { |
|
2160 | + if (array_key_exists($fieldLink, $this->properties) && !($value instanceof OODBBean)) { |
|
2161 | + if (is_null($value) || $value === FALSE) { |
|
2162 | 2162 | |
2163 | - unset( $this->properties[ $property ]); |
|
2164 | - $this->properties[ $fieldLink ] = NULL; |
|
2163 | + unset($this->properties[$property]); |
|
2164 | + $this->properties[$fieldLink] = NULL; |
|
2165 | 2165 | |
2166 | 2166 | return; |
2167 | 2167 | } else { |
2168 | - throw new RedException( 'Cannot cast to bean.' ); |
|
2168 | + throw new RedException('Cannot cast to bean.'); |
|
2169 | 2169 | } |
2170 | 2170 | } |
2171 | 2171 | |
2172 | - if ( $value === FALSE ) { |
|
2172 | + if ($value === FALSE) { |
|
2173 | 2173 | $value = '0'; |
2174 | - } elseif ( $value === TRUE ) { |
|
2174 | + } elseif ($value === TRUE) { |
|
2175 | 2175 | $value = '1'; |
2176 | - } elseif ( $value instanceof \DateTime ) { |
|
2177 | - $value = $value->format( 'Y-m-d H:i:s' ); |
|
2176 | + } elseif ($value instanceof \DateTime) { |
|
2177 | + $value = $value->format('Y-m-d H:i:s'); |
|
2178 | 2178 | } |
2179 | 2179 | |
2180 | 2180 | $this->properties[$property] = $value; |
@@ -2190,15 +2190,15 @@ discard block |
||
2190 | 2190 | * |
2191 | 2191 | * @return void |
2192 | 2192 | */ |
2193 | - public function setProperty( $property, $value, $updateShadow = FALSE, $taint = FALSE ) |
|
2193 | + public function setProperty($property, $value, $updateShadow = FALSE, $taint = FALSE) |
|
2194 | 2194 | { |
2195 | 2195 | $this->properties[$property] = $value; |
2196 | 2196 | |
2197 | - if ( $updateShadow ) { |
|
2197 | + if ($updateShadow) { |
|
2198 | 2198 | $this->__info['sys.shadow.' . $property] = $value; |
2199 | 2199 | } |
2200 | 2200 | |
2201 | - if ( $taint ) { |
|
2201 | + if ($taint) { |
|
2202 | 2202 | $this->__info['tainted'] = TRUE; |
2203 | 2203 | $this->__info['changed'] = TRUE; |
2204 | 2204 | } |
@@ -2223,9 +2223,9 @@ discard block |
||
2223 | 2223 | * |
2224 | 2224 | * @return mixed |
2225 | 2225 | */ |
2226 | - public function getMeta( $path, $default = NULL ) |
|
2226 | + public function getMeta($path, $default = NULL) |
|
2227 | 2227 | { |
2228 | - return ( isset( $this->__info[$path] ) ) ? $this->__info[$path] : $default; |
|
2228 | + return (isset($this->__info[$path])) ? $this->__info[$path] : $default; |
|
2229 | 2229 | } |
2230 | 2230 | |
2231 | 2231 | /** |
@@ -2239,11 +2239,11 @@ discard block |
||
2239 | 2239 | * |
2240 | 2240 | * @return mixed |
2241 | 2241 | */ |
2242 | - public function moveMeta( $path, $value = NULL ) |
|
2242 | + public function moveMeta($path, $value = NULL) |
|
2243 | 2243 | { |
2244 | - if ( isset( $this->__info[$path] ) ) { |
|
2245 | - $value = $this->__info[ $path ]; |
|
2246 | - unset( $this->__info[ $path ] ); |
|
2244 | + if (isset($this->__info[$path])) { |
|
2245 | + $value = $this->__info[$path]; |
|
2246 | + unset($this->__info[$path]); |
|
2247 | 2247 | } |
2248 | 2248 | return $value; |
2249 | 2249 | } |
@@ -2261,7 +2261,7 @@ discard block |
||
2261 | 2261 | * |
2262 | 2262 | * @return OODBBean |
2263 | 2263 | */ |
2264 | - public function setMeta( $path, $value ) |
|
2264 | + public function setMeta($path, $value) |
|
2265 | 2265 | { |
2266 | 2266 | $this->__info[$path] = $value; |
2267 | 2267 | |
@@ -2277,7 +2277,7 @@ discard block |
||
2277 | 2277 | * |
2278 | 2278 | * @return OODBBean |
2279 | 2279 | */ |
2280 | - public function copyMetaFrom( OODBBean $bean ) |
|
2280 | + public function copyMetaFrom(OODBBean $bean) |
|
2281 | 2281 | { |
2282 | 2282 | $this->__info = $bean->__info; |
2283 | 2283 | |
@@ -2292,40 +2292,40 @@ discard block |
||
2292 | 2292 | * |
2293 | 2293 | * @return mixed |
2294 | 2294 | */ |
2295 | - public function __call( $method, $args ) |
|
2295 | + public function __call($method, $args) |
|
2296 | 2296 | { |
2297 | - if ( !isset( $this->__info['model'] ) ) { |
|
2298 | - $model = $this->beanHelper->getModelForBean( $this ); |
|
2297 | + if (!isset($this->__info['model'])) { |
|
2298 | + $model = $this->beanHelper->getModelForBean($this); |
|
2299 | 2299 | |
2300 | - if ( !$model ) { |
|
2300 | + if (!$model) { |
|
2301 | 2301 | return NULL; |
2302 | 2302 | } |
2303 | 2303 | |
2304 | 2304 | $this->__info['model'] = $model; |
2305 | 2305 | } |
2306 | - if ( !method_exists( $this->__info['model'], $method ) ) { |
|
2306 | + if (!method_exists($this->__info['model'], $method)) { |
|
2307 | 2307 | |
2308 | - if ( self::$errorHandlingFUSE === FALSE ) { |
|
2308 | + if (self::$errorHandlingFUSE === FALSE) { |
|
2309 | 2309 | return NULL; |
2310 | 2310 | } |
2311 | 2311 | |
2312 | - if ( in_array( $method, array( 'update', 'open', 'delete', 'after_delete', 'after_update', 'dispense' ), TRUE ) ) { |
|
2312 | + if (in_array($method, array('update', 'open', 'delete', 'after_delete', 'after_update', 'dispense'), TRUE)) { |
|
2313 | 2313 | return NULL; |
2314 | 2314 | } |
2315 | 2315 | |
2316 | 2316 | $message = "FUSE: method does not exist in model: $method"; |
2317 | - if ( self::$errorHandlingFUSE === self::C_ERR_LOG ) { |
|
2318 | - error_log( $message ); |
|
2317 | + if (self::$errorHandlingFUSE === self::C_ERR_LOG) { |
|
2318 | + error_log($message); |
|
2319 | 2319 | return NULL; |
2320 | - } elseif ( self::$errorHandlingFUSE === self::C_ERR_NOTICE ) { |
|
2321 | - trigger_error( $message, E_USER_NOTICE ); |
|
2320 | + } elseif (self::$errorHandlingFUSE === self::C_ERR_NOTICE) { |
|
2321 | + trigger_error($message, E_USER_NOTICE); |
|
2322 | 2322 | return NULL; |
2323 | - } elseif ( self::$errorHandlingFUSE === self::C_ERR_WARN ) { |
|
2324 | - trigger_error( $message, E_USER_WARNING ); |
|
2323 | + } elseif (self::$errorHandlingFUSE === self::C_ERR_WARN) { |
|
2324 | + trigger_error($message, E_USER_WARNING); |
|
2325 | 2325 | return NULL; |
2326 | - } elseif ( self::$errorHandlingFUSE === self::C_ERR_EXCEPTION ) { |
|
2327 | - throw new \Exception( $message ); |
|
2328 | - } elseif ( self::$errorHandlingFUSE === self::C_ERR_FUNC ) { |
|
2326 | + } elseif (self::$errorHandlingFUSE === self::C_ERR_EXCEPTION) { |
|
2327 | + throw new \Exception($message); |
|
2328 | + } elseif (self::$errorHandlingFUSE === self::C_ERR_FUNC) { |
|
2329 | 2329 | $func = self::$errorHandler; |
2330 | 2330 | return $func(array( |
2331 | 2331 | 'message' => $message, |
@@ -2334,11 +2334,11 @@ discard block |
||
2334 | 2334 | 'bean' => $this |
2335 | 2335 | )); |
2336 | 2336 | } |
2337 | - trigger_error( $message, E_USER_ERROR ); |
|
2337 | + trigger_error($message, E_USER_ERROR); |
|
2338 | 2338 | return NULL; |
2339 | 2339 | } |
2340 | 2340 | |
2341 | - return call_user_func_array( array( $this->__info['model'], $method ), $args ); |
|
2341 | + return call_user_func_array(array($this->__info['model'], $method), $args); |
|
2342 | 2342 | } |
2343 | 2343 | |
2344 | 2344 | /** |
@@ -2353,10 +2353,10 @@ discard block |
||
2353 | 2353 | */ |
2354 | 2354 | public function __toString() |
2355 | 2355 | { |
2356 | - $string = $this->__call( '__toString', array() ); |
|
2356 | + $string = $this->__call('__toString', array()); |
|
2357 | 2357 | |
2358 | - if ( $string === NULL ) { |
|
2359 | - return json_encode( $this->properties ); |
|
2358 | + if ($string === NULL) { |
|
2359 | + return json_encode($this->properties); |
|
2360 | 2360 | } else { |
2361 | 2361 | return $string; |
2362 | 2362 | } |
@@ -2372,9 +2372,9 @@ discard block |
||
2372 | 2372 | * |
2373 | 2373 | * @return void |
2374 | 2374 | */ |
2375 | - public function offsetSet( $offset, $value ) |
|
2375 | + public function offsetSet($offset, $value) |
|
2376 | 2376 | { |
2377 | - $this->__set( $offset, $value ); |
|
2377 | + $this->__set($offset, $value); |
|
2378 | 2378 | } |
2379 | 2379 | |
2380 | 2380 | /** |
@@ -2389,9 +2389,9 @@ discard block |
||
2389 | 2389 | * |
2390 | 2390 | * @return boolean |
2391 | 2391 | */ |
2392 | - public function offsetExists( $offset ) |
|
2392 | + public function offsetExists($offset) |
|
2393 | 2393 | { |
2394 | - return $this->__isset( $offset ); |
|
2394 | + return $this->__isset($offset); |
|
2395 | 2395 | } |
2396 | 2396 | |
2397 | 2397 | /** |
@@ -2407,9 +2407,9 @@ discard block |
||
2407 | 2407 | * |
2408 | 2408 | * @return void |
2409 | 2409 | */ |
2410 | - public function offsetUnset( $offset ) |
|
2410 | + public function offsetUnset($offset) |
|
2411 | 2411 | { |
2412 | - $this->__unset( $offset ); |
|
2412 | + $this->__unset($offset); |
|
2413 | 2413 | } |
2414 | 2414 | |
2415 | 2415 | /** |
@@ -2425,9 +2425,9 @@ discard block |
||
2425 | 2425 | * |
2426 | 2426 | * @return mixed |
2427 | 2427 | */ |
2428 | - public function &offsetGet( $offset ) |
|
2428 | + public function &offsetGet($offset) |
|
2429 | 2429 | { |
2430 | - return $this->__get( $offset ); |
|
2430 | + return $this->__get($offset); |
|
2431 | 2431 | } |
2432 | 2432 | |
2433 | 2433 | /** |
@@ -2439,7 +2439,7 @@ discard block |
||
2439 | 2439 | * |
2440 | 2440 | * @return OODBBean |
2441 | 2441 | */ |
2442 | - public function fetchAs( $type ) |
|
2442 | + public function fetchAs($type) |
|
2443 | 2443 | { |
2444 | 2444 | $this->fetchType = $type; |
2445 | 2445 | |
@@ -2454,9 +2454,9 @@ discard block |
||
2454 | 2454 | * |
2455 | 2455 | * @return OODBBean |
2456 | 2456 | */ |
2457 | - public function poly( $field ) |
|
2457 | + public function poly($field) |
|
2458 | 2458 | { |
2459 | - return $this->fetchAs( $this->$field ); |
|
2459 | + return $this->fetchAs($this->$field); |
|
2460 | 2460 | } |
2461 | 2461 | |
2462 | 2462 | /** |
@@ -2471,15 +2471,15 @@ discard block |
||
2471 | 2471 | * |
2472 | 2472 | * @return OODBBean |
2473 | 2473 | */ |
2474 | - public function traverse( $property, $function, $maxDepth = NULL ) |
|
2474 | + public function traverse($property, $function, $maxDepth = NULL) |
|
2475 | 2475 | { |
2476 | 2476 | $this->via = NULL; |
2477 | - if ( strpos( $property, 'shared' ) !== FALSE ) { |
|
2478 | - throw new RedException( 'Traverse only works with (x)own-lists.' ); |
|
2477 | + if (strpos($property, 'shared') !== FALSE) { |
|
2478 | + throw new RedException('Traverse only works with (x)own-lists.'); |
|
2479 | 2479 | } |
2480 | 2480 | |
2481 | - if ( !is_null( $maxDepth ) ) { |
|
2482 | - if ( !$maxDepth-- ) return $this; |
|
2481 | + if (!is_null($maxDepth)) { |
|
2482 | + if (!$maxDepth--) return $this; |
|
2483 | 2483 | } |
2484 | 2484 | |
2485 | 2485 | $oldFetchType = $this->fetchType; |
@@ -2489,20 +2489,20 @@ discard block |
||
2489 | 2489 | |
2490 | 2490 | $beans = $this->$property; |
2491 | 2491 | |
2492 | - if ( $beans === NULL ) return $this; |
|
2492 | + if ($beans === NULL) return $this; |
|
2493 | 2493 | |
2494 | - if ( !is_array( $beans ) ) $beans = array( $beans ); |
|
2494 | + if (!is_array($beans)) $beans = array($beans); |
|
2495 | 2495 | |
2496 | - foreach( $beans as $bean ) { |
|
2496 | + foreach ($beans as $bean) { |
|
2497 | 2497 | |
2498 | - $function( $bean ); |
|
2498 | + $function($bean); |
|
2499 | 2499 | |
2500 | 2500 | $bean->fetchType = $oldFetchType; |
2501 | 2501 | $bean->aliasName = $oldAliasName; |
2502 | 2502 | $bean->withSql = $oldWith; |
2503 | 2503 | $bean->withParams = $oldBindings; |
2504 | 2504 | |
2505 | - $bean->traverse( $property, $function, $maxDepth ); |
|
2505 | + $bean->traverse($property, $function, $maxDepth); |
|
2506 | 2506 | } |
2507 | 2507 | |
2508 | 2508 | return $this; |
@@ -2516,7 +2516,7 @@ discard block |
||
2516 | 2516 | */ |
2517 | 2517 | public function count() |
2518 | 2518 | { |
2519 | - return count( $this->properties ); |
|
2519 | + return count($this->properties); |
|
2520 | 2520 | } |
2521 | 2521 | |
2522 | 2522 | /** |
@@ -2529,11 +2529,11 @@ discard block |
||
2529 | 2529 | public function isEmpty() |
2530 | 2530 | { |
2531 | 2531 | $empty = TRUE; |
2532 | - foreach ( $this->properties as $key => $value ) { |
|
2533 | - if ( $key == 'id' ) { |
|
2532 | + foreach ($this->properties as $key => $value) { |
|
2533 | + if ($key == 'id') { |
|
2534 | 2534 | continue; |
2535 | 2535 | } |
2536 | - if ( !empty( $value ) ) { |
|
2536 | + if (!empty($value)) { |
|
2537 | 2537 | $empty = FALSE; |
2538 | 2538 | } |
2539 | 2539 | } |
@@ -2549,7 +2549,7 @@ discard block |
||
2549 | 2549 | * |
2550 | 2550 | * @return OODBBean |
2551 | 2551 | */ |
2552 | - public function setAttr( $property, $value ) |
|
2552 | + public function setAttr($property, $value) |
|
2553 | 2553 | { |
2554 | 2554 | $this->$property = $value; |
2555 | 2555 | |
@@ -2564,11 +2564,11 @@ discard block |
||
2564 | 2564 | * |
2565 | 2565 | * @return OODBBean |
2566 | 2566 | */ |
2567 | - public function unsetAll( $properties ) |
|
2567 | + public function unsetAll($properties) |
|
2568 | 2568 | { |
2569 | - foreach ( $properties as $prop ) { |
|
2570 | - if ( isset( $this->properties[$prop] ) ) { |
|
2571 | - unset( $this->properties[$prop] ); |
|
2569 | + foreach ($properties as $prop) { |
|
2570 | + if (isset($this->properties[$prop])) { |
|
2571 | + unset($this->properties[$prop]); |
|
2572 | 2572 | } |
2573 | 2573 | } |
2574 | 2574 | |
@@ -2584,11 +2584,11 @@ discard block |
||
2584 | 2584 | * |
2585 | 2585 | * @return mixed |
2586 | 2586 | */ |
2587 | - public function old( $property ) |
|
2587 | + public function old($property) |
|
2588 | 2588 | { |
2589 | - $old = $this->getMeta( 'sys.orig', array() ); |
|
2589 | + $old = $this->getMeta('sys.orig', array()); |
|
2590 | 2590 | |
2591 | - if ( array_key_exists( $property, $old ) ) { |
|
2591 | + if (array_key_exists($property, $old)) { |
|
2592 | 2592 | return $old[$property]; |
2593 | 2593 | } |
2594 | 2594 | |
@@ -2608,7 +2608,7 @@ discard block |
||
2608 | 2608 | */ |
2609 | 2609 | public function isTainted() |
2610 | 2610 | { |
2611 | - return $this->getMeta( 'tainted' ); |
|
2611 | + return $this->getMeta('tainted'); |
|
2612 | 2612 | } |
2613 | 2613 | |
2614 | 2614 | /** |
@@ -2624,10 +2624,10 @@ discard block |
||
2624 | 2624 | * |
2625 | 2625 | * @return boolean |
2626 | 2626 | */ |
2627 | - public function hasChanged( $property ) |
|
2627 | + public function hasChanged($property) |
|
2628 | 2628 | { |
2629 | - return ( array_key_exists( $property, $this->properties ) ) ? |
|
2630 | - $this->old( $property ) != $this->properties[$property] : FALSE; |
|
2629 | + return (array_key_exists($property, $this->properties)) ? |
|
2630 | + $this->old($property) != $this->properties[$property] : FALSE; |
|
2631 | 2631 | } |
2632 | 2632 | |
2633 | 2633 | /** |
@@ -2639,13 +2639,13 @@ discard block |
||
2639 | 2639 | * |
2640 | 2640 | * @return boolean |
2641 | 2641 | */ |
2642 | - public function hasListChanged( $property ) |
|
2642 | + public function hasListChanged($property) |
|
2643 | 2643 | { |
2644 | - if ( !array_key_exists( $property, $this->properties ) ) return FALSE; |
|
2645 | - $diffAdded = array_diff_assoc( $this->properties[$property], $this->__info['sys.shadow.'.$property] ); |
|
2646 | - if ( count( $diffAdded ) ) return TRUE; |
|
2647 | - $diffMissing = array_diff_assoc( $this->__info['sys.shadow.'.$property], $this->properties[$property] ); |
|
2648 | - if ( count( $diffMissing ) ) return TRUE; |
|
2644 | + if (!array_key_exists($property, $this->properties)) return FALSE; |
|
2645 | + $diffAdded = array_diff_assoc($this->properties[$property], $this->__info['sys.shadow.' . $property]); |
|
2646 | + if (count($diffAdded)) return TRUE; |
|
2647 | + $diffMissing = array_diff_assoc($this->__info['sys.shadow.' . $property], $this->properties[$property]); |
|
2648 | + if (count($diffMissing)) return TRUE; |
|
2649 | 2649 | return FALSE; |
2650 | 2650 | } |
2651 | 2651 | |
@@ -2658,11 +2658,11 @@ discard block |
||
2658 | 2658 | public function clearHistory() |
2659 | 2659 | { |
2660 | 2660 | $this->__info['sys.orig'] = array(); |
2661 | - foreach( $this->properties as $key => $value ) { |
|
2662 | - if ( is_scalar($value) ) { |
|
2661 | + foreach ($this->properties as $key => $value) { |
|
2662 | + if (is_scalar($value)) { |
|
2663 | 2663 | $this->__info['sys.orig'][$key] = $value; |
2664 | 2664 | } else { |
2665 | - $this->__info['sys.shadow.'.$key] = $value; |
|
2665 | + $this->__info['sys.shadow.' . $key] = $value; |
|
2666 | 2666 | } |
2667 | 2667 | } |
2668 | 2668 | return $this; |
@@ -2693,30 +2693,30 @@ discard block |
||
2693 | 2693 | * |
2694 | 2694 | * @return OODBBean |
2695 | 2695 | */ |
2696 | - public function link( $typeOrBean, $qualification = array() ) |
|
2696 | + public function link($typeOrBean, $qualification = array()) |
|
2697 | 2697 | { |
2698 | - if ( is_string( $typeOrBean ) ) { |
|
2698 | + if (is_string($typeOrBean)) { |
|
2699 | 2699 | |
2700 | - $typeOrBean = AQueryWriter::camelsSnake( $typeOrBean ); |
|
2700 | + $typeOrBean = AQueryWriter::camelsSnake($typeOrBean); |
|
2701 | 2701 | |
2702 | - $bean = $this->beanHelper->getToolBox()->getRedBean()->dispense( $typeOrBean ); |
|
2702 | + $bean = $this->beanHelper->getToolBox()->getRedBean()->dispense($typeOrBean); |
|
2703 | 2703 | |
2704 | - if ( is_string( $qualification ) ) { |
|
2705 | - $data = json_decode( $qualification, TRUE ); |
|
2704 | + if (is_string($qualification)) { |
|
2705 | + $data = json_decode($qualification, TRUE); |
|
2706 | 2706 | } else { |
2707 | 2707 | $data = $qualification; |
2708 | 2708 | } |
2709 | 2709 | |
2710 | - foreach ( $data as $key => $value ) { |
|
2710 | + foreach ($data as $key => $value) { |
|
2711 | 2711 | $bean->$key = $value; |
2712 | 2712 | } |
2713 | 2713 | } else { |
2714 | 2714 | $bean = $typeOrBean; |
2715 | 2715 | } |
2716 | 2716 | |
2717 | - $list = 'own' . ucfirst( $bean->getMeta( 'type' ) ); |
|
2717 | + $list = 'own' . ucfirst($bean->getMeta('type')); |
|
2718 | 2718 | |
2719 | - array_push( $this->$list, $bean ); |
|
2719 | + array_push($this->$list, $bean); |
|
2720 | 2720 | |
2721 | 2721 | return $bean; |
2722 | 2722 | } |
@@ -2728,7 +2728,7 @@ discard block |
||
2728 | 2728 | */ |
2729 | 2729 | public function fresh() |
2730 | 2730 | { |
2731 | - return $this->beanHelper->getToolbox()->getRedBean()->load( $this->getMeta( 'type' ), $this->properties['id'] ); |
|
2731 | + return $this->beanHelper->getToolbox()->getRedBean()->load($this->getMeta('type'), $this->properties['id']); |
|
2732 | 2732 | } |
2733 | 2733 | |
2734 | 2734 | /** |
@@ -2738,9 +2738,9 @@ discard block |
||
2738 | 2738 | * |
2739 | 2739 | * @return OODBBean |
2740 | 2740 | */ |
2741 | - public function via( $via ) |
|
2741 | + public function via($via) |
|
2742 | 2742 | { |
2743 | - $this->via = AQueryWriter::camelsSnake( $via ); |
|
2743 | + $this->via = AQueryWriter::camelsSnake($via); |
|
2744 | 2744 | |
2745 | 2745 | return $this; |
2746 | 2746 | } |
@@ -2753,11 +2753,11 @@ discard block |
||
2753 | 2753 | * |
2754 | 2754 | * @return integer |
2755 | 2755 | */ |
2756 | - public function countOwn( $type ) |
|
2756 | + public function countOwn($type) |
|
2757 | 2757 | { |
2758 | - $type = $this->beau( $type ); |
|
2758 | + $type = $this->beau($type); |
|
2759 | 2759 | |
2760 | - if ( $this->aliasName ) { |
|
2760 | + if ($this->aliasName) { |
|
2761 | 2761 | $myFieldLink = $this->aliasName . '_id'; |
2762 | 2762 | |
2763 | 2763 | $this->aliasName = NULL; |
@@ -2767,23 +2767,23 @@ discard block |
||
2767 | 2767 | |
2768 | 2768 | $count = 0; |
2769 | 2769 | |
2770 | - if ( $this->getID() ) { |
|
2770 | + if ($this->getID()) { |
|
2771 | 2771 | |
2772 | 2772 | $firstKey = NULL; |
2773 | - if ( count( $this->withParams ) > 0 ) { |
|
2774 | - reset( $this->withParams ); |
|
2775 | - $firstKey = key( $this->withParams ); |
|
2773 | + if (count($this->withParams) > 0) { |
|
2774 | + reset($this->withParams); |
|
2775 | + $firstKey = key($this->withParams); |
|
2776 | 2776 | } |
2777 | 2777 | |
2778 | - $joinSql = $this->parseJoin( $type ); |
|
2778 | + $joinSql = $this->parseJoin($type); |
|
2779 | 2779 | |
2780 | - if ( !is_numeric( $firstKey ) || $firstKey === NULL ) { |
|
2780 | + if (!is_numeric($firstKey) || $firstKey === NULL) { |
|
2781 | 2781 | $bindings = $this->withParams; |
2782 | 2782 | $bindings[':slot0'] = $this->getID(); |
2783 | - $count = $this->beanHelper->getToolbox()->getWriter()->queryRecordCount( $type, array(), " {$joinSql} $myFieldLink = :slot0 " . $this->withSql, $bindings ); |
|
2783 | + $count = $this->beanHelper->getToolbox()->getWriter()->queryRecordCount($type, array(), " {$joinSql} $myFieldLink = :slot0 " . $this->withSql, $bindings); |
|
2784 | 2784 | } else { |
2785 | - $bindings = array_merge( array( $this->getID() ), $this->withParams ); |
|
2786 | - $count = $this->beanHelper->getToolbox()->getWriter()->queryRecordCount( $type, array(), " {$joinSql} $myFieldLink = ? " . $this->withSql, $bindings ); |
|
2785 | + $bindings = array_merge(array($this->getID()), $this->withParams); |
|
2786 | + $count = $this->beanHelper->getToolbox()->getWriter()->queryRecordCount($type, array(), " {$joinSql} $myFieldLink = ? " . $this->withSql, $bindings); |
|
2787 | 2787 | } |
2788 | 2788 | |
2789 | 2789 | } |
@@ -2800,27 +2800,27 @@ discard block |
||
2800 | 2800 | * |
2801 | 2801 | * @return integer |
2802 | 2802 | */ |
2803 | - public function countShared( $type ) |
|
2803 | + public function countShared($type) |
|
2804 | 2804 | { |
2805 | 2805 | $toolbox = $this->beanHelper->getToolbox(); |
2806 | 2806 | $redbean = $toolbox->getRedBean(); |
2807 | 2807 | $writer = $toolbox->getWriter(); |
2808 | 2808 | |
2809 | - if ( $this->via ) { |
|
2810 | - $oldName = $writer->getAssocTable( array( $this->__info['type'], $type ) ); |
|
2809 | + if ($this->via) { |
|
2810 | + $oldName = $writer->getAssocTable(array($this->__info['type'], $type)); |
|
2811 | 2811 | |
2812 | - if ( $oldName !== $this->via ) { |
|
2812 | + if ($oldName !== $this->via) { |
|
2813 | 2813 | //set the new renaming rule |
2814 | - $writer->renameAssocTable( $oldName, $this->via ); |
|
2814 | + $writer->renameAssocTable($oldName, $this->via); |
|
2815 | 2815 | $this->via = NULL; |
2816 | 2816 | } |
2817 | 2817 | } |
2818 | 2818 | |
2819 | - $type = $this->beau( $type ); |
|
2819 | + $type = $this->beau($type); |
|
2820 | 2820 | $count = 0; |
2821 | 2821 | |
2822 | - if ( $this->getID() ) { |
|
2823 | - $count = $redbean->getAssociationManager()->relatedCount( $this, $type, $this->withSql, $this->withParams, TRUE ); |
|
2822 | + if ($this->getID()) { |
|
2823 | + $count = $redbean->getAssociationManager()->relatedCount($this, $type, $this->withSql, $this->withParams, TRUE); |
|
2824 | 2824 | } |
2825 | 2825 | |
2826 | 2826 | $this->clearModifiers(); |
@@ -2851,33 +2851,33 @@ discard block |
||
2851 | 2851 | * |
2852 | 2852 | * @return array |
2853 | 2853 | */ |
2854 | - public function &aggr( $list, $property, $type = NULL ) |
|
2854 | + public function &aggr($list, $property, $type = NULL) |
|
2855 | 2855 | { |
2856 | 2856 | $this->via = NULL; |
2857 | 2857 | $ids = $beanIndex = $references = array(); |
2858 | 2858 | |
2859 | - if ( strlen( $list ) < 4 ) throw new RedException('Invalid own-list.'); |
|
2860 | - if ( strpos( $list, 'own') !== 0 ) throw new RedException('Only own-lists can be aggregated.'); |
|
2861 | - if ( !ctype_upper( substr( $list, 3, 1 ) ) ) throw new RedException('Invalid own-list.'); |
|
2859 | + if (strlen($list) < 4) throw new RedException('Invalid own-list.'); |
|
2860 | + if (strpos($list, 'own') !== 0) throw new RedException('Only own-lists can be aggregated.'); |
|
2861 | + if (!ctype_upper(substr($list, 3, 1))) throw new RedException('Invalid own-list.'); |
|
2862 | 2862 | |
2863 | - if ( is_null( $type ) ) $type = $property; |
|
2863 | + if (is_null($type)) $type = $property; |
|
2864 | 2864 | |
2865 | - foreach( $this->$list as $bean ) { |
|
2865 | + foreach ($this->$list as $bean) { |
|
2866 | 2866 | $field = $property . '_id'; |
2867 | - if ( isset( $bean->$field) ) { |
|
2867 | + if (isset($bean->$field)) { |
|
2868 | 2868 | $ids[] = $bean->$field; |
2869 | 2869 | $beanIndex[$bean->$field] = $bean; |
2870 | 2870 | } |
2871 | 2871 | } |
2872 | 2872 | |
2873 | - $beans = $this->beanHelper->getToolBox()->getRedBean()->batch( $type, $ids ); |
|
2873 | + $beans = $this->beanHelper->getToolBox()->getRedBean()->batch($type, $ids); |
|
2874 | 2874 | |
2875 | 2875 | //now preload the beans as well |
2876 | - foreach( $beans as $bean ) { |
|
2877 | - $beanIndex[$bean->id]->setProperty( $property, $bean ); |
|
2876 | + foreach ($beans as $bean) { |
|
2877 | + $beanIndex[$bean->id]->setProperty($property, $bean); |
|
2878 | 2878 | } |
2879 | 2879 | |
2880 | - foreach( $beanIndex as $indexedBean ) { |
|
2880 | + foreach ($beanIndex as $indexedBean) { |
|
2881 | 2881 | $references[] = $indexedBean->$property; |
2882 | 2882 | } |
2883 | 2883 | |
@@ -2894,8 +2894,8 @@ discard block |
||
2894 | 2894 | public function equals(OODBBean $bean) |
2895 | 2895 | { |
2896 | 2896 | return (bool) ( |
2897 | - ( (string) $this->properties['id'] === (string) $bean->properties['id'] ) |
|
2898 | - && ( (string) $this->__info['type'] === (string) $bean->__info['type'] ) |
|
2897 | + ((string) $this->properties['id'] === (string) $bean->properties['id']) |
|
2898 | + && ((string) $this->__info['type'] === (string) $bean->__info['type']) |
|
2899 | 2899 | ); |
2900 | 2900 | } |
2901 | 2901 | } |
@@ -2937,14 +2937,14 @@ discard block |
||
2937 | 2937 | * |
2938 | 2938 | * @return void |
2939 | 2939 | */ |
2940 | - public function addEventListener( $eventname, Observer $observer ) |
|
2940 | + public function addEventListener($eventname, Observer $observer) |
|
2941 | 2941 | { |
2942 | - if ( !isset( $this->observers[$eventname] ) ) { |
|
2942 | + if (!isset($this->observers[$eventname])) { |
|
2943 | 2943 | $this->observers[$eventname] = array(); |
2944 | 2944 | } |
2945 | 2945 | |
2946 | - foreach ( $this->observers[$eventname] as $o ) { |
|
2947 | - if ( $o == $observer ) { |
|
2946 | + foreach ($this->observers[$eventname] as $o) { |
|
2947 | + if ($o == $observer) { |
|
2948 | 2948 | return; |
2949 | 2949 | } |
2950 | 2950 | } |
@@ -2963,14 +2963,14 @@ discard block |
||
2963 | 2963 | * |
2964 | 2964 | * @return void |
2965 | 2965 | */ |
2966 | - public function signal( $eventname, $info ) |
|
2966 | + public function signal($eventname, $info) |
|
2967 | 2967 | { |
2968 | - if ( !isset( $this->observers[$eventname] ) ) { |
|
2968 | + if (!isset($this->observers[$eventname])) { |
|
2969 | 2969 | $this->observers[$eventname] = array(); |
2970 | 2970 | } |
2971 | 2971 | |
2972 | - foreach ( $this->observers[$eventname] as $observer ) { |
|
2973 | - $observer->onEvent( $eventname, $info ); |
|
2972 | + foreach ($this->observers[$eventname] as $observer) { |
|
2973 | + $observer->onEvent($eventname, $info); |
|
2974 | 2974 | } |
2975 | 2975 | } |
2976 | 2976 | } |
@@ -3007,7 +3007,7 @@ discard block |
||
3007 | 3007 | * |
3008 | 3008 | * @return void |
3009 | 3009 | */ |
3010 | - public function onEvent( $eventname, $bean ); |
|
3010 | + public function onEvent($eventname, $bean); |
|
3011 | 3011 | } |
3012 | 3012 | } |
3013 | 3013 | |
@@ -3047,7 +3047,7 @@ discard block |
||
3047 | 3047 | * @param array $bindings values |
3048 | 3048 | * @param boolean $noevent no event firing |
3049 | 3049 | */ |
3050 | - public function exec( $sql, $bindings = array(), $noevent = FALSE ); |
|
3050 | + public function exec($sql, $bindings = array(), $noevent = FALSE); |
|
3051 | 3051 | |
3052 | 3052 | /** |
3053 | 3053 | * Executes an SQL Query and returns a resultset. |
@@ -3060,7 +3060,7 @@ discard block |
||
3060 | 3060 | * |
3061 | 3061 | * @return array |
3062 | 3062 | */ |
3063 | - public function get( $sql, $bindings = array() ); |
|
3063 | + public function get($sql, $bindings = array()); |
|
3064 | 3064 | |
3065 | 3065 | /** |
3066 | 3066 | * Executes an SQL Query and returns a resultset. |
@@ -3073,7 +3073,7 @@ discard block |
||
3073 | 3073 | * |
3074 | 3074 | * @return array |
3075 | 3075 | */ |
3076 | - public function getRow( $sql, $bindings = array() ); |
|
3076 | + public function getRow($sql, $bindings = array()); |
|
3077 | 3077 | |
3078 | 3078 | /** |
3079 | 3079 | * Executes an SQL Query and returns a resultset. |
@@ -3086,7 +3086,7 @@ discard block |
||
3086 | 3086 | * |
3087 | 3087 | * @return array |
3088 | 3088 | */ |
3089 | - public function getCol( $sql, $bindings = array() ); |
|
3089 | + public function getCol($sql, $bindings = array()); |
|
3090 | 3090 | |
3091 | 3091 | /** |
3092 | 3092 | * Executes an SQL Query and returns a resultset. |
@@ -3099,7 +3099,7 @@ discard block |
||
3099 | 3099 | * |
3100 | 3100 | * @return string |
3101 | 3101 | */ |
3102 | - public function getCell( $sql, $bindings = array() ); |
|
3102 | + public function getCell($sql, $bindings = array()); |
|
3103 | 3103 | |
3104 | 3104 | /** |
3105 | 3105 | * Executes the SQL query specified in $sql and takes |
@@ -3114,7 +3114,7 @@ discard block |
||
3114 | 3114 | * |
3115 | 3115 | * @return array |
3116 | 3116 | */ |
3117 | - public function getAssoc( $sql, $bindings = array() ); |
|
3117 | + public function getAssoc($sql, $bindings = array()); |
|
3118 | 3118 | |
3119 | 3119 | /** |
3120 | 3120 | * Executes the SQL query specified in $sql and indexes |
@@ -3125,7 +3125,7 @@ discard block |
||
3125 | 3125 | * |
3126 | 3126 | * @return array |
3127 | 3127 | */ |
3128 | - public function getAssocRow( $sql, $bindings = array() ); |
|
3128 | + public function getAssocRow($sql, $bindings = array()); |
|
3129 | 3129 | |
3130 | 3130 | /** |
3131 | 3131 | * Returns the latest insert ID. |
@@ -3150,7 +3150,7 @@ discard block |
||
3150 | 3150 | * |
3151 | 3151 | * @return Cursor |
3152 | 3152 | */ |
3153 | - public function getCursor( $sql, $bindings = array() ); |
|
3153 | + public function getCursor($sql, $bindings = array()); |
|
3154 | 3154 | |
3155 | 3155 | /** |
3156 | 3156 | * Returns the original database resource. This is useful if you want to |
@@ -3244,7 +3244,7 @@ discard block |
||
3244 | 3244 | * |
3245 | 3245 | * @param Driver $database ADO Compatible DB Instance |
3246 | 3246 | */ |
3247 | - public function __construct( $database ) |
|
3247 | + public function __construct($database) |
|
3248 | 3248 | { |
3249 | 3249 | $this->db = $database; |
3250 | 3250 | } |
@@ -3260,76 +3260,76 @@ discard block |
||
3260 | 3260 | /** |
3261 | 3261 | * @see Adapter::exec |
3262 | 3262 | */ |
3263 | - public function exec( $sql, $bindings = array(), $noevent = FALSE ) |
|
3263 | + public function exec($sql, $bindings = array(), $noevent = FALSE) |
|
3264 | 3264 | { |
3265 | - if ( !$noevent ) { |
|
3265 | + if (!$noevent) { |
|
3266 | 3266 | $this->sql = $sql; |
3267 | - $this->signal( 'sql_exec', $this ); |
|
3267 | + $this->signal('sql_exec', $this); |
|
3268 | 3268 | } |
3269 | 3269 | |
3270 | - return $this->db->Execute( $sql, $bindings ); |
|
3270 | + return $this->db->Execute($sql, $bindings); |
|
3271 | 3271 | } |
3272 | 3272 | |
3273 | 3273 | /** |
3274 | 3274 | * @see Adapter::get |
3275 | 3275 | */ |
3276 | - public function get( $sql, $bindings = array() ) |
|
3276 | + public function get($sql, $bindings = array()) |
|
3277 | 3277 | { |
3278 | 3278 | $this->sql = $sql; |
3279 | - $this->signal( 'sql_exec', $this ); |
|
3279 | + $this->signal('sql_exec', $this); |
|
3280 | 3280 | |
3281 | - return $this->db->GetAll( $sql, $bindings ); |
|
3281 | + return $this->db->GetAll($sql, $bindings); |
|
3282 | 3282 | } |
3283 | 3283 | |
3284 | 3284 | /** |
3285 | 3285 | * @see Adapter::getRow |
3286 | 3286 | */ |
3287 | - public function getRow( $sql, $bindings = array() ) |
|
3287 | + public function getRow($sql, $bindings = array()) |
|
3288 | 3288 | { |
3289 | 3289 | $this->sql = $sql; |
3290 | - $this->signal( 'sql_exec', $this ); |
|
3290 | + $this->signal('sql_exec', $this); |
|
3291 | 3291 | |
3292 | - return $this->db->GetRow( $sql, $bindings ); |
|
3292 | + return $this->db->GetRow($sql, $bindings); |
|
3293 | 3293 | } |
3294 | 3294 | |
3295 | 3295 | /** |
3296 | 3296 | * @see Adapter::getCol |
3297 | 3297 | */ |
3298 | - public function getCol( $sql, $bindings = array() ) |
|
3298 | + public function getCol($sql, $bindings = array()) |
|
3299 | 3299 | { |
3300 | 3300 | $this->sql = $sql; |
3301 | - $this->signal( 'sql_exec', $this ); |
|
3301 | + $this->signal('sql_exec', $this); |
|
3302 | 3302 | |
3303 | - return $this->db->GetCol( $sql, $bindings ); |
|
3303 | + return $this->db->GetCol($sql, $bindings); |
|
3304 | 3304 | } |
3305 | 3305 | |
3306 | 3306 | /** |
3307 | 3307 | * @see Adapter::getAssoc |
3308 | 3308 | */ |
3309 | - public function getAssoc( $sql, $bindings = array() ) |
|
3309 | + public function getAssoc($sql, $bindings = array()) |
|
3310 | 3310 | { |
3311 | 3311 | $this->sql = $sql; |
3312 | 3312 | |
3313 | - $this->signal( 'sql_exec', $this ); |
|
3313 | + $this->signal('sql_exec', $this); |
|
3314 | 3314 | |
3315 | - $rows = $this->db->GetAll( $sql, $bindings ); |
|
3315 | + $rows = $this->db->GetAll($sql, $bindings); |
|
3316 | 3316 | |
3317 | 3317 | $assoc = array(); |
3318 | - if ( !$rows ) { |
|
3318 | + if (!$rows) { |
|
3319 | 3319 | return $assoc; |
3320 | 3320 | } |
3321 | 3321 | |
3322 | - foreach ( $rows as $row ) { |
|
3323 | - if ( empty( $row ) ) continue; |
|
3322 | + foreach ($rows as $row) { |
|
3323 | + if (empty($row)) continue; |
|
3324 | 3324 | |
3325 | - if ( count( $row ) > 2 ) { |
|
3326 | - $key = array_shift( $row ); |
|
3325 | + if (count($row) > 2) { |
|
3326 | + $key = array_shift($row); |
|
3327 | 3327 | $value = $row; |
3328 | - } elseif ( count( $row ) > 1 ) { |
|
3329 | - $key = array_shift( $row ); |
|
3330 | - $value = array_shift( $row ); |
|
3328 | + } elseif (count($row) > 1) { |
|
3329 | + $key = array_shift($row); |
|
3330 | + $value = array_shift($row); |
|
3331 | 3331 | } else { |
3332 | - $key = array_shift( $row ); |
|
3332 | + $key = array_shift($row); |
|
3333 | 3333 | $value = $key; |
3334 | 3334 | } |
3335 | 3335 | |
@@ -3345,29 +3345,29 @@ discard block |
||
3345 | 3345 | public function getAssocRow($sql, $bindings = array()) |
3346 | 3346 | { |
3347 | 3347 | $this->sql = $sql; |
3348 | - $this->signal( 'sql_exec', $this ); |
|
3348 | + $this->signal('sql_exec', $this); |
|
3349 | 3349 | |
3350 | - return $this->db->GetAssocRow( $sql, $bindings ); |
|
3350 | + return $this->db->GetAssocRow($sql, $bindings); |
|
3351 | 3351 | } |
3352 | 3352 | |
3353 | 3353 | /** |
3354 | 3354 | * @see Adapter::getCell |
3355 | 3355 | */ |
3356 | - public function getCell( $sql, $bindings = array(), $noSignal = NULL ) |
|
3356 | + public function getCell($sql, $bindings = array(), $noSignal = NULL) |
|
3357 | 3357 | { |
3358 | 3358 | $this->sql = $sql; |
3359 | 3359 | |
3360 | - if ( !$noSignal ) $this->signal( 'sql_exec', $this ); |
|
3360 | + if (!$noSignal) $this->signal('sql_exec', $this); |
|
3361 | 3361 | |
3362 | - return $this->db->GetOne( $sql, $bindings ); |
|
3362 | + return $this->db->GetOne($sql, $bindings); |
|
3363 | 3363 | } |
3364 | 3364 | |
3365 | 3365 | /** |
3366 | 3366 | * @see Adapter::getCursor |
3367 | 3367 | */ |
3368 | - public function getCursor( $sql, $bindings = array() ) |
|
3368 | + public function getCursor($sql, $bindings = array()) |
|
3369 | 3369 | { |
3370 | - return $this->db->GetCursor( $sql, $bindings ); |
|
3370 | + return $this->db->GetCursor($sql, $bindings); |
|
3371 | 3371 | } |
3372 | 3372 | |
3373 | 3373 | /** |
@@ -3502,7 +3502,7 @@ discard block |
||
3502 | 3502 | * |
3503 | 3503 | * @return void |
3504 | 3504 | */ |
3505 | - public function __construct( \PDOStatement $res, $fetchStyle ) |
|
3505 | + public function __construct(\PDOStatement $res, $fetchStyle) |
|
3506 | 3506 | { |
3507 | 3507 | $this->res = $res; |
3508 | 3508 | $this->fetchStyle = $fetchStyle; |
@@ -3618,7 +3618,7 @@ discard block |
||
3618 | 3618 | * |
3619 | 3619 | * @return void |
3620 | 3620 | */ |
3621 | - public function __construct( $type, Repository $repository, Cursor $cursor ) |
|
3621 | + public function __construct($type, Repository $repository, Cursor $cursor) |
|
3622 | 3622 | { |
3623 | 3623 | $this->type = $type; |
3624 | 3624 | $this->cursor = $cursor; |
@@ -3636,9 +3636,9 @@ discard block |
||
3636 | 3636 | public function next() |
3637 | 3637 | { |
3638 | 3638 | $row = $this->cursor->getNextItem(); |
3639 | - if ( $row ) { |
|
3640 | - $beans = $this->repository->convertToBeans( $this->type, array( $row ) ); |
|
3641 | - $bean = array_shift( $beans ); |
|
3639 | + if ($row) { |
|
3640 | + $beans = $this->repository->convertToBeans($this->type, array($row)); |
|
3641 | + $bean = array_shift($beans); |
|
3642 | 3642 | return $bean; |
3643 | 3643 | } |
3644 | 3644 | return NULL; |
@@ -3732,7 +3732,7 @@ discard block |
||
3732 | 3732 | * |
3733 | 3733 | * @return string $joinSQLSnippet |
3734 | 3734 | */ |
3735 | - public function writeJoin( $type, $targetType, $joinType ); |
|
3735 | + public function writeJoin($type, $targetType, $joinType); |
|
3736 | 3736 | |
3737 | 3737 | /** |
3738 | 3738 | * Glues an SQL snippet to the beginning of a WHERE clause. |
@@ -3765,7 +3765,7 @@ discard block |
||
3765 | 3765 | * |
3766 | 3766 | * @return string |
3767 | 3767 | */ |
3768 | - public function glueSQLCondition( $sql, $glue = NULL ); |
|
3768 | + public function glueSQLCondition($sql, $glue = NULL); |
|
3769 | 3769 | |
3770 | 3770 | /** |
3771 | 3771 | * Determines if there is a LIMIT 1 clause in the SQL. |
@@ -3778,7 +3778,7 @@ discard block |
||
3778 | 3778 | * |
3779 | 3779 | * @return string |
3780 | 3780 | */ |
3781 | - public function glueLimitOne( $sql ); |
|
3781 | + public function glueLimitOne($sql); |
|
3782 | 3782 | |
3783 | 3783 | /** |
3784 | 3784 | * Returns the tables that are in the database. |
@@ -3795,7 +3795,7 @@ discard block |
||
3795 | 3795 | * |
3796 | 3796 | * @return void |
3797 | 3797 | */ |
3798 | - public function createTable( $type ); |
|
3798 | + public function createTable($type); |
|
3799 | 3799 | |
3800 | 3800 | /** |
3801 | 3801 | * Returns an array containing all the columns of the specified type. |
@@ -3809,7 +3809,7 @@ discard block |
||
3809 | 3809 | * |
3810 | 3810 | * @return array |
3811 | 3811 | */ |
3812 | - public function getColumns( $type ); |
|
3812 | + public function getColumns($type); |
|
3813 | 3813 | |
3814 | 3814 | /** |
3815 | 3815 | * Returns the Column Type Code (integer) that corresponds |
@@ -3820,7 +3820,7 @@ discard block |
||
3820 | 3820 | * |
3821 | 3821 | * @return integer |
3822 | 3822 | */ |
3823 | - public function scanType( $value, $alsoScanSpecialForTypes = FALSE ); |
|
3823 | + public function scanType($value, $alsoScanSpecialForTypes = FALSE); |
|
3824 | 3824 | |
3825 | 3825 | /** |
3826 | 3826 | * This method will add a column to a table. |
@@ -3832,7 +3832,7 @@ discard block |
||
3832 | 3832 | * |
3833 | 3833 | * @return void |
3834 | 3834 | */ |
3835 | - public function addColumn( $type, $column, $field ); |
|
3835 | + public function addColumn($type, $column, $field); |
|
3836 | 3836 | |
3837 | 3837 | /** |
3838 | 3838 | * Returns the Type Code for a Column Description. |
@@ -3846,7 +3846,7 @@ discard block |
||
3846 | 3846 | * |
3847 | 3847 | * @return integer |
3848 | 3848 | */ |
3849 | - public function code( $typedescription, $includeSpecials = FALSE ); |
|
3849 | + public function code($typedescription, $includeSpecials = FALSE); |
|
3850 | 3850 | |
3851 | 3851 | /** |
3852 | 3852 | * This method will widen the column to the specified data type. |
@@ -3858,7 +3858,7 @@ discard block |
||
3858 | 3858 | * |
3859 | 3859 | * @return void |
3860 | 3860 | */ |
3861 | - public function widenColumn( $type, $column, $datatype ); |
|
3861 | + public function widenColumn($type, $column, $datatype); |
|
3862 | 3862 | |
3863 | 3863 | /** |
3864 | 3864 | * Selects records from the database. |
@@ -3872,7 +3872,7 @@ discard block |
||
3872 | 3872 | * |
3873 | 3873 | * @return array |
3874 | 3874 | */ |
3875 | - public function queryRecord( $type, $conditions = array(), $addSql = NULL, $bindings = array() ); |
|
3875 | + public function queryRecord($type, $conditions = array(), $addSql = NULL, $bindings = array()); |
|
3876 | 3876 | |
3877 | 3877 | /** |
3878 | 3878 | * Selects records from the database and returns a cursor. |
@@ -3886,7 +3886,7 @@ discard block |
||
3886 | 3886 | * |
3887 | 3887 | * @return Cursor |
3888 | 3888 | */ |
3889 | - public function queryRecordWithCursor( $type, $addSql = NULL, $bindings = array() ); |
|
3889 | + public function queryRecordWithCursor($type, $addSql = NULL, $bindings = array()); |
|
3890 | 3890 | |
3891 | 3891 | /** |
3892 | 3892 | * Returns records through an intermediate type. This method is used to obtain records using a link table and |
@@ -3900,7 +3900,7 @@ discard block |
||
3900 | 3900 | * |
3901 | 3901 | * @return array |
3902 | 3902 | */ |
3903 | - public function queryRecordRelated( $sourceType, $destType, $linkID, $addSql = '', $bindings = array() ); |
|
3903 | + public function queryRecordRelated($sourceType, $destType, $linkID, $addSql = '', $bindings = array()); |
|
3904 | 3904 | |
3905 | 3905 | /** |
3906 | 3906 | * Returns the row that links $sourceType $sourcID to $destType $destID in an N-M relation. |
@@ -3912,7 +3912,7 @@ discard block |
||
3912 | 3912 | * |
3913 | 3913 | * @return array|null |
3914 | 3914 | */ |
3915 | - public function queryRecordLink( $sourceType, $destType, $sourceID, $destID ); |
|
3915 | + public function queryRecordLink($sourceType, $destType, $sourceID, $destID); |
|
3916 | 3916 | |
3917 | 3917 | /** |
3918 | 3918 | * Counts the number of records in the database that match the |
@@ -3925,7 +3925,7 @@ discard block |
||
3925 | 3925 | * |
3926 | 3926 | * @return integer |
3927 | 3927 | */ |
3928 | - public function queryRecordCount( $type, $conditions = array(), $addSql = NULL, $bindings = array() ); |
|
3928 | + public function queryRecordCount($type, $conditions = array(), $addSql = NULL, $bindings = array()); |
|
3929 | 3929 | |
3930 | 3930 | /** |
3931 | 3931 | * Returns the number of records linked through $linkType and satisfying the SQL in $addSQL/$bindings. |
@@ -3938,7 +3938,7 @@ discard block |
||
3938 | 3938 | * |
3939 | 3939 | * @return integer |
3940 | 3940 | */ |
3941 | - public function queryRecordCountRelated( $sourceType, $targetType, $linkID, $addSQL = '', $bindings = array() ); |
|
3941 | + public function queryRecordCountRelated($sourceType, $targetType, $linkID, $addSQL = '', $bindings = array()); |
|
3942 | 3942 | |
3943 | 3943 | /** |
3944 | 3944 | * Returns all rows of specified type that have been tagged with one of the |
@@ -3955,7 +3955,7 @@ discard block |
||
3955 | 3955 | * |
3956 | 3956 | * @return array |
3957 | 3957 | */ |
3958 | - public function queryTagged( $type, $tagList, $all = FALSE, $addSql = '', $bindings = array() ); |
|
3958 | + public function queryTagged($type, $tagList, $all = FALSE, $addSql = '', $bindings = array()); |
|
3959 | 3959 | |
3960 | 3960 | /** |
3961 | 3961 | * This method should update (or insert a record), it takes |
@@ -3971,7 +3971,7 @@ discard block |
||
3971 | 3971 | * |
3972 | 3972 | * @return integer |
3973 | 3973 | */ |
3974 | - public function updateRecord( $type, $updatevalues, $id = NULL ); |
|
3974 | + public function updateRecord($type, $updatevalues, $id = NULL); |
|
3975 | 3975 | |
3976 | 3976 | /** |
3977 | 3977 | * Deletes records from the database. |
@@ -3984,7 +3984,7 @@ discard block |
||
3984 | 3984 | * |
3985 | 3985 | * @return void |
3986 | 3986 | */ |
3987 | - public function deleteRecord( $type, $conditions = array(), $addSql = '', $bindings = array() ); |
|
3987 | + public function deleteRecord($type, $conditions = array(), $addSql = '', $bindings = array()); |
|
3988 | 3988 | |
3989 | 3989 | /** |
3990 | 3990 | * Deletes all links between $sourceType and $destType in an N-M relation. |
@@ -3995,12 +3995,12 @@ discard block |
||
3995 | 3995 | * |
3996 | 3996 | * @return void |
3997 | 3997 | */ |
3998 | - public function deleteRelations( $sourceType, $destType, $sourceID ); |
|
3998 | + public function deleteRelations($sourceType, $destType, $sourceID); |
|
3999 | 3999 | |
4000 | 4000 | /** |
4001 | 4001 | * @see QueryWriter::addUniqueConstaint |
4002 | 4002 | */ |
4003 | - public function addUniqueIndex( $type, $columns ); |
|
4003 | + public function addUniqueIndex($type, $columns); |
|
4004 | 4004 | |
4005 | 4005 | /** |
4006 | 4006 | * This method will add a UNIQUE constraint index to a table on columns $columns. |
@@ -4011,7 +4011,7 @@ discard block |
||
4011 | 4011 | * |
4012 | 4012 | * @return void |
4013 | 4013 | */ |
4014 | - public function addUniqueConstraint( $type, $columns ); |
|
4014 | + public function addUniqueConstraint($type, $columns); |
|
4015 | 4015 | |
4016 | 4016 | /** |
4017 | 4017 | * This method will check whether the SQL state is in the list of specified states |
@@ -4025,7 +4025,7 @@ discard block |
||
4025 | 4025 | * |
4026 | 4026 | * @return boolean |
4027 | 4027 | */ |
4028 | - public function sqlStateIn( $state, $list ); |
|
4028 | + public function sqlStateIn($state, $list); |
|
4029 | 4029 | |
4030 | 4030 | /** |
4031 | 4031 | * This method will remove all beans of a certain type. |
@@ -4035,7 +4035,7 @@ discard block |
||
4035 | 4035 | * |
4036 | 4036 | * @return void |
4037 | 4037 | */ |
4038 | - public function wipe( $type ); |
|
4038 | + public function wipe($type); |
|
4039 | 4039 | |
4040 | 4040 | /** |
4041 | 4041 | * This method will add a foreign key from type and field to |
@@ -4055,7 +4055,7 @@ discard block |
||
4055 | 4055 | * |
4056 | 4056 | * @return void |
4057 | 4057 | */ |
4058 | - public function addFK( $type, $targetType, $property, $targetProperty, $isDep = false ); |
|
4058 | + public function addFK($type, $targetType, $property, $targetProperty, $isDep = false); |
|
4059 | 4059 | |
4060 | 4060 | /** |
4061 | 4061 | * This method will add an index to a type and field with name |
@@ -4068,7 +4068,7 @@ discard block |
||
4068 | 4068 | * |
4069 | 4069 | * @return void |
4070 | 4070 | */ |
4071 | - public function addIndex( $type, $name, $property ); |
|
4071 | + public function addIndex($type, $name, $property); |
|
4072 | 4072 | |
4073 | 4073 | /** |
4074 | 4074 | * Checks and filters a database structure element like a table of column |
@@ -4082,7 +4082,7 @@ discard block |
||
4082 | 4082 | * |
4083 | 4083 | * @return string |
4084 | 4084 | */ |
4085 | - public function esc( $databaseStructure, $dontQuote = FALSE ); |
|
4085 | + public function esc($databaseStructure, $dontQuote = FALSE); |
|
4086 | 4086 | |
4087 | 4087 | /** |
4088 | 4088 | * Removes all tables and views from the database. |
@@ -4112,7 +4112,7 @@ discard block |
||
4112 | 4112 | * |
4113 | 4113 | * @return void |
4114 | 4114 | */ |
4115 | - public function renameAssocTable( $fromType, $toType = NULL ); |
|
4115 | + public function renameAssocTable($fromType, $toType = NULL); |
|
4116 | 4116 | |
4117 | 4117 | /** |
4118 | 4118 | * Returns the format for link tables. |
@@ -4125,7 +4125,7 @@ discard block |
||
4125 | 4125 | * |
4126 | 4126 | * @return string |
4127 | 4127 | */ |
4128 | - public function getAssocTable( $types ); |
|
4128 | + public function getAssocTable($types); |
|
4129 | 4129 | |
4130 | 4130 | /** |
4131 | 4131 | * Given a bean type and a property, this method |
@@ -4142,7 +4142,7 @@ discard block |
||
4142 | 4142 | * |
4143 | 4143 | * @return string|NULL |
4144 | 4144 | */ |
4145 | - public function inferFetchType( $type, $property ); |
|
4145 | + public function inferFetchType($type, $property); |
|
4146 | 4146 | } |
4147 | 4147 | } |
4148 | 4148 | |
@@ -4234,30 +4234,30 @@ discard block |
||
4234 | 4234 | * |
4235 | 4235 | * @return boolean |
4236 | 4236 | */ |
4237 | - public static function canBeTreatedAsInt( $value ) |
|
4237 | + public static function canBeTreatedAsInt($value) |
|
4238 | 4238 | { |
4239 | - return (bool) ( strval( $value ) === strval( intval( $value ) ) ); |
|
4239 | + return (bool) (strval($value) === strval(intval($value))); |
|
4240 | 4240 | } |
4241 | 4241 | |
4242 | 4242 | /** |
4243 | 4243 | * @see QueryWriter::getAssocTableFormat |
4244 | 4244 | */ |
4245 | - public static function getAssocTableFormat( $types ) |
|
4245 | + public static function getAssocTableFormat($types) |
|
4246 | 4246 | { |
4247 | - sort( $types ); |
|
4247 | + sort($types); |
|
4248 | 4248 | |
4249 | - $assoc = implode( '_', $types ); |
|
4249 | + $assoc = implode('_', $types); |
|
4250 | 4250 | |
4251 | - return ( isset( self::$renames[$assoc] ) ) ? self::$renames[$assoc] : $assoc; |
|
4251 | + return (isset(self::$renames[$assoc])) ? self::$renames[$assoc] : $assoc; |
|
4252 | 4252 | } |
4253 | 4253 | |
4254 | 4254 | /** |
4255 | 4255 | * @see QueryWriter::renameAssociation |
4256 | 4256 | */ |
4257 | - public static function renameAssociation( $from, $to = NULL ) |
|
4257 | + public static function renameAssociation($from, $to = NULL) |
|
4258 | 4258 | { |
4259 | - if ( is_array( $from ) ) { |
|
4260 | - foreach ( $from as $key => $value ) self::$renames[$key] = $value; |
|
4259 | + if (is_array($from)) { |
|
4260 | + foreach ($from as $key => $value) self::$renames[$key] = $value; |
|
4261 | 4261 | |
4262 | 4262 | return; |
4263 | 4263 | } |
@@ -4273,9 +4273,9 @@ discard block |
||
4273 | 4273 | * |
4274 | 4274 | * @return string |
4275 | 4275 | */ |
4276 | - public static function camelsSnake( $camel ) |
|
4276 | + public static function camelsSnake($camel) |
|
4277 | 4277 | { |
4278 | - return strtolower( preg_replace( '/(?<=[a-z])([A-Z])|([A-Z])(?=[a-z])/', '_$1$2', $camel ) ); |
|
4278 | + return strtolower(preg_replace('/(?<=[a-z])([A-Z])|([A-Z])(?=[a-z])/', '_$1$2', $camel)); |
|
4279 | 4279 | } |
4280 | 4280 | |
4281 | 4281 | /** |
@@ -4308,7 +4308,7 @@ discard block |
||
4308 | 4308 | * |
4309 | 4309 | * @return void |
4310 | 4310 | */ |
4311 | - public static function setNarrowFieldMode( $narrowField ) |
|
4311 | + public static function setNarrowFieldMode($narrowField) |
|
4312 | 4312 | { |
4313 | 4313 | self::$flagNarrowFieldMode = (boolean) $narrowField; |
4314 | 4314 | } |
@@ -4342,7 +4342,7 @@ discard block |
||
4342 | 4342 | * |
4343 | 4343 | * @param array |
4344 | 4344 | */ |
4345 | - public static function setSQLFilters( $sqlFilters, $safeMode = false ) |
|
4345 | + public static function setSQLFilters($sqlFilters, $safeMode = false) |
|
4346 | 4346 | { |
4347 | 4347 | self::$flagSQLFilterSafeMode = (boolean) $safeMode; |
4348 | 4348 | self::$sqlFilters = $sqlFilters; |
@@ -4370,9 +4370,9 @@ discard block |
||
4370 | 4370 | * |
4371 | 4371 | * @return string |
4372 | 4372 | */ |
4373 | - private function getCacheKey( $keyValues ) |
|
4373 | + private function getCacheKey($keyValues) |
|
4374 | 4374 | { |
4375 | - return json_encode( $keyValues ); |
|
4375 | + return json_encode($keyValues); |
|
4376 | 4376 | } |
4377 | 4377 | |
4378 | 4378 | /** |
@@ -4383,12 +4383,12 @@ discard block |
||
4383 | 4383 | * |
4384 | 4384 | * @return mixed |
4385 | 4385 | */ |
4386 | - private function getCached( $cacheTag, $key ) |
|
4386 | + private function getCached($cacheTag, $key) |
|
4387 | 4387 | { |
4388 | 4388 | $sql = $this->adapter->getSQL(); |
4389 | 4389 | |
4390 | 4390 | if ($this->updateCache()) { |
4391 | - if ( isset( $this->cache[$cacheTag][$key] ) ) { |
|
4391 | + if (isset($this->cache[$cacheTag][$key])) { |
|
4392 | 4392 | return $this->cache[$cacheTag][$key]; |
4393 | 4393 | } |
4394 | 4394 | } |
@@ -4408,7 +4408,7 @@ discard block |
||
4408 | 4408 | private function updateCache() |
4409 | 4409 | { |
4410 | 4410 | $sql = $this->adapter->getSQL(); |
4411 | - if ( strpos( $sql, '-- keep-cache' ) !== strlen( $sql ) - 13 ) { |
|
4411 | + if (strpos($sql, '-- keep-cache') !== strlen($sql) - 13) { |
|
4412 | 4412 | // If SQL has been taken place outside of this method then something else then |
4413 | 4413 | // a select query might have happened! (or instruct to keep cache) |
4414 | 4414 | $this->cache = array(); |
@@ -4435,10 +4435,10 @@ discard block |
||
4435 | 4435 | * |
4436 | 4436 | * @return void |
4437 | 4437 | */ |
4438 | - private function putResultInCache( $cacheTag, $key, $values ) |
|
4438 | + private function putResultInCache($cacheTag, $key, $values) |
|
4439 | 4439 | { |
4440 | - if ( isset( $this->cache[$cacheTag] ) ) { |
|
4441 | - if ( count( $this->cache[$cacheTag] ) > $this->maxCacheSizePerType ) array_shift( $this->cache[$cacheTag] ); |
|
4440 | + if (isset($this->cache[$cacheTag])) { |
|
4441 | + if (count($this->cache[$cacheTag]) > $this->maxCacheSizePerType) array_shift($this->cache[$cacheTag]); |
|
4442 | 4442 | } else { |
4443 | 4443 | $this->cache[$cacheTag] = array(); |
4444 | 4444 | } |
@@ -4461,63 +4461,63 @@ discard block |
||
4461 | 4461 | * |
4462 | 4462 | * @return string |
4463 | 4463 | */ |
4464 | - private function makeSQLFromConditions( $conditions, &$bindings, $addSql = '' ) |
|
4464 | + private function makeSQLFromConditions($conditions, &$bindings, $addSql = '') |
|
4465 | 4465 | { |
4466 | - reset( $bindings ); |
|
4467 | - $firstKey = key( $bindings ); |
|
4468 | - $paramTypeIsNum = ( is_numeric( $firstKey ) ); |
|
4466 | + reset($bindings); |
|
4467 | + $firstKey = key($bindings); |
|
4468 | + $paramTypeIsNum = (is_numeric($firstKey)); |
|
4469 | 4469 | $counter = 0; |
4470 | 4470 | |
4471 | 4471 | $sqlConditions = array(); |
4472 | - foreach ( $conditions as $column => $values ) { |
|
4473 | - if ( !count( $values ) ) continue; |
|
4472 | + foreach ($conditions as $column => $values) { |
|
4473 | + if (!count($values)) continue; |
|
4474 | 4474 | |
4475 | - $sql = $this->esc( $column ); |
|
4475 | + $sql = $this->esc($column); |
|
4476 | 4476 | $sql .= ' IN ( '; |
4477 | 4477 | |
4478 | - if ( !is_array( $values ) ) $values = array( $values ); |
|
4478 | + if (!is_array($values)) $values = array($values); |
|
4479 | 4479 | |
4480 | 4480 | // If it's safe to skip bindings, do so... |
4481 | - if ( ctype_digit( implode( '', $values ) ) ) { |
|
4482 | - $sql .= implode( ',', $values ) . ' ) '; |
|
4481 | + if (ctype_digit(implode('', $values))) { |
|
4482 | + $sql .= implode(',', $values) . ' ) '; |
|
4483 | 4483 | |
4484 | 4484 | // only numeric, cant do much harm |
4485 | 4485 | $sqlConditions[] = $sql; |
4486 | 4486 | } else { |
4487 | 4487 | |
4488 | - if ( $paramTypeIsNum ) { |
|
4489 | - $sql .= implode( ',', array_fill( 0, count( $values ), '?' ) ) . ' ) '; |
|
4488 | + if ($paramTypeIsNum) { |
|
4489 | + $sql .= implode(',', array_fill(0, count($values), '?')) . ' ) '; |
|
4490 | 4490 | |
4491 | 4491 | array_unshift($sqlConditions, $sql); |
4492 | 4492 | |
4493 | - foreach ( $values as $k => $v ) { |
|
4494 | - $values[$k] = strval( $v ); |
|
4493 | + foreach ($values as $k => $v) { |
|
4494 | + $values[$k] = strval($v); |
|
4495 | 4495 | |
4496 | - array_unshift( $bindings, $v ); |
|
4496 | + array_unshift($bindings, $v); |
|
4497 | 4497 | } |
4498 | 4498 | } else { |
4499 | 4499 | |
4500 | 4500 | $slots = array(); |
4501 | 4501 | |
4502 | - foreach( $values as $k => $v ) { |
|
4503 | - $slot = ':slot'.$counter++; |
|
4502 | + foreach ($values as $k => $v) { |
|
4503 | + $slot = ':slot' . $counter++; |
|
4504 | 4504 | $slots[] = $slot; |
4505 | - $bindings[$slot] = strval( $v ); |
|
4505 | + $bindings[$slot] = strval($v); |
|
4506 | 4506 | } |
4507 | 4507 | |
4508 | - $sql .= implode( ',', $slots ).' ) '; |
|
4508 | + $sql .= implode(',', $slots) . ' ) '; |
|
4509 | 4509 | $sqlConditions[] = $sql; |
4510 | 4510 | } |
4511 | 4511 | } |
4512 | 4512 | } |
4513 | 4513 | |
4514 | 4514 | $sql = ''; |
4515 | - if ( is_array( $sqlConditions ) && count( $sqlConditions ) > 0 ) { |
|
4516 | - $sql = implode( ' AND ', $sqlConditions ); |
|
4515 | + if (is_array($sqlConditions) && count($sqlConditions) > 0) { |
|
4516 | + $sql = implode(' AND ', $sqlConditions); |
|
4517 | 4517 | $sql = " WHERE ( $sql ) "; |
4518 | 4518 | |
4519 | - if ( $addSql ) $sql .= $addSql; |
|
4520 | - } elseif ( $addSql ) { |
|
4519 | + if ($addSql) $sql .= $addSql; |
|
4520 | + } elseif ($addSql) { |
|
4521 | 4521 | $sql = $addSql; |
4522 | 4522 | } |
4523 | 4523 | |
@@ -4533,21 +4533,21 @@ discard block |
||
4533 | 4533 | * |
4534 | 4534 | * @return array |
4535 | 4535 | */ |
4536 | - private function getRelationalTablesAndColumns( $sourceType, $destType, $noQuote = FALSE ) |
|
4536 | + private function getRelationalTablesAndColumns($sourceType, $destType, $noQuote = FALSE) |
|
4537 | 4537 | { |
4538 | - $linkTable = $this->esc( $this->getAssocTable( array( $sourceType, $destType ) ), $noQuote ); |
|
4539 | - $sourceCol = $this->esc( $sourceType . '_id', $noQuote ); |
|
4538 | + $linkTable = $this->esc($this->getAssocTable(array($sourceType, $destType)), $noQuote); |
|
4539 | + $sourceCol = $this->esc($sourceType . '_id', $noQuote); |
|
4540 | 4540 | |
4541 | - if ( $sourceType === $destType ) { |
|
4542 | - $destCol = $this->esc( $destType . '2_id', $noQuote ); |
|
4541 | + if ($sourceType === $destType) { |
|
4542 | + $destCol = $this->esc($destType . '2_id', $noQuote); |
|
4543 | 4543 | } else { |
4544 | - $destCol = $this->esc( $destType . '_id', $noQuote ); |
|
4544 | + $destCol = $this->esc($destType . '_id', $noQuote); |
|
4545 | 4545 | } |
4546 | 4546 | |
4547 | - $sourceTable = $this->esc( $sourceType, $noQuote ); |
|
4548 | - $destTable = $this->esc( $destType, $noQuote ); |
|
4547 | + $sourceTable = $this->esc($sourceType, $noQuote); |
|
4548 | + $destTable = $this->esc($destType, $noQuote); |
|
4549 | 4549 | |
4550 | - return array( $sourceTable, $destTable, $linkTable, $sourceCol, $destCol ); |
|
4550 | + return array($sourceTable, $destTable, $linkTable, $sourceCol, $destCol); |
|
4551 | 4551 | } |
4552 | 4552 | |
4553 | 4553 | /** |
@@ -4559,18 +4559,18 @@ discard block |
||
4559 | 4559 | * |
4560 | 4560 | * @return array|NULL |
4561 | 4561 | */ |
4562 | - protected function getForeignKeyForTypeProperty( $type, $property ) |
|
4562 | + protected function getForeignKeyForTypeProperty($type, $property) |
|
4563 | 4563 | { |
4564 | - $property = $this->esc( $property, TRUE ); |
|
4564 | + $property = $this->esc($property, TRUE); |
|
4565 | 4565 | |
4566 | 4566 | try { |
4567 | - $map = $this->getKeyMapForType( $type ); |
|
4568 | - } catch ( SQLException $e ) { |
|
4567 | + $map = $this->getKeyMapForType($type); |
|
4568 | + } catch (SQLException $e) { |
|
4569 | 4569 | return NULL; |
4570 | 4570 | } |
4571 | 4571 | |
4572 | - foreach( $map as $key ) { |
|
4573 | - if ( $key['from'] === $property ) return $key; |
|
4572 | + foreach ($map as $key) { |
|
4573 | + if ($key['from'] === $property) return $key; |
|
4574 | 4574 | } |
4575 | 4575 | return NULL; |
4576 | 4576 | } |
@@ -4596,7 +4596,7 @@ discard block |
||
4596 | 4596 | * |
4597 | 4597 | * @return array |
4598 | 4598 | */ |
4599 | - protected function getKeyMapForType( $type ) |
|
4599 | + protected function getKeyMapForType($type) |
|
4600 | 4600 | { |
4601 | 4601 | return array(); |
4602 | 4602 | } |
@@ -4627,22 +4627,22 @@ discard block |
||
4627 | 4627 | * |
4628 | 4628 | * @return string |
4629 | 4629 | */ |
4630 | - protected function getSQLFilterSnippet( $type ) |
|
4630 | + protected function getSQLFilterSnippet($type) |
|
4631 | 4631 | { |
4632 | 4632 | $existingCols = array(); |
4633 | 4633 | if (self::$flagSQLFilterSafeMode) { |
4634 | - $existingCols = $this->getColumns( $type ); |
|
4634 | + $existingCols = $this->getColumns($type); |
|
4635 | 4635 | } |
4636 | 4636 | |
4637 | 4637 | $sqlFilters = array(); |
4638 | - if ( isset( self::$sqlFilters[QueryWriter::C_SQLFILTER_READ][$type] ) ) { |
|
4639 | - foreach( self::$sqlFilters[QueryWriter::C_SQLFILTER_READ][$type] as $property => $sqlFilter ) { |
|
4640 | - if ( !self::$flagSQLFilterSafeMode || isset( $existingCols[$property] ) ) { |
|
4641 | - $sqlFilters[] = $sqlFilter.' AS '.$property.' '; |
|
4638 | + if (isset(self::$sqlFilters[QueryWriter::C_SQLFILTER_READ][$type])) { |
|
4639 | + foreach (self::$sqlFilters[QueryWriter::C_SQLFILTER_READ][$type] as $property => $sqlFilter) { |
|
4640 | + if (!self::$flagSQLFilterSafeMode || isset($existingCols[$property])) { |
|
4641 | + $sqlFilters[] = $sqlFilter . ' AS ' . $property . ' '; |
|
4642 | 4642 | } |
4643 | 4643 | } |
4644 | 4644 | } |
4645 | - $sqlFilterStr = ( count($sqlFilters) ) ? ( ','.implode( ',', $sqlFilters ) ) : ''; |
|
4645 | + $sqlFilterStr = (count($sqlFilters)) ? (',' . implode(',', $sqlFilters)) : ''; |
|
4646 | 4646 | return $sqlFilterStr; |
4647 | 4647 | } |
4648 | 4648 | |
@@ -4662,20 +4662,20 @@ discard block |
||
4662 | 4662 | * |
4663 | 4663 | * @return string |
4664 | 4664 | */ |
4665 | - protected function getParametersForInClause( &$valueList, $otherBindings, $offset = 0 ) |
|
4665 | + protected function getParametersForInClause(&$valueList, $otherBindings, $offset = 0) |
|
4666 | 4666 | { |
4667 | - if ( is_array( $otherBindings ) && count( $otherBindings ) > 0 ) { |
|
4668 | - reset( $otherBindings ); |
|
4667 | + if (is_array($otherBindings) && count($otherBindings) > 0) { |
|
4668 | + reset($otherBindings); |
|
4669 | 4669 | |
4670 | - $key = key( $otherBindings ); |
|
4670 | + $key = key($otherBindings); |
|
4671 | 4671 | |
4672 | - if ( !is_numeric($key) ) { |
|
4672 | + if (!is_numeric($key)) { |
|
4673 | 4673 | $filler = array(); |
4674 | 4674 | $newList = (!$offset) ? array() : $valueList; |
4675 | 4675 | $counter = $offset; |
4676 | 4676 | |
4677 | - foreach( $valueList as $value ) { |
|
4678 | - $slot = ':slot' . ( $counter++ ); |
|
4677 | + foreach ($valueList as $value) { |
|
4678 | + $slot = ':slot' . ($counter++); |
|
4679 | 4679 | $filler[] = $slot; |
4680 | 4680 | $newList[$slot] = $value; |
4681 | 4681 | } |
@@ -4683,11 +4683,11 @@ discard block |
||
4683 | 4683 | // Change the keys! |
4684 | 4684 | $valueList = $newList; |
4685 | 4685 | |
4686 | - return implode( ',', $filler ); |
|
4686 | + return implode(',', $filler); |
|
4687 | 4687 | } |
4688 | 4688 | } |
4689 | 4689 | |
4690 | - return implode( ',', array_fill( 0, count( $valueList ), '?' ) ); |
|
4690 | + return implode(',', array_fill(0, count($valueList), '?')); |
|
4691 | 4691 | } |
4692 | 4692 | |
4693 | 4693 | /** |
@@ -4700,10 +4700,10 @@ discard block |
||
4700 | 4700 | * |
4701 | 4701 | * @return self |
4702 | 4702 | */ |
4703 | - protected function addDataType( $dataTypeID, $SQLDefinition ) |
|
4703 | + protected function addDataType($dataTypeID, $SQLDefinition) |
|
4704 | 4704 | { |
4705 | - $this->typeno_sqltype[ $dataTypeID ] = $SQLDefinition; |
|
4706 | - $this->sqltype_typeno[ $SQLDefinition ] = $dataTypeID; |
|
4705 | + $this->typeno_sqltype[$dataTypeID] = $SQLDefinition; |
|
4706 | + $this->sqltype_typeno[$SQLDefinition] = $dataTypeID; |
|
4707 | 4707 | return $this; |
4708 | 4708 | } |
4709 | 4709 | |
@@ -4714,7 +4714,7 @@ discard block |
||
4714 | 4714 | * |
4715 | 4715 | * @return string |
4716 | 4716 | */ |
4717 | - protected function getInsertSuffix( $table ) |
|
4717 | + protected function getInsertSuffix($table) |
|
4718 | 4718 | { |
4719 | 4719 | return ''; |
4720 | 4720 | } |
@@ -4728,11 +4728,11 @@ discard block |
||
4728 | 4728 | * |
4729 | 4729 | * @return boolean |
4730 | 4730 | */ |
4731 | - protected function startsWithZeros( $value ) |
|
4731 | + protected function startsWithZeros($value) |
|
4732 | 4732 | { |
4733 | - $value = strval( $value ); |
|
4733 | + $value = strval($value); |
|
4734 | 4734 | |
4735 | - if ( strlen( $value ) > 1 && strpos( $value, '0' ) === 0 && strpos( $value, '0.' ) !== 0 ) { |
|
4735 | + if (strlen($value) > 1 && strpos($value, '0') === 0 && strpos($value, '0.') !== 0) { |
|
4736 | 4736 | return TRUE; |
4737 | 4737 | } else { |
4738 | 4738 | return FALSE; |
@@ -4749,17 +4749,17 @@ discard block |
||
4749 | 4749 | * |
4750 | 4750 | * @return integer |
4751 | 4751 | */ |
4752 | - protected function insertRecord( $type, $insertcolumns, $insertvalues ) |
|
4752 | + protected function insertRecord($type, $insertcolumns, $insertvalues) |
|
4753 | 4753 | { |
4754 | 4754 | $default = $this->defaultValue; |
4755 | - $suffix = $this->getInsertSuffix( $type ); |
|
4756 | - $table = $this->esc( $type ); |
|
4755 | + $suffix = $this->getInsertSuffix($type); |
|
4756 | + $table = $this->esc($type); |
|
4757 | 4757 | |
4758 | - if ( count( $insertvalues ) > 0 && is_array( $insertvalues[0] ) && count( $insertvalues[0] ) > 0 ) { |
|
4758 | + if (count($insertvalues) > 0 && is_array($insertvalues[0]) && count($insertvalues[0]) > 0) { |
|
4759 | 4759 | |
4760 | 4760 | $insertSlots = array(); |
4761 | - foreach ( $insertcolumns as $k => $v ) { |
|
4762 | - $insertcolumns[$k] = $this->esc( $v ); |
|
4761 | + foreach ($insertcolumns as $k => $v) { |
|
4762 | + $insertcolumns[$k] = $this->esc($v); |
|
4763 | 4763 | |
4764 | 4764 | if (isset(self::$sqlFilters['w'][$type][$v])) { |
4765 | 4765 | $insertSlots[] = self::$sqlFilters['w'][$type][$v]; |
@@ -4768,20 +4768,20 @@ discard block |
||
4768 | 4768 | } |
4769 | 4769 | } |
4770 | 4770 | |
4771 | - $insertSQL = "INSERT INTO $table ( id, " . implode( ',', $insertcolumns ) . " ) VALUES |
|
4772 | - ( $default, " . implode( ',', $insertSlots ) . " ) $suffix"; |
|
4771 | + $insertSQL = "INSERT INTO $table ( id, " . implode(',', $insertcolumns) . " ) VALUES |
|
4772 | + ( $default, " . implode(',', $insertSlots) . " ) $suffix"; |
|
4773 | 4773 | |
4774 | 4774 | $ids = array(); |
4775 | - foreach ( $insertvalues as $i => $insertvalue ) { |
|
4776 | - $ids[] = $this->adapter->getCell( $insertSQL, $insertvalue, $i ); |
|
4775 | + foreach ($insertvalues as $i => $insertvalue) { |
|
4776 | + $ids[] = $this->adapter->getCell($insertSQL, $insertvalue, $i); |
|
4777 | 4777 | } |
4778 | 4778 | |
4779 | - $result = count( $ids ) === 1 ? array_pop( $ids ) : $ids; |
|
4779 | + $result = count($ids) === 1 ? array_pop($ids) : $ids; |
|
4780 | 4780 | } else { |
4781 | - $result = $this->adapter->getCell( "INSERT INTO $table (id) VALUES($default) $suffix" ); |
|
4781 | + $result = $this->adapter->getCell("INSERT INTO $table (id) VALUES($default) $suffix"); |
|
4782 | 4782 | } |
4783 | 4783 | |
4784 | - if ( $suffix ) return $result; |
|
4784 | + if ($suffix) return $result; |
|
4785 | 4785 | |
4786 | 4786 | $last_id = $this->adapter->getInsertID(); |
4787 | 4787 | |
@@ -4797,10 +4797,10 @@ discard block |
||
4797 | 4797 | * |
4798 | 4798 | * @throws Security |
4799 | 4799 | */ |
4800 | - protected function check( $struct ) |
|
4800 | + protected function check($struct) |
|
4801 | 4801 | { |
4802 | - if ( !is_string( $struct ) || !preg_match( '/^[a-zA-Z0-9_]+$/', $struct ) ) { |
|
4803 | - throw new RedException( 'Identifier does not conform to RedBeanPHP security policies.' ); |
|
4802 | + if (!is_string($struct) || !preg_match('/^[a-zA-Z0-9_]+$/', $struct)) { |
|
4803 | + throw new RedException('Identifier does not conform to RedBeanPHP security policies.'); |
|
4804 | 4804 | } |
4805 | 4805 | |
4806 | 4806 | return $struct; |
@@ -4814,40 +4814,40 @@ discard block |
||
4814 | 4814 | * |
4815 | 4815 | * @return boolean |
4816 | 4816 | */ |
4817 | - public function tableExists( $table ) |
|
4817 | + public function tableExists($table) |
|
4818 | 4818 | { |
4819 | 4819 | $tables = $this->getTables(); |
4820 | 4820 | |
4821 | - return in_array( $table, $tables ); |
|
4821 | + return in_array($table, $tables); |
|
4822 | 4822 | } |
4823 | 4823 | |
4824 | 4824 | /** |
4825 | 4825 | * @see QueryWriter::glueSQLCondition |
4826 | 4826 | */ |
4827 | - public function glueSQLCondition( $sql, $glue = NULL ) |
|
4827 | + public function glueSQLCondition($sql, $glue = NULL) |
|
4828 | 4828 | { |
4829 | 4829 | static $snippetCache = array(); |
4830 | 4830 | |
4831 | - if ( trim( $sql ) === '' ) { |
|
4831 | + if (trim($sql) === '') { |
|
4832 | 4832 | return $sql; |
4833 | 4833 | } |
4834 | 4834 | |
4835 | 4835 | $key = $glue . '|' . $sql; |
4836 | 4836 | |
4837 | - if ( isset( $snippetCache[$key] ) ) { |
|
4837 | + if (isset($snippetCache[$key])) { |
|
4838 | 4838 | return $snippetCache[$key]; |
4839 | 4839 | } |
4840 | 4840 | |
4841 | - $lsql = ltrim( $sql ); |
|
4841 | + $lsql = ltrim($sql); |
|
4842 | 4842 | |
4843 | - if ( preg_match( '/^(INNER|LEFT|RIGHT|JOIN|AND|OR|WHERE|ORDER|GROUP|HAVING|LIMIT|OFFSET)\s+/i', $lsql ) ) { |
|
4844 | - if ( $glue === QueryWriter::C_GLUE_WHERE && stripos( $lsql, 'AND' ) === 0 ) { |
|
4845 | - $snippetCache[$key] = ' WHERE ' . substr( $lsql, 3 ); |
|
4843 | + if (preg_match('/^(INNER|LEFT|RIGHT|JOIN|AND|OR|WHERE|ORDER|GROUP|HAVING|LIMIT|OFFSET)\s+/i', $lsql)) { |
|
4844 | + if ($glue === QueryWriter::C_GLUE_WHERE && stripos($lsql, 'AND') === 0) { |
|
4845 | + $snippetCache[$key] = ' WHERE ' . substr($lsql, 3); |
|
4846 | 4846 | } else { |
4847 | 4847 | $snippetCache[$key] = $sql; |
4848 | 4848 | } |
4849 | 4849 | } else { |
4850 | - $snippetCache[$key] = ( ( $glue === QueryWriter::C_GLUE_AND ) ? ' AND ' : ' WHERE ') . $sql; |
|
4850 | + $snippetCache[$key] = (($glue === QueryWriter::C_GLUE_AND) ? ' AND ' : ' WHERE ') . $sql; |
|
4851 | 4851 | } |
4852 | 4852 | |
4853 | 4853 | return $snippetCache[$key]; |
@@ -4856,80 +4856,80 @@ discard block |
||
4856 | 4856 | /** |
4857 | 4857 | * @see QueryWriter::glueLimitOne |
4858 | 4858 | */ |
4859 | - public function glueLimitOne( $sql = '') |
|
4859 | + public function glueLimitOne($sql = '') |
|
4860 | 4860 | { |
4861 | - return ( strpos( $sql, 'LIMIT' ) === FALSE ) ? ( $sql . ' LIMIT 1 ' ) : $sql; |
|
4861 | + return (strpos($sql, 'LIMIT') === FALSE) ? ($sql . ' LIMIT 1 ') : $sql; |
|
4862 | 4862 | } |
4863 | 4863 | |
4864 | 4864 | /** |
4865 | 4865 | * @see QueryWriter::esc |
4866 | 4866 | */ |
4867 | - public function esc( $dbStructure, $dontQuote = FALSE ) |
|
4867 | + public function esc($dbStructure, $dontQuote = FALSE) |
|
4868 | 4868 | { |
4869 | - $this->check( $dbStructure ); |
|
4869 | + $this->check($dbStructure); |
|
4870 | 4870 | |
4871 | - return ( $dontQuote ) ? $dbStructure : $this->quoteCharacter . $dbStructure . $this->quoteCharacter; |
|
4871 | + return ($dontQuote) ? $dbStructure : $this->quoteCharacter . $dbStructure . $this->quoteCharacter; |
|
4872 | 4872 | } |
4873 | 4873 | |
4874 | 4874 | /** |
4875 | 4875 | * @see QueryWriter::addColumn |
4876 | 4876 | */ |
4877 | - public function addColumn( $type, $column, $field ) |
|
4877 | + public function addColumn($type, $column, $field) |
|
4878 | 4878 | { |
4879 | 4879 | $table = $type; |
4880 | 4880 | $type = $field; |
4881 | - $table = $this->esc( $table ); |
|
4882 | - $column = $this->esc( $column ); |
|
4881 | + $table = $this->esc($table); |
|
4882 | + $column = $this->esc($column); |
|
4883 | 4883 | |
4884 | - $type = ( isset( $this->typeno_sqltype[$type] ) ) ? $this->typeno_sqltype[$type] : ''; |
|
4884 | + $type = (isset($this->typeno_sqltype[$type])) ? $this->typeno_sqltype[$type] : ''; |
|
4885 | 4885 | |
4886 | - $this->adapter->exec( "ALTER TABLE $table ADD $column $type " ); |
|
4886 | + $this->adapter->exec("ALTER TABLE $table ADD $column $type "); |
|
4887 | 4887 | } |
4888 | 4888 | |
4889 | 4889 | /** |
4890 | 4890 | * @see QueryWriter::updateRecord |
4891 | 4891 | */ |
4892 | - public function updateRecord( $type, $updatevalues, $id = NULL ) |
|
4892 | + public function updateRecord($type, $updatevalues, $id = NULL) |
|
4893 | 4893 | { |
4894 | 4894 | $table = $type; |
4895 | 4895 | |
4896 | - if ( !$id ) { |
|
4896 | + if (!$id) { |
|
4897 | 4897 | $insertcolumns = $insertvalues = array(); |
4898 | 4898 | |
4899 | - foreach ( $updatevalues as $pair ) { |
|
4899 | + foreach ($updatevalues as $pair) { |
|
4900 | 4900 | $insertcolumns[] = $pair['property']; |
4901 | 4901 | $insertvalues[] = $pair['value']; |
4902 | 4902 | } |
4903 | 4903 | |
4904 | 4904 | //Otherwise psql returns string while MySQL/SQLite return numeric causing problems with additions (array_diff) |
4905 | - return (string) $this->insertRecord( $table, $insertcolumns, array( $insertvalues ) ); |
|
4905 | + return (string) $this->insertRecord($table, $insertcolumns, array($insertvalues)); |
|
4906 | 4906 | } |
4907 | 4907 | |
4908 | - if ( $id && !count( $updatevalues ) ) { |
|
4908 | + if ($id && !count($updatevalues)) { |
|
4909 | 4909 | return $id; |
4910 | 4910 | } |
4911 | 4911 | |
4912 | - $table = $this->esc( $table ); |
|
4912 | + $table = $this->esc($table); |
|
4913 | 4913 | $sql = "UPDATE $table SET "; |
4914 | 4914 | |
4915 | 4915 | $p = $v = array(); |
4916 | 4916 | |
4917 | - foreach ( $updatevalues as $uv ) { |
|
4917 | + foreach ($updatevalues as $uv) { |
|
4918 | 4918 | |
4919 | - if ( isset( self::$sqlFilters['w'][$type][$uv['property']] ) ) { |
|
4920 | - $p[] = " {$this->esc( $uv["property"] )} = ". self::$sqlFilters['w'][$type][$uv['property']]; |
|
4919 | + if (isset(self::$sqlFilters['w'][$type][$uv['property']])) { |
|
4920 | + $p[] = " {$this->esc($uv["property"])} = " . self::$sqlFilters['w'][$type][$uv['property']]; |
|
4921 | 4921 | } else { |
4922 | - $p[] = " {$this->esc( $uv["property"] )} = ? "; |
|
4922 | + $p[] = " {$this->esc($uv["property"])} = ? "; |
|
4923 | 4923 | } |
4924 | 4924 | |
4925 | 4925 | $v[] = $uv['value']; |
4926 | 4926 | } |
4927 | 4927 | |
4928 | - $sql .= implode( ',', $p ) . ' WHERE id = ? '; |
|
4928 | + $sql .= implode(',', $p) . ' WHERE id = ? '; |
|
4929 | 4929 | |
4930 | 4930 | $v[] = $id; |
4931 | 4931 | |
4932 | - $this->adapter->exec( $sql, $v ); |
|
4932 | + $this->adapter->exec($sql, $v); |
|
4933 | 4933 | |
4934 | 4934 | return $id; |
4935 | 4935 | } |
@@ -4937,50 +4937,50 @@ discard block |
||
4937 | 4937 | /** |
4938 | 4938 | * @see QueryWriter::writeJoin |
4939 | 4939 | */ |
4940 | - public function writeJoin( $type, $targetType, $leftRight = 'LEFT' ) |
|
4940 | + public function writeJoin($type, $targetType, $leftRight = 'LEFT') |
|
4941 | 4941 | { |
4942 | - if ( $leftRight !== 'LEFT' && $leftRight !== 'RIGHT' && $leftRight !== 'INNER' ) |
|
4943 | - throw new RedException( 'Invalid JOIN.' ); |
|
4942 | + if ($leftRight !== 'LEFT' && $leftRight !== 'RIGHT' && $leftRight !== 'INNER') |
|
4943 | + throw new RedException('Invalid JOIN.'); |
|
4944 | 4944 | |
4945 | - $table = $this->esc( $type ); |
|
4946 | - $targetTable = $this->esc( $targetType ); |
|
4947 | - $field = $this->esc( $targetType, TRUE ); |
|
4945 | + $table = $this->esc($type); |
|
4946 | + $targetTable = $this->esc($targetType); |
|
4947 | + $field = $this->esc($targetType, TRUE); |
|
4948 | 4948 | return " {$leftRight} JOIN {$targetTable} ON {$targetTable}.id = {$table}.{$field}_id "; |
4949 | 4949 | } |
4950 | 4950 | |
4951 | 4951 | /** |
4952 | 4952 | * @see QueryWriter::queryRecord |
4953 | 4953 | */ |
4954 | - public function queryRecord( $type, $conditions = array(), $addSql = NULL, $bindings = array() ) |
|
4954 | + public function queryRecord($type, $conditions = array(), $addSql = NULL, $bindings = array()) |
|
4955 | 4955 | { |
4956 | - $addSql = $this->glueSQLCondition( $addSql, ( count($conditions) > 0) ? QueryWriter::C_GLUE_AND : NULL ); |
|
4956 | + $addSql = $this->glueSQLCondition($addSql, (count($conditions) > 0) ? QueryWriter::C_GLUE_AND : NULL); |
|
4957 | 4957 | |
4958 | 4958 | $key = NULL; |
4959 | - if ( $this->flagUseCache ) { |
|
4960 | - $key = $this->getCacheKey( array( $conditions, $addSql, $bindings, 'select' ) ); |
|
4959 | + if ($this->flagUseCache) { |
|
4960 | + $key = $this->getCacheKey(array($conditions, $addSql, $bindings, 'select')); |
|
4961 | 4961 | |
4962 | - if ( $cached = $this->getCached( $type, $key ) ) { |
|
4962 | + if ($cached = $this->getCached($type, $key)) { |
|
4963 | 4963 | return $cached; |
4964 | 4964 | } |
4965 | 4965 | } |
4966 | 4966 | |
4967 | - $table = $this->esc( $type ); |
|
4967 | + $table = $this->esc($type); |
|
4968 | 4968 | |
4969 | 4969 | $sqlFilterStr = ''; |
4970 | - if ( count( self::$sqlFilters ) ) { |
|
4971 | - $sqlFilterStr = $this->getSQLFilterSnippet( $type ); |
|
4970 | + if (count(self::$sqlFilters)) { |
|
4971 | + $sqlFilterStr = $this->getSQLFilterSnippet($type); |
|
4972 | 4972 | } |
4973 | 4973 | |
4974 | - $sql = $this->makeSQLFromConditions( $conditions, $bindings, $addSql ); |
|
4974 | + $sql = $this->makeSQLFromConditions($conditions, $bindings, $addSql); |
|
4975 | 4975 | |
4976 | - $fieldSelection = ( self::$flagNarrowFieldMode ) ? "{$table}.*" : '*'; |
|
4976 | + $fieldSelection = (self::$flagNarrowFieldMode) ? "{$table}.*" : '*'; |
|
4977 | 4977 | $sql = "SELECT {$fieldSelection} {$sqlFilterStr} FROM {$table} {$sql} -- keep-cache"; |
4978 | 4978 | |
4979 | - $rows = $this->adapter->get( $sql, $bindings ); |
|
4979 | + $rows = $this->adapter->get($sql, $bindings); |
|
4980 | 4980 | |
4981 | 4981 | |
4982 | - if ( $this->flagUseCache && $key ) { |
|
4983 | - $this->putResultInCache( $type, $key, $rows ); |
|
4982 | + if ($this->flagUseCache && $key) { |
|
4983 | + $this->putResultInCache($type, $key, $rows); |
|
4984 | 4984 | } |
4985 | 4985 | |
4986 | 4986 | return $rows; |
@@ -4989,38 +4989,38 @@ discard block |
||
4989 | 4989 | /** |
4990 | 4990 | * @see QueryWriter::queryRecordWithCursor |
4991 | 4991 | */ |
4992 | - public function queryRecordWithCursor( $type, $addSql = NULL, $bindings = array() ) |
|
4992 | + public function queryRecordWithCursor($type, $addSql = NULL, $bindings = array()) |
|
4993 | 4993 | { |
4994 | - $sql = $this->glueSQLCondition( $addSql, NULL ); |
|
4995 | - $table = $this->esc( $type ); |
|
4994 | + $sql = $this->glueSQLCondition($addSql, NULL); |
|
4995 | + $table = $this->esc($type); |
|
4996 | 4996 | $sql = "SELECT {$table}.* FROM {$table} {$sql}"; |
4997 | - return $this->adapter->getCursor( $sql, $bindings ); |
|
4997 | + return $this->adapter->getCursor($sql, $bindings); |
|
4998 | 4998 | } |
4999 | 4999 | |
5000 | 5000 | /** |
5001 | 5001 | * @see QueryWriter::queryRecordRelated |
5002 | 5002 | */ |
5003 | - public function queryRecordRelated( $sourceType, $destType, $linkIDs, $addSql = '', $bindings = array() ) |
|
5003 | + public function queryRecordRelated($sourceType, $destType, $linkIDs, $addSql = '', $bindings = array()) |
|
5004 | 5004 | { |
5005 | - $addSql = $this->glueSQLCondition( $addSql, QueryWriter::C_GLUE_WHERE ); |
|
5005 | + $addSql = $this->glueSQLCondition($addSql, QueryWriter::C_GLUE_WHERE); |
|
5006 | 5006 | |
5007 | - list( $sourceTable, $destTable, $linkTable, $sourceCol, $destCol ) = $this->getRelationalTablesAndColumns( $sourceType, $destType ); |
|
5007 | + list($sourceTable, $destTable, $linkTable, $sourceCol, $destCol) = $this->getRelationalTablesAndColumns($sourceType, $destType); |
|
5008 | 5008 | |
5009 | - $key = $this->getCacheKey( array( $sourceType, $destType, implode( ',', $linkIDs ), $addSql, $bindings ) ); |
|
5009 | + $key = $this->getCacheKey(array($sourceType, $destType, implode(',', $linkIDs), $addSql, $bindings)); |
|
5010 | 5010 | |
5011 | - if ( $this->flagUseCache && $cached = $this->getCached( $destType, $key ) ) { |
|
5011 | + if ($this->flagUseCache && $cached = $this->getCached($destType, $key)) { |
|
5012 | 5012 | return $cached; |
5013 | 5013 | } |
5014 | 5014 | |
5015 | - $inClause = $this->getParametersForInClause( $linkIDs, $bindings ); |
|
5015 | + $inClause = $this->getParametersForInClause($linkIDs, $bindings); |
|
5016 | 5016 | |
5017 | 5017 | $sqlFilterStr = ''; |
5018 | - if ( count( self::$sqlFilters ) ) { |
|
5019 | - $sqlFilterStr = $this->getSQLFilterSnippet( $destType ); |
|
5018 | + if (count(self::$sqlFilters)) { |
|
5019 | + $sqlFilterStr = $this->getSQLFilterSnippet($destType); |
|
5020 | 5020 | } |
5021 | 5021 | |
5022 | - if ( $sourceType === $destType ) { |
|
5023 | - $inClause2 = $this->getParametersForInClause( $linkIDs, $bindings, count( $bindings ) ); //for some databases |
|
5022 | + if ($sourceType === $destType) { |
|
5023 | + $inClause2 = $this->getParametersForInClause($linkIDs, $bindings, count($bindings)); //for some databases |
|
5024 | 5024 | $sql = " |
5025 | 5025 | SELECT |
5026 | 5026 | {$destTable}.* {$sqlFilterStr} , |
@@ -5034,7 +5034,7 @@ discard block |
||
5034 | 5034 | {$addSql} |
5035 | 5035 | -- keep-cache"; |
5036 | 5036 | |
5037 | - $linkIDs = array_merge( $linkIDs, $linkIDs ); |
|
5037 | + $linkIDs = array_merge($linkIDs, $linkIDs); |
|
5038 | 5038 | } else { |
5039 | 5039 | $sql = " |
5040 | 5040 | SELECT |
@@ -5047,11 +5047,11 @@ discard block |
||
5047 | 5047 | -- keep-cache"; |
5048 | 5048 | } |
5049 | 5049 | |
5050 | - $bindings = array_merge( $linkIDs, $bindings ); |
|
5050 | + $bindings = array_merge($linkIDs, $bindings); |
|
5051 | 5051 | |
5052 | - $rows = $this->adapter->get( $sql, $bindings ); |
|
5052 | + $rows = $this->adapter->get($sql, $bindings); |
|
5053 | 5053 | |
5054 | - $this->putResultInCache( $destType, $key, $rows ); |
|
5054 | + $this->putResultInCache($destType, $key, $rows); |
|
5055 | 5055 | |
5056 | 5056 | return $rows; |
5057 | 5057 | } |
@@ -5059,33 +5059,33 @@ discard block |
||
5059 | 5059 | /** |
5060 | 5060 | * @see QueryWriter::queryRecordLink |
5061 | 5061 | */ |
5062 | - public function queryRecordLink( $sourceType, $destType, $sourceID, $destID ) |
|
5062 | + public function queryRecordLink($sourceType, $destType, $sourceID, $destID) |
|
5063 | 5063 | { |
5064 | - list( $sourceTable, $destTable, $linkTable, $sourceCol, $destCol ) = $this->getRelationalTablesAndColumns( $sourceType, $destType ); |
|
5064 | + list($sourceTable, $destTable, $linkTable, $sourceCol, $destCol) = $this->getRelationalTablesAndColumns($sourceType, $destType); |
|
5065 | 5065 | |
5066 | - $key = $this->getCacheKey( array( $sourceType, $destType, $sourceID, $destID ) ); |
|
5066 | + $key = $this->getCacheKey(array($sourceType, $destType, $sourceID, $destID)); |
|
5067 | 5067 | |
5068 | - if ( $this->flagUseCache && $cached = $this->getCached( $linkTable, $key ) ) { |
|
5068 | + if ($this->flagUseCache && $cached = $this->getCached($linkTable, $key)) { |
|
5069 | 5069 | return $cached; |
5070 | 5070 | } |
5071 | 5071 | |
5072 | 5072 | $sqlFilterStr = ''; |
5073 | - if ( count( self::$sqlFilters ) ) { |
|
5074 | - $sqlFilterStr = $this->getSQLFilterSnippet( $destType ); |
|
5073 | + if (count(self::$sqlFilters)) { |
|
5074 | + $sqlFilterStr = $this->getSQLFilterSnippet($destType); |
|
5075 | 5075 | } |
5076 | 5076 | |
5077 | - if ( $sourceTable === $destTable ) { |
|
5077 | + if ($sourceTable === $destTable) { |
|
5078 | 5078 | $sql = "SELECT {$linkTable}.* {$sqlFilterStr} FROM {$linkTable} |
5079 | 5079 | WHERE ( {$sourceCol} = ? AND {$destCol} = ? ) OR |
5080 | 5080 | ( {$destCol} = ? AND {$sourceCol} = ? ) -- keep-cache"; |
5081 | - $row = $this->adapter->getRow( $sql, array( $sourceID, $destID, $sourceID, $destID ) ); |
|
5081 | + $row = $this->adapter->getRow($sql, array($sourceID, $destID, $sourceID, $destID)); |
|
5082 | 5082 | } else { |
5083 | 5083 | $sql = "SELECT {$linkTable}.* {$sqlFilterStr} FROM {$linkTable} |
5084 | 5084 | WHERE {$sourceCol} = ? AND {$destCol} = ? -- keep-cache"; |
5085 | - $row = $this->adapter->getRow( $sql, array( $sourceID, $destID ) ); |
|
5085 | + $row = $this->adapter->getRow($sql, array($sourceID, $destID)); |
|
5086 | 5086 | } |
5087 | 5087 | |
5088 | - $this->putResultInCache( $linkTable, $key, $row ); |
|
5088 | + $this->putResultInCache($linkTable, $key, $row); |
|
5089 | 5089 | |
5090 | 5090 | return $row; |
5091 | 5091 | } |
@@ -5093,14 +5093,14 @@ discard block |
||
5093 | 5093 | /** |
5094 | 5094 | * @see QueryWriter::queryTagged |
5095 | 5095 | */ |
5096 | - public function queryTagged( $type, $tagList, $all = FALSE, $addSql = '', $bindings = array() ) |
|
5096 | + public function queryTagged($type, $tagList, $all = FALSE, $addSql = '', $bindings = array()) |
|
5097 | 5097 | { |
5098 | - $assocType = $this->getAssocTable( array( $type, 'tag' ) ); |
|
5099 | - $assocTable = $this->esc( $assocType ); |
|
5098 | + $assocType = $this->getAssocTable(array($type, 'tag')); |
|
5099 | + $assocTable = $this->esc($assocType); |
|
5100 | 5100 | $assocField = $type . '_id'; |
5101 | - $table = $this->esc( $type ); |
|
5102 | - $slots = implode( ',', array_fill( 0, count( $tagList ), '?' ) ); |
|
5103 | - $score = ( $all ) ? count( $tagList ) : 1; |
|
5101 | + $table = $this->esc($type); |
|
5102 | + $slots = implode(',', array_fill(0, count($tagList), '?')); |
|
5103 | + $score = ($all) ? count($tagList) : 1; |
|
5104 | 5104 | |
5105 | 5105 | $sql = " |
5106 | 5106 | SELECT {$table}.*, count({$table}.id) FROM {$table} |
@@ -5112,38 +5112,38 @@ discard block |
||
5112 | 5112 | {$addSql} |
5113 | 5113 | "; |
5114 | 5114 | |
5115 | - $bindings = array_merge( $tagList, array( $score ), $bindings ); |
|
5116 | - $rows = $this->adapter->get( $sql, $bindings ); |
|
5115 | + $bindings = array_merge($tagList, array($score), $bindings); |
|
5116 | + $rows = $this->adapter->get($sql, $bindings); |
|
5117 | 5117 | return $rows; |
5118 | 5118 | } |
5119 | 5119 | |
5120 | 5120 | /** |
5121 | 5121 | * @see QueryWriter::queryRecordCount |
5122 | 5122 | */ |
5123 | - public function queryRecordCount( $type, $conditions = array(), $addSql = NULL, $bindings = array() ) |
|
5123 | + public function queryRecordCount($type, $conditions = array(), $addSql = NULL, $bindings = array()) |
|
5124 | 5124 | { |
5125 | - $addSql = $this->glueSQLCondition( $addSql ); |
|
5125 | + $addSql = $this->glueSQLCondition($addSql); |
|
5126 | 5126 | |
5127 | - $table = $this->esc( $type ); |
|
5127 | + $table = $this->esc($type); |
|
5128 | 5128 | |
5129 | 5129 | $this->updateCache(); //check if cache chain has been broken |
5130 | 5130 | |
5131 | - $sql = $this->makeSQLFromConditions( $conditions, $bindings, $addSql ); |
|
5131 | + $sql = $this->makeSQLFromConditions($conditions, $bindings, $addSql); |
|
5132 | 5132 | $sql = "SELECT COUNT(*) FROM {$table} {$sql} -- keep-cache"; |
5133 | 5133 | |
5134 | - return (int) $this->adapter->getCell( $sql, $bindings ); |
|
5134 | + return (int) $this->adapter->getCell($sql, $bindings); |
|
5135 | 5135 | } |
5136 | 5136 | |
5137 | 5137 | /** |
5138 | 5138 | * @see QueryWriter::queryRecordCountRelated |
5139 | 5139 | */ |
5140 | - public function queryRecordCountRelated( $sourceType, $destType, $linkID, $addSql = '', $bindings = array() ) |
|
5140 | + public function queryRecordCountRelated($sourceType, $destType, $linkID, $addSql = '', $bindings = array()) |
|
5141 | 5141 | { |
5142 | - list( $sourceTable, $destTable, $linkTable, $sourceCol, $destCol ) = $this->getRelationalTablesAndColumns( $sourceType, $destType ); |
|
5142 | + list($sourceTable, $destTable, $linkTable, $sourceCol, $destCol) = $this->getRelationalTablesAndColumns($sourceType, $destType); |
|
5143 | 5143 | |
5144 | 5144 | $this->updateCache(); //check if cache chain has been broken |
5145 | 5145 | |
5146 | - if ( $sourceType === $destType ) { |
|
5146 | + if ($sourceType === $destType) { |
|
5147 | 5147 | $sql = " |
5148 | 5148 | SELECT COUNT(*) FROM {$linkTable} |
5149 | 5149 | INNER JOIN {$destTable} ON |
@@ -5152,7 +5152,7 @@ discard block |
||
5152 | 5152 | {$addSql} |
5153 | 5153 | -- keep-cache"; |
5154 | 5154 | |
5155 | - $bindings = array_merge( array( $linkID, $linkID ), $bindings ); |
|
5155 | + $bindings = array_merge(array($linkID, $linkID), $bindings); |
|
5156 | 5156 | } else { |
5157 | 5157 | $sql = " |
5158 | 5158 | SELECT COUNT(*) FROM {$linkTable} |
@@ -5161,62 +5161,62 @@ discard block |
||
5161 | 5161 | {$addSql} |
5162 | 5162 | -- keep-cache"; |
5163 | 5163 | |
5164 | - $bindings = array_merge( array( $linkID ), $bindings ); |
|
5164 | + $bindings = array_merge(array($linkID), $bindings); |
|
5165 | 5165 | } |
5166 | 5166 | |
5167 | - return (int) $this->adapter->getCell( $sql, $bindings ); |
|
5167 | + return (int) $this->adapter->getCell($sql, $bindings); |
|
5168 | 5168 | } |
5169 | 5169 | |
5170 | 5170 | /** |
5171 | 5171 | * @see QueryWriter::deleteRecord |
5172 | 5172 | */ |
5173 | - public function deleteRecord( $type, $conditions = array(), $addSql = NULL, $bindings = array() ) |
|
5173 | + public function deleteRecord($type, $conditions = array(), $addSql = NULL, $bindings = array()) |
|
5174 | 5174 | { |
5175 | - $addSql = $this->glueSQLCondition( $addSql ); |
|
5175 | + $addSql = $this->glueSQLCondition($addSql); |
|
5176 | 5176 | |
5177 | - $table = $this->esc( $type ); |
|
5177 | + $table = $this->esc($type); |
|
5178 | 5178 | |
5179 | - $sql = $this->makeSQLFromConditions( $conditions, $bindings, $addSql ); |
|
5179 | + $sql = $this->makeSQLFromConditions($conditions, $bindings, $addSql); |
|
5180 | 5180 | $sql = "DELETE FROM {$table} {$sql}"; |
5181 | 5181 | |
5182 | - $this->adapter->exec( $sql, $bindings ); |
|
5182 | + $this->adapter->exec($sql, $bindings); |
|
5183 | 5183 | } |
5184 | 5184 | |
5185 | 5185 | /** |
5186 | 5186 | * @see QueryWriter::deleteRelations |
5187 | 5187 | */ |
5188 | - public function deleteRelations( $sourceType, $destType, $sourceID ) |
|
5188 | + public function deleteRelations($sourceType, $destType, $sourceID) |
|
5189 | 5189 | { |
5190 | - list( $sourceTable, $destTable, $linkTable, $sourceCol, $destCol ) = $this->getRelationalTablesAndColumns( $sourceType, $destType ); |
|
5190 | + list($sourceTable, $destTable, $linkTable, $sourceCol, $destCol) = $this->getRelationalTablesAndColumns($sourceType, $destType); |
|
5191 | 5191 | |
5192 | - if ( $sourceTable === $destTable ) { |
|
5192 | + if ($sourceTable === $destTable) { |
|
5193 | 5193 | $sql = "DELETE FROM {$linkTable} |
5194 | 5194 | WHERE ( {$sourceCol} = ? ) OR |
5195 | 5195 | ( {$destCol} = ? ) |
5196 | 5196 | "; |
5197 | 5197 | |
5198 | - $this->adapter->exec( $sql, array( $sourceID, $sourceID ) ); |
|
5198 | + $this->adapter->exec($sql, array($sourceID, $sourceID)); |
|
5199 | 5199 | } else { |
5200 | 5200 | $sql = "DELETE FROM {$linkTable} |
5201 | 5201 | WHERE {$sourceCol} = ? "; |
5202 | 5202 | |
5203 | - $this->adapter->exec( $sql, array( $sourceID ) ); |
|
5203 | + $this->adapter->exec($sql, array($sourceID)); |
|
5204 | 5204 | } |
5205 | 5205 | } |
5206 | 5206 | |
5207 | 5207 | /** |
5208 | 5208 | * @see QueryWriter::widenColumn |
5209 | 5209 | */ |
5210 | - public function widenColumn( $type, $property, $dataType ) |
|
5210 | + public function widenColumn($type, $property, $dataType) |
|
5211 | 5211 | { |
5212 | - if ( !isset($this->typeno_sqltype[$dataType]) ) return FALSE; |
|
5212 | + if (!isset($this->typeno_sqltype[$dataType])) return FALSE; |
|
5213 | 5213 | |
5214 | - $table = $this->esc( $type ); |
|
5215 | - $column = $this->esc( $property ); |
|
5214 | + $table = $this->esc($type); |
|
5215 | + $column = $this->esc($property); |
|
5216 | 5216 | |
5217 | 5217 | $newType = $this->typeno_sqltype[$dataType]; |
5218 | 5218 | |
5219 | - $this->adapter->exec( "ALTER TABLE $table CHANGE $column $column $newType " ); |
|
5219 | + $this->adapter->exec("ALTER TABLE $table CHANGE $column $column $newType "); |
|
5220 | 5220 | |
5221 | 5221 | return TRUE; |
5222 | 5222 | } |
@@ -5224,27 +5224,27 @@ discard block |
||
5224 | 5224 | /** |
5225 | 5225 | * @see QueryWriter::wipe |
5226 | 5226 | */ |
5227 | - public function wipe( $type ) |
|
5227 | + public function wipe($type) |
|
5228 | 5228 | { |
5229 | - $table = $this->esc( $type ); |
|
5229 | + $table = $this->esc($type); |
|
5230 | 5230 | |
5231 | - $this->adapter->exec( "TRUNCATE $table " ); |
|
5231 | + $this->adapter->exec("TRUNCATE $table "); |
|
5232 | 5232 | } |
5233 | 5233 | |
5234 | 5234 | /** |
5235 | 5235 | * @see QueryWriter::renameAssocTable |
5236 | 5236 | */ |
5237 | - public function renameAssocTable( $from, $to = NULL ) |
|
5237 | + public function renameAssocTable($from, $to = NULL) |
|
5238 | 5238 | { |
5239 | - self::renameAssociation( $from, $to ); |
|
5239 | + self::renameAssociation($from, $to); |
|
5240 | 5240 | } |
5241 | 5241 | |
5242 | 5242 | /** |
5243 | 5243 | * @see QueryWriter::getAssocTable |
5244 | 5244 | */ |
5245 | - public function getAssocTable( $types ) |
|
5245 | + public function getAssocTable($types) |
|
5246 | 5246 | { |
5247 | - return self::getAssocTableFormat( $types ); |
|
5247 | + return self::getAssocTableFormat($types); |
|
5248 | 5248 | } |
5249 | 5249 | |
5250 | 5250 | /** |
@@ -5254,7 +5254,7 @@ discard block |
||
5254 | 5254 | * |
5255 | 5255 | * @param boolean |
5256 | 5256 | */ |
5257 | - public function setUseCache( $yesNo ) |
|
5257 | + public function setUseCache($yesNo) |
|
5258 | 5258 | { |
5259 | 5259 | $this->flushCache(); |
5260 | 5260 | |
@@ -5268,12 +5268,12 @@ discard block |
||
5268 | 5268 | * |
5269 | 5269 | * @return integer |
5270 | 5270 | */ |
5271 | - public function flushCache( $newMaxCacheSizePerType = NULL ) |
|
5271 | + public function flushCache($newMaxCacheSizePerType = NULL) |
|
5272 | 5272 | { |
5273 | - if ( !is_null( $newMaxCacheSizePerType ) && $newMaxCacheSizePerType > 0 ) { |
|
5273 | + if (!is_null($newMaxCacheSizePerType) && $newMaxCacheSizePerType > 0) { |
|
5274 | 5274 | $this->maxCacheSizePerType = $newMaxCacheSizePerType; |
5275 | 5275 | } |
5276 | - $count = count( $this->cache, COUNT_RECURSIVE ); |
|
5276 | + $count = count($this->cache, COUNT_RECURSIVE); |
|
5277 | 5277 | $this->cache = array(); |
5278 | 5278 | return $count; |
5279 | 5279 | } |
@@ -5286,9 +5286,9 @@ discard block |
||
5286 | 5286 | * |
5287 | 5287 | * @return string |
5288 | 5288 | */ |
5289 | - public function safeColumn( $column, $noQuotes = FALSE ) |
|
5289 | + public function safeColumn($column, $noQuotes = FALSE) |
|
5290 | 5290 | { |
5291 | - return $this->esc( $column, $noQuotes ); |
|
5291 | + return $this->esc($column, $noQuotes); |
|
5292 | 5292 | } |
5293 | 5293 | |
5294 | 5294 | /** |
@@ -5299,21 +5299,21 @@ discard block |
||
5299 | 5299 | * |
5300 | 5300 | * @return string |
5301 | 5301 | */ |
5302 | - public function safeTable( $table, $noQuotes = FALSE ) |
|
5302 | + public function safeTable($table, $noQuotes = FALSE) |
|
5303 | 5303 | { |
5304 | - return $this->esc( $table, $noQuotes ); |
|
5304 | + return $this->esc($table, $noQuotes); |
|
5305 | 5305 | } |
5306 | 5306 | |
5307 | 5307 | /** |
5308 | 5308 | * @see QueryWriter::inferFetchType |
5309 | 5309 | */ |
5310 | - public function inferFetchType( $type, $property ) |
|
5310 | + public function inferFetchType($type, $property) |
|
5311 | 5311 | { |
5312 | - $type = $this->esc( $type, TRUE ); |
|
5313 | - $field = $this->esc( $property, TRUE ) . '_id'; |
|
5314 | - $keys = $this->getKeyMapForType( $type ); |
|
5312 | + $type = $this->esc($type, TRUE); |
|
5313 | + $field = $this->esc($property, TRUE) . '_id'; |
|
5314 | + $keys = $this->getKeyMapForType($type); |
|
5315 | 5315 | |
5316 | - foreach( $keys as $key ) { |
|
5316 | + foreach ($keys as $key) { |
|
5317 | 5317 | if ( |
5318 | 5318 | $key['from'] === $field |
5319 | 5319 | ) return $key['table']; |
@@ -5324,9 +5324,9 @@ discard block |
||
5324 | 5324 | /** |
5325 | 5325 | * @see QueryWriter::addUniqueConstraint |
5326 | 5326 | */ |
5327 | - public function addUniqueIndex( $type, $properties ) |
|
5327 | + public function addUniqueIndex($type, $properties) |
|
5328 | 5328 | { |
5329 | - return $this->addUniqueConstraint( $type, $properties ); |
|
5329 | + return $this->addUniqueConstraint($type, $properties); |
|
5330 | 5330 | } |
5331 | 5331 | } |
5332 | 5332 | } |
@@ -5371,7 +5371,7 @@ discard block |
||
5371 | 5371 | const C_DATATYPE_SPECIAL_LINESTRING = 91; |
5372 | 5372 | const C_DATATYPE_SPECIAL_POLYGON = 92; |
5373 | 5373 | |
5374 | - const C_DATATYPE_SPECIFIED = 99; |
|
5374 | + const C_DATATYPE_SPECIFIED = 99; |
|
5375 | 5375 | |
5376 | 5376 | /** |
5377 | 5377 | * @var DBAdapter |
@@ -5386,9 +5386,9 @@ discard block |
||
5386 | 5386 | /** |
5387 | 5387 | * @see AQueryWriter::getKeyMapForType |
5388 | 5388 | */ |
5389 | - protected function getKeyMapForType( $type ) |
|
5389 | + protected function getKeyMapForType($type) |
|
5390 | 5390 | { |
5391 | - $table = $this->esc( $type, TRUE ); |
|
5391 | + $table = $this->esc($type, TRUE); |
|
5392 | 5392 | $keys = $this->adapter->get(' |
5393 | 5393 | SELECT |
5394 | 5394 | information_schema.key_column_usage.constraint_name AS `name`, |
@@ -5411,8 +5411,8 @@ discard block |
||
5411 | 5411 | AND information_schema.key_column_usage.referenced_table_name IS NOT NULL |
5412 | 5412 | ', array($table)); |
5413 | 5413 | $keyInfoList = array(); |
5414 | - foreach ( $keys as $k ) { |
|
5415 | - $label = $this->makeFKLabel( $k['from'], $k['table'], $k['to'] ); |
|
5414 | + foreach ($keys as $k) { |
|
5415 | + $label = $this->makeFKLabel($k['from'], $k['table'], $k['to']); |
|
5416 | 5416 | $keyInfoList[$label] = array( |
5417 | 5417 | 'name' => $k['name'], |
5418 | 5418 | 'from' => $k['from'], |
@@ -5430,7 +5430,7 @@ discard block |
||
5430 | 5430 | * |
5431 | 5431 | * @param Adapter $adapter Database Adapter |
5432 | 5432 | */ |
5433 | - public function __construct( Adapter $adapter ) |
|
5433 | + public function __construct(Adapter $adapter) |
|
5434 | 5434 | { |
5435 | 5435 | $this->typeno_sqltype = array( |
5436 | 5436 | MySQL::C_DATATYPE_BOOL => ' TINYINT(1) UNSIGNED ', |
@@ -5449,8 +5449,8 @@ discard block |
||
5449 | 5449 | |
5450 | 5450 | $this->sqltype_typeno = array(); |
5451 | 5451 | |
5452 | - foreach ( $this->typeno_sqltype as $k => $v ) { |
|
5453 | - $this->sqltype_typeno[trim( strtolower( $v ) )] = $k; |
|
5452 | + foreach ($this->typeno_sqltype as $k => $v) { |
|
5453 | + $this->sqltype_typeno[trim(strtolower($v))] = $k; |
|
5454 | 5454 | } |
5455 | 5455 | |
5456 | 5456 | $this->adapter = $adapter; |
@@ -5474,31 +5474,31 @@ discard block |
||
5474 | 5474 | */ |
5475 | 5475 | public function getTables() |
5476 | 5476 | { |
5477 | - return $this->adapter->getCol( 'show tables' ); |
|
5477 | + return $this->adapter->getCol('show tables'); |
|
5478 | 5478 | } |
5479 | 5479 | |
5480 | 5480 | /** |
5481 | 5481 | * @see QueryWriter::createTable |
5482 | 5482 | */ |
5483 | - public function createTable( $table ) |
|
5483 | + public function createTable($table) |
|
5484 | 5484 | { |
5485 | - $table = $this->esc( $table ); |
|
5485 | + $table = $this->esc($table); |
|
5486 | 5486 | |
5487 | 5487 | $encoding = $this->adapter->getDatabase()->getMysqlEncoding(); |
5488 | 5488 | $sql = "CREATE TABLE $table (id INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY ( id )) ENGINE = InnoDB DEFAULT CHARSET={$encoding} COLLATE={$encoding}_unicode_ci "; |
5489 | 5489 | |
5490 | - $this->adapter->exec( $sql ); |
|
5490 | + $this->adapter->exec($sql); |
|
5491 | 5491 | } |
5492 | 5492 | |
5493 | 5493 | /** |
5494 | 5494 | * @see QueryWriter::getColumns |
5495 | 5495 | */ |
5496 | - public function getColumns( $table ) |
|
5496 | + public function getColumns($table) |
|
5497 | 5497 | { |
5498 | - $columnsRaw = $this->adapter->get( "DESCRIBE " . $this->esc( $table ) ); |
|
5498 | + $columnsRaw = $this->adapter->get("DESCRIBE " . $this->esc($table)); |
|
5499 | 5499 | |
5500 | 5500 | $columns = array(); |
5501 | - foreach ( $columnsRaw as $r ) { |
|
5501 | + foreach ($columnsRaw as $r) { |
|
5502 | 5502 | $columns[$r['Field']] = $r['Type']; |
5503 | 5503 | } |
5504 | 5504 | |
@@ -5508,58 +5508,58 @@ discard block |
||
5508 | 5508 | /** |
5509 | 5509 | * @see QueryWriter::scanType |
5510 | 5510 | */ |
5511 | - public function scanType( $value, $flagSpecial = FALSE ) |
|
5511 | + public function scanType($value, $flagSpecial = FALSE) |
|
5512 | 5512 | { |
5513 | 5513 | $this->svalue = $value; |
5514 | 5514 | |
5515 | - if ( is_null( $value ) ) return MySQL::C_DATATYPE_BOOL; |
|
5516 | - if ( $value === INF ) return MySQL::C_DATATYPE_TEXT7; |
|
5515 | + if (is_null($value)) return MySQL::C_DATATYPE_BOOL; |
|
5516 | + if ($value === INF) return MySQL::C_DATATYPE_TEXT7; |
|
5517 | 5517 | |
5518 | - if ( $flagSpecial ) { |
|
5519 | - if ( preg_match( '/^\d{4}\-\d\d-\d\d$/', $value ) ) { |
|
5518 | + if ($flagSpecial) { |
|
5519 | + if (preg_match('/^\d{4}\-\d\d-\d\d$/', $value)) { |
|
5520 | 5520 | return MySQL::C_DATATYPE_SPECIAL_DATE; |
5521 | 5521 | } |
5522 | - if ( preg_match( '/^\d{4}\-\d\d-\d\d\s\d\d:\d\d:\d\d$/', $value ) ) { |
|
5522 | + if (preg_match('/^\d{4}\-\d\d-\d\d\s\d\d:\d\d:\d\d$/', $value)) { |
|
5523 | 5523 | return MySQL::C_DATATYPE_SPECIAL_DATETIME; |
5524 | 5524 | } |
5525 | - if ( preg_match( '/^POINT\(/', $value ) ) { |
|
5525 | + if (preg_match('/^POINT\(/', $value)) { |
|
5526 | 5526 | return MySQL::C_DATATYPE_SPECIAL_POINT; |
5527 | 5527 | } |
5528 | - if ( preg_match( '/^LINESTRING\(/', $value ) ) { |
|
5528 | + if (preg_match('/^LINESTRING\(/', $value)) { |
|
5529 | 5529 | return MySQL::C_DATATYPE_SPECIAL_LINESTRING; |
5530 | 5530 | } |
5531 | - if ( preg_match( '/^POLYGON\(/', $value ) ) { |
|
5531 | + if (preg_match('/^POLYGON\(/', $value)) { |
|
5532 | 5532 | return MySQL::C_DATATYPE_SPECIAL_POLYGON; |
5533 | 5533 | } |
5534 | 5534 | } |
5535 | 5535 | |
5536 | 5536 | //setter turns TRUE FALSE into 0 and 1 because database has no real bools (TRUE and FALSE only for test?). |
5537 | - if ( $value === FALSE || $value === TRUE || $value === '0' || $value === '1' ) { |
|
5537 | + if ($value === FALSE || $value === TRUE || $value === '0' || $value === '1') { |
|
5538 | 5538 | return MySQL::C_DATATYPE_BOOL; |
5539 | 5539 | } |
5540 | 5540 | |
5541 | - if ( is_float( $value ) ) return self::C_DATATYPE_DOUBLE; |
|
5541 | + if (is_float($value)) return self::C_DATATYPE_DOUBLE; |
|
5542 | 5542 | |
5543 | - if ( !$this->startsWithZeros( $value ) ) { |
|
5543 | + if (!$this->startsWithZeros($value)) { |
|
5544 | 5544 | |
5545 | - if ( is_numeric( $value ) && ( floor( $value ) == $value ) && $value >= 0 && $value <= 4294967295 ) { |
|
5545 | + if (is_numeric($value) && (floor($value) == $value) && $value >= 0 && $value <= 4294967295) { |
|
5546 | 5546 | return MySQL::C_DATATYPE_UINT32; |
5547 | 5547 | } |
5548 | 5548 | |
5549 | - if ( is_numeric( $value ) ) { |
|
5549 | + if (is_numeric($value)) { |
|
5550 | 5550 | return MySQL::C_DATATYPE_DOUBLE; |
5551 | 5551 | } |
5552 | 5552 | } |
5553 | 5553 | |
5554 | - if ( mb_strlen( $value, 'UTF-8' ) <= 191 ) { |
|
5554 | + if (mb_strlen($value, 'UTF-8') <= 191) { |
|
5555 | 5555 | return MySQL::C_DATATYPE_TEXT7; |
5556 | 5556 | } |
5557 | 5557 | |
5558 | - if ( mb_strlen( $value, 'UTF-8' ) <= 255 ) { |
|
5558 | + if (mb_strlen($value, 'UTF-8') <= 255) { |
|
5559 | 5559 | return MySQL::C_DATATYPE_TEXT8; |
5560 | 5560 | } |
5561 | 5561 | |
5562 | - if ( mb_strlen( $value, 'UTF-8' ) <= 65535 ) { |
|
5562 | + if (mb_strlen($value, 'UTF-8') <= 65535) { |
|
5563 | 5563 | return MySQL::C_DATATYPE_TEXT16; |
5564 | 5564 | } |
5565 | 5565 | |
@@ -5569,19 +5569,19 @@ discard block |
||
5569 | 5569 | /** |
5570 | 5570 | * @see QueryWriter::code |
5571 | 5571 | */ |
5572 | - public function code( $typedescription, $includeSpecials = FALSE ) |
|
5572 | + public function code($typedescription, $includeSpecials = FALSE) |
|
5573 | 5573 | { |
5574 | - if ( isset( $this->sqltype_typeno[$typedescription] ) ) { |
|
5574 | + if (isset($this->sqltype_typeno[$typedescription])) { |
|
5575 | 5575 | $r = $this->sqltype_typeno[$typedescription]; |
5576 | 5576 | } else { |
5577 | 5577 | $r = self::C_DATATYPE_SPECIFIED; |
5578 | 5578 | } |
5579 | 5579 | |
5580 | - if ( $includeSpecials ) { |
|
5580 | + if ($includeSpecials) { |
|
5581 | 5581 | return $r; |
5582 | 5582 | } |
5583 | 5583 | |
5584 | - if ( $r >= QueryWriter::C_DATATYPE_RANGE_SPECIAL ) { |
|
5584 | + if ($r >= QueryWriter::C_DATATYPE_RANGE_SPECIAL) { |
|
5585 | 5585 | return self::C_DATATYPE_SPECIFIED; |
5586 | 5586 | } |
5587 | 5587 | |
@@ -5591,19 +5591,19 @@ discard block |
||
5591 | 5591 | /** |
5592 | 5592 | * @see QueryWriter::addUniqueIndex |
5593 | 5593 | */ |
5594 | - public function addUniqueConstraint( $type, $properties ) |
|
5594 | + public function addUniqueConstraint($type, $properties) |
|
5595 | 5595 | { |
5596 | - $tableNoQ = $this->esc( $type, TRUE ); |
|
5596 | + $tableNoQ = $this->esc($type, TRUE); |
|
5597 | 5597 | $columns = array(); |
5598 | - foreach( $properties as $key => $column ) $columns[$key] = $this->esc( $column ); |
|
5599 | - $table = $this->esc( $type ); |
|
5600 | - sort( $columns ); // Else we get multiple indexes due to order-effects |
|
5601 | - $name = 'UQ_' . sha1( implode( ',', $columns ) ); |
|
5598 | + foreach ($properties as $key => $column) $columns[$key] = $this->esc($column); |
|
5599 | + $table = $this->esc($type); |
|
5600 | + sort($columns); // Else we get multiple indexes due to order-effects |
|
5601 | + $name = 'UQ_' . sha1(implode(',', $columns)); |
|
5602 | 5602 | try { |
5603 | 5603 | $sql = "ALTER TABLE $table |
5604 | - ADD UNIQUE INDEX $name (" . implode( ',', $columns ) . ")"; |
|
5605 | - $this->adapter->exec( $sql ); |
|
5606 | - } catch ( SQLException $e ) { |
|
5604 | + ADD UNIQUE INDEX $name (" . implode(',', $columns) . ")"; |
|
5605 | + $this->adapter->exec($sql); |
|
5606 | + } catch (SQLException $e) { |
|
5607 | 5607 | //do nothing, dont use alter table ignore, this will delete duplicate records in 3-ways! |
5608 | 5608 | return FALSE; |
5609 | 5609 | } |
@@ -5613,15 +5613,15 @@ discard block |
||
5613 | 5613 | /** |
5614 | 5614 | * @see QueryWriter::addIndex |
5615 | 5615 | */ |
5616 | - public function addIndex( $type, $name, $property ) |
|
5616 | + public function addIndex($type, $name, $property) |
|
5617 | 5617 | { |
5618 | 5618 | try { |
5619 | - $table = $this->esc( $type ); |
|
5620 | - $name = preg_replace( '/\W/', '', $name ); |
|
5621 | - $column = $this->esc( $property ); |
|
5622 | - $this->adapter->exec( "CREATE INDEX $name ON $table ($column) " ); |
|
5619 | + $table = $this->esc($type); |
|
5620 | + $name = preg_replace('/\W/', '', $name); |
|
5621 | + $column = $this->esc($property); |
|
5622 | + $this->adapter->exec("CREATE INDEX $name ON $table ($column) "); |
|
5623 | 5623 | return TRUE; |
5624 | - } catch ( SQLException $e ) { |
|
5624 | + } catch (SQLException $e) { |
|
5625 | 5625 | return FALSE; |
5626 | 5626 | } |
5627 | 5627 | } |
@@ -5629,35 +5629,35 @@ discard block |
||
5629 | 5629 | /** |
5630 | 5630 | * @see QueryWriter::addFK |
5631 | 5631 | */ |
5632 | - public function addFK( $type, $targetType, $property, $targetProperty, $isDependent = FALSE ) |
|
5632 | + public function addFK($type, $targetType, $property, $targetProperty, $isDependent = FALSE) |
|
5633 | 5633 | { |
5634 | - $table = $this->esc( $type ); |
|
5635 | - $targetTable = $this->esc( $targetType ); |
|
5636 | - $targetTableNoQ = $this->esc( $targetType, TRUE ); |
|
5637 | - $field = $this->esc( $property ); |
|
5638 | - $fieldNoQ = $this->esc( $property, TRUE ); |
|
5639 | - $targetField = $this->esc( $targetProperty ); |
|
5640 | - $targetFieldNoQ = $this->esc( $targetProperty, TRUE ); |
|
5641 | - $tableNoQ = $this->esc( $type, TRUE ); |
|
5642 | - $fieldNoQ = $this->esc( $property, TRUE ); |
|
5643 | - if ( !is_null( $this->getForeignKeyForTypeProperty( $tableNoQ, $fieldNoQ ) ) ) return FALSE; |
|
5634 | + $table = $this->esc($type); |
|
5635 | + $targetTable = $this->esc($targetType); |
|
5636 | + $targetTableNoQ = $this->esc($targetType, TRUE); |
|
5637 | + $field = $this->esc($property); |
|
5638 | + $fieldNoQ = $this->esc($property, TRUE); |
|
5639 | + $targetField = $this->esc($targetProperty); |
|
5640 | + $targetFieldNoQ = $this->esc($targetProperty, TRUE); |
|
5641 | + $tableNoQ = $this->esc($type, TRUE); |
|
5642 | + $fieldNoQ = $this->esc($property, TRUE); |
|
5643 | + if (!is_null($this->getForeignKeyForTypeProperty($tableNoQ, $fieldNoQ))) return FALSE; |
|
5644 | 5644 | |
5645 | 5645 | //Widen the column if it's incapable of representing a foreign key (at least INT). |
5646 | - $columns = $this->getColumns( $tableNoQ ); |
|
5646 | + $columns = $this->getColumns($tableNoQ); |
|
5647 | 5647 | $idType = $this->getTypeForID(); |
5648 | - if ( $this->code( $columns[$fieldNoQ] ) !== $idType ) { |
|
5649 | - $this->widenColumn( $type, $property, $idType ); |
|
5648 | + if ($this->code($columns[$fieldNoQ]) !== $idType) { |
|
5649 | + $this->widenColumn($type, $property, $idType); |
|
5650 | 5650 | } |
5651 | 5651 | |
5652 | - $fkName = 'fk_'.($tableNoQ.'_'.$fieldNoQ); |
|
5653 | - $cName = 'c_'.$fkName; |
|
5652 | + $fkName = 'fk_' . ($tableNoQ . '_' . $fieldNoQ); |
|
5653 | + $cName = 'c_' . $fkName; |
|
5654 | 5654 | try { |
5655 | - $this->adapter->exec( " |
|
5655 | + $this->adapter->exec(" |
|
5656 | 5656 | ALTER TABLE {$table} |
5657 | 5657 | ADD CONSTRAINT $cName |
5658 | 5658 | FOREIGN KEY $fkName ( {$fieldNoQ} ) REFERENCES {$targetTableNoQ} |
5659 | - ({$targetFieldNoQ}) ON DELETE " . ( $isDependent ? 'CASCADE' : 'SET NULL' ) . ' ON UPDATE '.( $isDependent ? 'CASCADE' : 'SET NULL' ).';'); |
|
5660 | - } catch ( SQLException $e ) { |
|
5659 | + ({$targetFieldNoQ}) ON DELETE " . ($isDependent ? 'CASCADE' : 'SET NULL') . ' ON UPDATE ' . ($isDependent ? 'CASCADE' : 'SET NULL') . ';'); |
|
5660 | + } catch (SQLException $e) { |
|
5661 | 5661 | // Failure of fk-constraints is not a problem |
5662 | 5662 | } |
5663 | 5663 | } |
@@ -5665,7 +5665,7 @@ discard block |
||
5665 | 5665 | /** |
5666 | 5666 | * @see QueryWriter::sqlStateIn |
5667 | 5667 | */ |
5668 | - public function sqlStateIn( $state, $list ) |
|
5668 | + public function sqlStateIn($state, $list) |
|
5669 | 5669 | { |
5670 | 5670 | $stateMap = array( |
5671 | 5671 | '42S02' => QueryWriter::C_SQLSTATE_NO_SUCH_TABLE, |
@@ -5673,7 +5673,7 @@ discard block |
||
5673 | 5673 | '23000' => QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION |
5674 | 5674 | ); |
5675 | 5675 | |
5676 | - return in_array( ( isset( $stateMap[$state] ) ? $stateMap[$state] : '0' ), $list ); |
|
5676 | + return in_array((isset($stateMap[$state]) ? $stateMap[$state] : '0'), $list); |
|
5677 | 5677 | } |
5678 | 5678 | |
5679 | 5679 | /** |
@@ -5681,21 +5681,21 @@ discard block |
||
5681 | 5681 | */ |
5682 | 5682 | public function wipeAll() |
5683 | 5683 | { |
5684 | - $this->adapter->exec( 'SET FOREIGN_KEY_CHECKS = 0;' ); |
|
5684 | + $this->adapter->exec('SET FOREIGN_KEY_CHECKS = 0;'); |
|
5685 | 5685 | |
5686 | - foreach ( $this->getTables() as $t ) { |
|
5686 | + foreach ($this->getTables() as $t) { |
|
5687 | 5687 | try { |
5688 | - $this->adapter->exec( "DROP TABLE IF EXISTS `$t`" ); |
|
5689 | - } catch ( SQLException $e ) { |
|
5688 | + $this->adapter->exec("DROP TABLE IF EXISTS `$t`"); |
|
5689 | + } catch (SQLException $e) { |
|
5690 | 5690 | } |
5691 | 5691 | |
5692 | 5692 | try { |
5693 | - $this->adapter->exec( "DROP VIEW IF EXISTS `$t`" ); |
|
5694 | - } catch ( SQLException $e ) { |
|
5693 | + $this->adapter->exec("DROP VIEW IF EXISTS `$t`"); |
|
5694 | + } catch (SQLException $e) { |
|
5695 | 5695 | } |
5696 | 5696 | } |
5697 | 5697 | |
5698 | - $this->adapter->exec( 'SET FOREIGN_KEY_CHECKS = 1;' ); |
|
5698 | + $this->adapter->exec('SET FOREIGN_KEY_CHECKS = 1;'); |
|
5699 | 5699 | } |
5700 | 5700 | } |
5701 | 5701 | } |
@@ -5757,12 +5757,12 @@ discard block |
||
5757 | 5757 | * |
5758 | 5758 | * @return array $info |
5759 | 5759 | */ |
5760 | - protected function getTable( $type ) |
|
5760 | + protected function getTable($type) |
|
5761 | 5761 | { |
5762 | - $tableName = $this->esc( $type, TRUE ); |
|
5763 | - $columns = $this->getColumns( $type ); |
|
5764 | - $indexes = $this->getIndexes( $type ); |
|
5765 | - $keys = $this->getKeyMapForType( $type ); |
|
5762 | + $tableName = $this->esc($type, TRUE); |
|
5763 | + $columns = $this->getColumns($type); |
|
5764 | + $indexes = $this->getIndexes($type); |
|
5765 | + $keys = $this->getKeyMapForType($type); |
|
5766 | 5766 | |
5767 | 5767 | $table = array( |
5768 | 5768 | 'columns' => $columns, |
@@ -5784,30 +5784,30 @@ discard block |
||
5784 | 5784 | * |
5785 | 5785 | * @param array $tableMap information array |
5786 | 5786 | */ |
5787 | - protected function putTable( $tableMap ) |
|
5787 | + protected function putTable($tableMap) |
|
5788 | 5788 | { |
5789 | 5789 | $table = $tableMap['name']; |
5790 | 5790 | $q = array(); |
5791 | 5791 | $q[] = "DROP TABLE IF EXISTS tmp_backup;"; |
5792 | 5792 | |
5793 | - $oldColumnNames = array_keys( $this->getColumns( $table ) ); |
|
5793 | + $oldColumnNames = array_keys($this->getColumns($table)); |
|
5794 | 5794 | |
5795 | - foreach ( $oldColumnNames as $k => $v ) $oldColumnNames[$k] = "`$v`"; |
|
5795 | + foreach ($oldColumnNames as $k => $v) $oldColumnNames[$k] = "`$v`"; |
|
5796 | 5796 | |
5797 | - $q[] = "CREATE TEMPORARY TABLE tmp_backup(" . implode( ",", $oldColumnNames ) . ");"; |
|
5797 | + $q[] = "CREATE TEMPORARY TABLE tmp_backup(" . implode(",", $oldColumnNames) . ");"; |
|
5798 | 5798 | $q[] = "INSERT INTO tmp_backup SELECT * FROM `$table`;"; |
5799 | 5799 | $q[] = "PRAGMA foreign_keys = 0 "; |
5800 | 5800 | $q[] = "DROP TABLE `$table`;"; |
5801 | 5801 | |
5802 | 5802 | $newTableDefStr = ''; |
5803 | - foreach ( $tableMap['columns'] as $column => $type ) { |
|
5804 | - if ( $column != 'id' ) { |
|
5803 | + foreach ($tableMap['columns'] as $column => $type) { |
|
5804 | + if ($column != 'id') { |
|
5805 | 5805 | $newTableDefStr .= ",`$column` $type"; |
5806 | 5806 | } |
5807 | 5807 | } |
5808 | 5808 | |
5809 | 5809 | $fkDef = ''; |
5810 | - foreach ( $tableMap['keys'] as $key ) { |
|
5810 | + foreach ($tableMap['keys'] as $key) { |
|
5811 | 5811 | $fkDef .= ", FOREIGN KEY(`{$key['from']}`) |
5812 | 5812 | REFERENCES `{$key['table']}`(`{$key['to']}`) |
5813 | 5813 | ON DELETE {$key['on_delete']} ON UPDATE {$key['on_update']}"; |
@@ -5815,11 +5815,11 @@ discard block |
||
5815 | 5815 | |
5816 | 5816 | $q[] = "CREATE TABLE `$table` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT $newTableDefStr $fkDef );"; |
5817 | 5817 | |
5818 | - foreach ( $tableMap['indexes'] as $name => $index ) { |
|
5819 | - if ( strpos( $name, 'UQ_' ) === 0 ) { |
|
5820 | - $cols = explode( '__', substr( $name, strlen( 'UQ_' . $table ) ) ); |
|
5821 | - foreach ( $cols as $k => $v ) $cols[$k] = "`$v`"; |
|
5822 | - $q[] = "CREATE UNIQUE INDEX $name ON `$table` (" . implode( ',', $cols ) . ")"; |
|
5818 | + foreach ($tableMap['indexes'] as $name => $index) { |
|
5819 | + if (strpos($name, 'UQ_') === 0) { |
|
5820 | + $cols = explode('__', substr($name, strlen('UQ_' . $table))); |
|
5821 | + foreach ($cols as $k => $v) $cols[$k] = "`$v`"; |
|
5822 | + $q[] = "CREATE UNIQUE INDEX $name ON `$table` (" . implode(',', $cols) . ")"; |
|
5823 | 5823 | } else $q[] = "CREATE INDEX $name ON `$table` ({$index['name']}) "; |
5824 | 5824 | } |
5825 | 5825 | |
@@ -5827,7 +5827,7 @@ discard block |
||
5827 | 5827 | $q[] = "DROP TABLE tmp_backup;"; |
5828 | 5828 | $q[] = "PRAGMA foreign_keys = 1 "; |
5829 | 5829 | |
5830 | - foreach ( $q as $sq ) $this->adapter->exec( $sq ); |
|
5830 | + foreach ($q as $sq) $this->adapter->exec($sq); |
|
5831 | 5831 | } |
5832 | 5832 | |
5833 | 5833 | /** |
@@ -5837,14 +5837,14 @@ discard block |
||
5837 | 5837 | * |
5838 | 5838 | * @return array $indexInfo index information |
5839 | 5839 | */ |
5840 | - protected function getIndexes( $type ) |
|
5840 | + protected function getIndexes($type) |
|
5841 | 5841 | { |
5842 | - $table = $this->esc( $type, TRUE ); |
|
5843 | - $indexes = $this->adapter->get( "PRAGMA index_list('$table')" ); |
|
5842 | + $table = $this->esc($type, TRUE); |
|
5843 | + $indexes = $this->adapter->get("PRAGMA index_list('$table')"); |
|
5844 | 5844 | |
5845 | 5845 | $indexInfoList = array(); |
5846 | - foreach ( $indexes as $i ) { |
|
5847 | - $indexInfoList[$i['name']] = $this->adapter->getRow( "PRAGMA index_info('{$i['name']}') " ); |
|
5846 | + foreach ($indexes as $i) { |
|
5847 | + $indexInfoList[$i['name']] = $this->adapter->getRow("PRAGMA index_info('{$i['name']}') "); |
|
5848 | 5848 | |
5849 | 5849 | $indexInfoList[$i['name']]['unique'] = $i['unique']; |
5850 | 5850 | } |
@@ -5866,19 +5866,19 @@ discard block |
||
5866 | 5866 | * @note: cant put this in try-catch because that can hide the fact |
5867 | 5867 | * that database has been damaged. |
5868 | 5868 | */ |
5869 | - protected function buildFK( $type, $targetType, $property, $targetProperty, $constraint = FALSE ) |
|
5869 | + protected function buildFK($type, $targetType, $property, $targetProperty, $constraint = FALSE) |
|
5870 | 5870 | { |
5871 | - $table = $this->esc( $type, TRUE ); |
|
5872 | - $targetTable = $this->esc( $targetType, TRUE ); |
|
5873 | - $column = $this->esc( $property, TRUE ); |
|
5874 | - $targetColumn = $this->esc( $targetProperty, TRUE ); |
|
5871 | + $table = $this->esc($type, TRUE); |
|
5872 | + $targetTable = $this->esc($targetType, TRUE); |
|
5873 | + $column = $this->esc($property, TRUE); |
|
5874 | + $targetColumn = $this->esc($targetProperty, TRUE); |
|
5875 | 5875 | |
5876 | 5876 | $tables = $this->getTables(); |
5877 | - if ( !in_array( $targetTable, $tables ) ) return FALSE; |
|
5877 | + if (!in_array($targetTable, $tables)) return FALSE; |
|
5878 | 5878 | |
5879 | - if ( !is_null( $this->getForeignKeyForTypeProperty( $table, $column ) ) ) return FALSE; |
|
5880 | - $t = $this->getTable( $table ); |
|
5881 | - $consSQL = ( $constraint ? 'CASCADE' : 'SET NULL' ); |
|
5879 | + if (!is_null($this->getForeignKeyForTypeProperty($table, $column))) return FALSE; |
|
5880 | + $t = $this->getTable($table); |
|
5881 | + $consSQL = ($constraint ? 'CASCADE' : 'SET NULL'); |
|
5882 | 5882 | $label = 'from_' . $column . '_to_table_' . $targetTable . '_col_' . $targetColumn; |
5883 | 5883 | $t['keys'][$label] = array( |
5884 | 5884 | 'table' => $targetTable, |
@@ -5887,20 +5887,20 @@ discard block |
||
5887 | 5887 | 'on_update' => $consSQL, |
5888 | 5888 | 'on_delete' => $consSQL |
5889 | 5889 | ); |
5890 | - $this->putTable( $t ); |
|
5890 | + $this->putTable($t); |
|
5891 | 5891 | return TRUE; |
5892 | 5892 | } |
5893 | 5893 | |
5894 | 5894 | /** |
5895 | 5895 | * @see AQueryWriter::getKeyMapForType |
5896 | 5896 | */ |
5897 | - protected function getKeyMapForType( $type ) |
|
5897 | + protected function getKeyMapForType($type) |
|
5898 | 5898 | { |
5899 | - $table = $this->esc( $type, TRUE ); |
|
5900 | - $keys = $this->adapter->get( "PRAGMA foreign_key_list('$table')" ); |
|
5899 | + $table = $this->esc($type, TRUE); |
|
5900 | + $keys = $this->adapter->get("PRAGMA foreign_key_list('$table')"); |
|
5901 | 5901 | $keyInfoList = array(); |
5902 | - foreach ( $keys as $k ) { |
|
5903 | - $label = $this->makeFKLabel( $k['from'], $k['table'], $k['to'] ); |
|
5902 | + foreach ($keys as $k) { |
|
5903 | + $label = $this->makeFKLabel($k['from'], $k['table'], $k['to']); |
|
5904 | 5904 | $keyInfoList[$label] = array( |
5905 | 5905 | 'name' => $label, |
5906 | 5906 | 'from' => $k['from'], |
@@ -5918,7 +5918,7 @@ discard block |
||
5918 | 5918 | * |
5919 | 5919 | * @param Adapter $adapter Database Adapter |
5920 | 5920 | */ |
5921 | - public function __construct( Adapter $adapter ) |
|
5921 | + public function __construct(Adapter $adapter) |
|
5922 | 5922 | { |
5923 | 5923 | $this->typeno_sqltype = array( |
5924 | 5924 | SQLiteT::C_DATATYPE_INTEGER => 'INTEGER', |
@@ -5928,7 +5928,7 @@ discard block |
||
5928 | 5928 | |
5929 | 5929 | $this->sqltype_typeno = array(); |
5930 | 5930 | |
5931 | - foreach ( $this->typeno_sqltype as $k => $v ) { |
|
5931 | + foreach ($this->typeno_sqltype as $k => $v) { |
|
5932 | 5932 | $this->sqltype_typeno[$v] = $k; |
5933 | 5933 | } |
5934 | 5934 | |
@@ -5949,22 +5949,22 @@ discard block |
||
5949 | 5949 | /** |
5950 | 5950 | * @see QueryWriter::scanType |
5951 | 5951 | */ |
5952 | - public function scanType( $value, $flagSpecial = FALSE ) |
|
5952 | + public function scanType($value, $flagSpecial = FALSE) |
|
5953 | 5953 | { |
5954 | 5954 | $this->svalue = $value; |
5955 | 5955 | |
5956 | - if ( $value === NULL ) return self::C_DATATYPE_INTEGER; |
|
5957 | - if ( $value === INF ) return self::C_DATATYPE_TEXT; |
|
5956 | + if ($value === NULL) return self::C_DATATYPE_INTEGER; |
|
5957 | + if ($value === INF) return self::C_DATATYPE_TEXT; |
|
5958 | 5958 | |
5959 | - if ( $this->startsWithZeros( $value ) ) return self::C_DATATYPE_TEXT; |
|
5959 | + if ($this->startsWithZeros($value)) return self::C_DATATYPE_TEXT; |
|
5960 | 5960 | |
5961 | - if ( $value === TRUE || $value === FALSE ) return self::C_DATATYPE_INTEGER; |
|
5961 | + if ($value === TRUE || $value === FALSE) return self::C_DATATYPE_INTEGER; |
|
5962 | 5962 | |
5963 | - if ( is_numeric( $value ) && ( intval( $value ) == $value ) && $value < 2147483648 && $value > -2147483648 ) return self::C_DATATYPE_INTEGER; |
|
5963 | + if (is_numeric($value) && (intval($value) == $value) && $value < 2147483648 && $value > -2147483648) return self::C_DATATYPE_INTEGER; |
|
5964 | 5964 | |
5965 | - if ( ( is_numeric( $value ) && $value < 2147483648 && $value > -2147483648) |
|
5966 | - || preg_match( '/\d{4}\-\d\d\-\d\d/', $value ) |
|
5967 | - || preg_match( '/\d{4}\-\d\d\-\d\d\s\d\d:\d\d:\d\d/', $value ) |
|
5965 | + if ((is_numeric($value) && $value < 2147483648 && $value > -2147483648) |
|
5966 | + || preg_match('/\d{4}\-\d\d\-\d\d/', $value) |
|
5967 | + || preg_match('/\d{4}\-\d\d\-\d\d\s\d\d:\d\d:\d\d/', $value) |
|
5968 | 5968 | ) { |
5969 | 5969 | return self::C_DATATYPE_NUMERIC; |
5970 | 5970 | } |
@@ -5975,21 +5975,21 @@ discard block |
||
5975 | 5975 | /** |
5976 | 5976 | * @see QueryWriter::addColumn |
5977 | 5977 | */ |
5978 | - public function addColumn( $table, $column, $type ) |
|
5978 | + public function addColumn($table, $column, $type) |
|
5979 | 5979 | { |
5980 | - $column = $this->check( $column ); |
|
5981 | - $table = $this->check( $table ); |
|
5980 | + $column = $this->check($column); |
|
5981 | + $table = $this->check($table); |
|
5982 | 5982 | $type = $this->typeno_sqltype[$type]; |
5983 | 5983 | |
5984 | - $this->adapter->exec( "ALTER TABLE `$table` ADD `$column` $type " ); |
|
5984 | + $this->adapter->exec("ALTER TABLE `$table` ADD `$column` $type "); |
|
5985 | 5985 | } |
5986 | 5986 | |
5987 | 5987 | /** |
5988 | 5988 | * @see QueryWriter::code |
5989 | 5989 | */ |
5990 | - public function code( $typedescription, $includeSpecials = FALSE ) |
|
5990 | + public function code($typedescription, $includeSpecials = FALSE) |
|
5991 | 5991 | { |
5992 | - $r = ( ( isset( $this->sqltype_typeno[$typedescription] ) ) ? $this->sqltype_typeno[$typedescription] : 99 ); |
|
5992 | + $r = ((isset($this->sqltype_typeno[$typedescription])) ? $this->sqltype_typeno[$typedescription] : 99); |
|
5993 | 5993 | |
5994 | 5994 | return $r; |
5995 | 5995 | } |
@@ -5997,13 +5997,13 @@ discard block |
||
5997 | 5997 | /** |
5998 | 5998 | * @see QueryWriter::widenColumn |
5999 | 5999 | */ |
6000 | - public function widenColumn( $type, $column, $datatype ) |
|
6000 | + public function widenColumn($type, $column, $datatype) |
|
6001 | 6001 | { |
6002 | - $t = $this->getTable( $type ); |
|
6002 | + $t = $this->getTable($type); |
|
6003 | 6003 | |
6004 | 6004 | $t['columns'][$column] = $this->typeno_sqltype[$datatype]; |
6005 | 6005 | |
6006 | - $this->putTable( $t ); |
|
6006 | + $this->putTable($t); |
|
6007 | 6007 | } |
6008 | 6008 | |
6009 | 6009 | /** |
@@ -6011,33 +6011,33 @@ discard block |
||
6011 | 6011 | */ |
6012 | 6012 | public function getTables() |
6013 | 6013 | { |
6014 | - return $this->adapter->getCol( "SELECT name FROM sqlite_master |
|
6014 | + return $this->adapter->getCol("SELECT name FROM sqlite_master |
|
6015 | 6015 | WHERE type='table' AND name!='sqlite_sequence';" ); |
6016 | 6016 | } |
6017 | 6017 | |
6018 | 6018 | /** |
6019 | 6019 | * @see QueryWriter::createTable |
6020 | 6020 | */ |
6021 | - public function createTable( $table ) |
|
6021 | + public function createTable($table) |
|
6022 | 6022 | { |
6023 | - $table = $this->esc( $table ); |
|
6023 | + $table = $this->esc($table); |
|
6024 | 6024 | |
6025 | 6025 | $sql = "CREATE TABLE $table ( id INTEGER PRIMARY KEY AUTOINCREMENT ) "; |
6026 | 6026 | |
6027 | - $this->adapter->exec( $sql ); |
|
6027 | + $this->adapter->exec($sql); |
|
6028 | 6028 | } |
6029 | 6029 | |
6030 | 6030 | /** |
6031 | 6031 | * @see QueryWriter::getColumns |
6032 | 6032 | */ |
6033 | - public function getColumns( $table ) |
|
6033 | + public function getColumns($table) |
|
6034 | 6034 | { |
6035 | - $table = $this->esc( $table, TRUE ); |
|
6035 | + $table = $this->esc($table, TRUE); |
|
6036 | 6036 | |
6037 | - $columnsRaw = $this->adapter->get( "PRAGMA table_info('$table')" ); |
|
6037 | + $columnsRaw = $this->adapter->get("PRAGMA table_info('$table')"); |
|
6038 | 6038 | |
6039 | 6039 | $columns = array(); |
6040 | - foreach ( $columnsRaw as $r ) $columns[$r['name']] = $r['type']; |
|
6040 | + foreach ($columnsRaw as $r) $columns[$r['name']] = $r['type']; |
|
6041 | 6041 | |
6042 | 6042 | return $columns; |
6043 | 6043 | } |
@@ -6045,15 +6045,15 @@ discard block |
||
6045 | 6045 | /** |
6046 | 6046 | * @see QueryWriter::addUniqueIndex |
6047 | 6047 | */ |
6048 | - public function addUniqueConstraint( $type, $properties ) |
|
6048 | + public function addUniqueConstraint($type, $properties) |
|
6049 | 6049 | { |
6050 | - $tableNoQ = $this->esc( $type, TRUE ); |
|
6051 | - $name = 'UQ_' . $this->esc( $type, TRUE ) . implode( '__', $properties ); |
|
6052 | - $t = $this->getTable( $type ); |
|
6053 | - $t['indexes'][$name] = array( 'name' => $name ); |
|
6050 | + $tableNoQ = $this->esc($type, TRUE); |
|
6051 | + $name = 'UQ_' . $this->esc($type, TRUE) . implode('__', $properties); |
|
6052 | + $t = $this->getTable($type); |
|
6053 | + $t['indexes'][$name] = array('name' => $name); |
|
6054 | 6054 | try { |
6055 | - $this->putTable( $t ); |
|
6056 | - } catch( SQLException $e ) { |
|
6055 | + $this->putTable($t); |
|
6056 | + } catch (SQLException $e) { |
|
6057 | 6057 | return FALSE; |
6058 | 6058 | } |
6059 | 6059 | return TRUE; |
@@ -6062,34 +6062,34 @@ discard block |
||
6062 | 6062 | /** |
6063 | 6063 | * @see QueryWriter::sqlStateIn |
6064 | 6064 | */ |
6065 | - public function sqlStateIn( $state, $list ) |
|
6065 | + public function sqlStateIn($state, $list) |
|
6066 | 6066 | { |
6067 | 6067 | $stateMap = array( |
6068 | 6068 | 'HY000' => QueryWriter::C_SQLSTATE_NO_SUCH_TABLE, |
6069 | 6069 | '23000' => QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION |
6070 | 6070 | ); |
6071 | 6071 | |
6072 | - return in_array( ( isset( $stateMap[$state] ) ? $stateMap[$state] : '0' ), $list ); |
|
6072 | + return in_array((isset($stateMap[$state]) ? $stateMap[$state] : '0'), $list); |
|
6073 | 6073 | } |
6074 | 6074 | |
6075 | 6075 | /** |
6076 | 6076 | * @see QueryWriter::addIndex |
6077 | 6077 | */ |
6078 | - public function addIndex( $type, $name, $column ) |
|
6078 | + public function addIndex($type, $name, $column) |
|
6079 | 6079 | { |
6080 | - $columns = $this->getColumns( $type ); |
|
6081 | - if ( !isset( $columns[$column] ) ) return FALSE; |
|
6080 | + $columns = $this->getColumns($type); |
|
6081 | + if (!isset($columns[$column])) return FALSE; |
|
6082 | 6082 | |
6083 | - $table = $this->esc( $type ); |
|
6084 | - $name = preg_replace( '/\W/', '', $name ); |
|
6085 | - $column = $this->esc( $column, TRUE ); |
|
6083 | + $table = $this->esc($type); |
|
6084 | + $name = preg_replace('/\W/', '', $name); |
|
6085 | + $column = $this->esc($column, TRUE); |
|
6086 | 6086 | |
6087 | 6087 | try { |
6088 | - $t = $this->getTable( $type ); |
|
6089 | - $t['indexes'][$name] = array( 'name' => $column ); |
|
6090 | - $this->putTable( $t ); |
|
6088 | + $t = $this->getTable($type); |
|
6089 | + $t['indexes'][$name] = array('name' => $column); |
|
6090 | + $this->putTable($t); |
|
6091 | 6091 | return TRUE; |
6092 | - } catch( SQLException $exception ) { |
|
6092 | + } catch (SQLException $exception) { |
|
6093 | 6093 | return FALSE; |
6094 | 6094 | } |
6095 | 6095 | } |
@@ -6097,19 +6097,19 @@ discard block |
||
6097 | 6097 | /** |
6098 | 6098 | * @see QueryWriter::wipe |
6099 | 6099 | */ |
6100 | - public function wipe( $type ) |
|
6100 | + public function wipe($type) |
|
6101 | 6101 | { |
6102 | - $table = $this->esc( $type ); |
|
6102 | + $table = $this->esc($type); |
|
6103 | 6103 | |
6104 | - $this->adapter->exec( "DELETE FROM $table " ); |
|
6104 | + $this->adapter->exec("DELETE FROM $table "); |
|
6105 | 6105 | } |
6106 | 6106 | |
6107 | 6107 | /** |
6108 | 6108 | * @see QueryWriter::addFK |
6109 | 6109 | */ |
6110 | - public function addFK( $type, $targetType, $property, $targetProperty, $isDep = FALSE ) |
|
6110 | + public function addFK($type, $targetType, $property, $targetProperty, $isDep = FALSE) |
|
6111 | 6111 | { |
6112 | - return $this->buildFK( $type, $targetType, $property, $targetProperty, $isDep ); |
|
6112 | + return $this->buildFK($type, $targetType, $property, $targetProperty, $isDep); |
|
6113 | 6113 | } |
6114 | 6114 | |
6115 | 6115 | /** |
@@ -6117,21 +6117,21 @@ discard block |
||
6117 | 6117 | */ |
6118 | 6118 | public function wipeAll() |
6119 | 6119 | { |
6120 | - $this->adapter->exec( 'PRAGMA foreign_keys = 0 ' ); |
|
6120 | + $this->adapter->exec('PRAGMA foreign_keys = 0 '); |
|
6121 | 6121 | |
6122 | - foreach ( $this->getTables() as $t ) { |
|
6122 | + foreach ($this->getTables() as $t) { |
|
6123 | 6123 | try { |
6124 | - $this->adapter->exec( "DROP TABLE IF EXISTS `$t`" ); |
|
6125 | - } catch ( SQLException $e ) { |
|
6124 | + $this->adapter->exec("DROP TABLE IF EXISTS `$t`"); |
|
6125 | + } catch (SQLException $e) { |
|
6126 | 6126 | } |
6127 | 6127 | |
6128 | 6128 | try { |
6129 | - $this->adapter->exec( "DROP TABLE IF EXISTS `$t`" ); |
|
6130 | - } catch ( SQLException $e ) { |
|
6129 | + $this->adapter->exec("DROP TABLE IF EXISTS `$t`"); |
|
6130 | + } catch (SQLException $e) { |
|
6131 | 6131 | } |
6132 | 6132 | } |
6133 | 6133 | |
6134 | - $this->adapter->exec( 'PRAGMA foreign_keys = 1 ' ); |
|
6134 | + $this->adapter->exec('PRAGMA foreign_keys = 1 '); |
|
6135 | 6135 | } |
6136 | 6136 | } |
6137 | 6137 | } |
@@ -6197,7 +6197,7 @@ discard block |
||
6197 | 6197 | * |
6198 | 6198 | * @return string $sql SQL Snippet |
6199 | 6199 | */ |
6200 | - protected function getInsertSuffix( $table ) |
|
6200 | + protected function getInsertSuffix($table) |
|
6201 | 6201 | { |
6202 | 6202 | return 'RETURNING id '; |
6203 | 6203 | } |
@@ -6205,10 +6205,10 @@ discard block |
||
6205 | 6205 | /** |
6206 | 6206 | * @see AQueryWriter::getKeyMapForType |
6207 | 6207 | */ |
6208 | - protected function getKeyMapForType( $type ) |
|
6208 | + protected function getKeyMapForType($type) |
|
6209 | 6209 | { |
6210 | - $table = $this->esc( $type, TRUE ); |
|
6211 | - $keys = $this->adapter->get( ' |
|
6210 | + $table = $this->esc($type, TRUE); |
|
6211 | + $keys = $this->adapter->get(' |
|
6212 | 6212 | SELECT |
6213 | 6213 | information_schema.key_column_usage.constraint_name AS "name", |
6214 | 6214 | information_schema.key_column_usage.column_name AS "from", |
@@ -6239,10 +6239,10 @@ discard block |
||
6239 | 6239 | information_schema.key_column_usage.table_catalog = current_database() |
6240 | 6240 | AND information_schema.key_column_usage.table_schema = ANY( current_schemas( FALSE ) ) |
6241 | 6241 | AND information_schema.key_column_usage.table_name = ? |
6242 | - ', array( $type ) ); |
|
6242 | + ', array($type)); |
|
6243 | 6243 | $keyInfoList = array(); |
6244 | - foreach ( $keys as $k ) { |
|
6245 | - $label = $this->makeFKLabel( $k['from'], $k['table'], $k['to'] ); |
|
6244 | + foreach ($keys as $k) { |
|
6245 | + $label = $this->makeFKLabel($k['from'], $k['table'], $k['to']); |
|
6246 | 6246 | $keyInfoList[$label] = array( |
6247 | 6247 | 'name' => $k['name'], |
6248 | 6248 | 'from' => $k['from'], |
@@ -6260,7 +6260,7 @@ discard block |
||
6260 | 6260 | * |
6261 | 6261 | * @param Adapter $adapter Database Adapter |
6262 | 6262 | */ |
6263 | - public function __construct( Adapter $adapter ) |
|
6263 | + public function __construct(Adapter $adapter) |
|
6264 | 6264 | { |
6265 | 6265 | $this->typeno_sqltype = array( |
6266 | 6266 | self::C_DATATYPE_INTEGER => ' integer ', |
@@ -6277,8 +6277,8 @@ discard block |
||
6277 | 6277 | |
6278 | 6278 | $this->sqltype_typeno = array(); |
6279 | 6279 | |
6280 | - foreach ( $this->typeno_sqltype as $k => $v ) { |
|
6281 | - $this->sqltype_typeno[trim( strtolower( $v ) )] = $k; |
|
6280 | + foreach ($this->typeno_sqltype as $k => $v) { |
|
6281 | + $this->sqltype_typeno[trim(strtolower($v))] = $k; |
|
6282 | 6282 | } |
6283 | 6283 | |
6284 | 6284 | $this->adapter = $adapter; |
@@ -6300,30 +6300,30 @@ discard block |
||
6300 | 6300 | */ |
6301 | 6301 | public function getTables() |
6302 | 6302 | { |
6303 | - return $this->adapter->getCol( 'SELECT table_name FROM information_schema.tables WHERE table_schema = ANY( current_schemas( FALSE ) )' ); |
|
6303 | + return $this->adapter->getCol('SELECT table_name FROM information_schema.tables WHERE table_schema = ANY( current_schemas( FALSE ) )'); |
|
6304 | 6304 | } |
6305 | 6305 | |
6306 | 6306 | /** |
6307 | 6307 | * @see QueryWriter::createTable |
6308 | 6308 | */ |
6309 | - public function createTable( $table ) |
|
6309 | + public function createTable($table) |
|
6310 | 6310 | { |
6311 | - $table = $this->esc( $table ); |
|
6311 | + $table = $this->esc($table); |
|
6312 | 6312 | |
6313 | - $this->adapter->exec( " CREATE TABLE $table (id SERIAL PRIMARY KEY); " ); |
|
6313 | + $this->adapter->exec(" CREATE TABLE $table (id SERIAL PRIMARY KEY); "); |
|
6314 | 6314 | } |
6315 | 6315 | |
6316 | 6316 | /** |
6317 | 6317 | * @see QueryWriter::getColumns |
6318 | 6318 | */ |
6319 | - public function getColumns( $table ) |
|
6319 | + public function getColumns($table) |
|
6320 | 6320 | { |
6321 | - $table = $this->esc( $table, TRUE ); |
|
6321 | + $table = $this->esc($table, TRUE); |
|
6322 | 6322 | |
6323 | - $columnsRaw = $this->adapter->get( "SELECT column_name, data_type FROM information_schema.columns WHERE table_name='$table'" ); |
|
6323 | + $columnsRaw = $this->adapter->get("SELECT column_name, data_type FROM information_schema.columns WHERE table_name='$table'"); |
|
6324 | 6324 | |
6325 | 6325 | $columns = array(); |
6326 | - foreach ( $columnsRaw as $r ) { |
|
6326 | + foreach ($columnsRaw as $r) { |
|
6327 | 6327 | $columns[$r['column_name']] = $r['data_type']; |
6328 | 6328 | } |
6329 | 6329 | |
@@ -6333,53 +6333,53 @@ discard block |
||
6333 | 6333 | /** |
6334 | 6334 | * @see QueryWriter::scanType |
6335 | 6335 | */ |
6336 | - public function scanType( $value, $flagSpecial = FALSE ) |
|
6336 | + public function scanType($value, $flagSpecial = FALSE) |
|
6337 | 6337 | { |
6338 | 6338 | $this->svalue = $value; |
6339 | 6339 | |
6340 | - if ( $value === INF ) return self::C_DATATYPE_TEXT; |
|
6340 | + if ($value === INF) return self::C_DATATYPE_TEXT; |
|
6341 | 6341 | |
6342 | - if ( $flagSpecial && $value ) { |
|
6343 | - if ( preg_match( '/^\d{4}\-\d\d-\d\d$/', $value ) ) { |
|
6342 | + if ($flagSpecial && $value) { |
|
6343 | + if (preg_match('/^\d{4}\-\d\d-\d\d$/', $value)) { |
|
6344 | 6344 | return PostgreSQL::C_DATATYPE_SPECIAL_DATE; |
6345 | 6345 | } |
6346 | 6346 | |
6347 | - if ( preg_match( '/^\d{4}\-\d\d-\d\d\s\d\d:\d\d:\d\d(\.\d{1,6})?$/', $value ) ) { |
|
6347 | + if (preg_match('/^\d{4}\-\d\d-\d\d\s\d\d:\d\d:\d\d(\.\d{1,6})?$/', $value)) { |
|
6348 | 6348 | return PostgreSQL::C_DATATYPE_SPECIAL_DATETIME; |
6349 | 6349 | } |
6350 | 6350 | |
6351 | - if ( preg_match( '/^\([\d\.]+,[\d\.]+\)$/', $value ) ) { |
|
6351 | + if (preg_match('/^\([\d\.]+,[\d\.]+\)$/', $value)) { |
|
6352 | 6352 | return PostgreSQL::C_DATATYPE_SPECIAL_POINT; |
6353 | 6353 | } |
6354 | 6354 | |
6355 | - if ( preg_match( '/^\[\([\d\.]+,[\d\.]+\),\([\d\.]+,[\d\.]+\)\]$/', $value ) ) { |
|
6355 | + if (preg_match('/^\[\([\d\.]+,[\d\.]+\),\([\d\.]+,[\d\.]+\)\]$/', $value)) { |
|
6356 | 6356 | return PostgreSQL::C_DATATYPE_SPECIAL_LSEG; |
6357 | 6357 | } |
6358 | 6358 | |
6359 | - if ( preg_match( '/^\<\([\d\.]+,[\d\.]+\),[\d\.]+\>$/', $value ) ) { |
|
6359 | + if (preg_match('/^\<\([\d\.]+,[\d\.]+\),[\d\.]+\>$/', $value)) { |
|
6360 | 6360 | return PostgreSQL::C_DATATYPE_SPECIAL_CIRCLE; |
6361 | 6361 | } |
6362 | 6362 | |
6363 | - if ( preg_match( '/^\((\([\d\.]+,[\d\.]+\),?)+\)$/', $value ) ) { |
|
6363 | + if (preg_match('/^\((\([\d\.]+,[\d\.]+\),?)+\)$/', $value)) { |
|
6364 | 6364 | return PostgreSQL::C_DATATYPE_SPECIAL_POLYGON; |
6365 | 6365 | } |
6366 | 6366 | |
6367 | - if ( preg_match( '/^\-?(\$|€|¥|£)[\d,\.]+$/', $value ) ) { |
|
6367 | + if (preg_match('/^\-?(\$|€|¥|£)[\d,\.]+$/', $value)) { |
|
6368 | 6368 | return PostgreSQL::C_DATATYPE_SPECIAL_MONEY; |
6369 | 6369 | } |
6370 | 6370 | } |
6371 | 6371 | |
6372 | - if ( is_float( $value ) ) return self::C_DATATYPE_DOUBLE; |
|
6372 | + if (is_float($value)) return self::C_DATATYPE_DOUBLE; |
|
6373 | 6373 | |
6374 | - if ( $this->startsWithZeros( $value ) ) return self::C_DATATYPE_TEXT; |
|
6374 | + if ($this->startsWithZeros($value)) return self::C_DATATYPE_TEXT; |
|
6375 | 6375 | |
6376 | - if ( $value === FALSE || $value === TRUE || $value === NULL || ( is_numeric( $value ) |
|
6377 | - && AQueryWriter::canBeTreatedAsInt( $value ) |
|
6376 | + if ($value === FALSE || $value === TRUE || $value === NULL || (is_numeric($value) |
|
6377 | + && AQueryWriter::canBeTreatedAsInt($value) |
|
6378 | 6378 | && $value < 2147483648 |
6379 | - && $value > -2147483648 ) |
|
6379 | + && $value > -2147483648) |
|
6380 | 6380 | ) { |
6381 | 6381 | return self::C_DATATYPE_INTEGER; |
6382 | - } elseif ( is_numeric( $value ) ) { |
|
6382 | + } elseif (is_numeric($value)) { |
|
6383 | 6383 | return self::C_DATATYPE_DOUBLE; |
6384 | 6384 | } else { |
6385 | 6385 | return self::C_DATATYPE_TEXT; |
@@ -6389,13 +6389,13 @@ discard block |
||
6389 | 6389 | /** |
6390 | 6390 | * @see QueryWriter::code |
6391 | 6391 | */ |
6392 | - public function code( $typedescription, $includeSpecials = FALSE ) |
|
6392 | + public function code($typedescription, $includeSpecials = FALSE) |
|
6393 | 6393 | { |
6394 | - $r = ( isset( $this->sqltype_typeno[$typedescription] ) ) ? $this->sqltype_typeno[$typedescription] : 99; |
|
6394 | + $r = (isset($this->sqltype_typeno[$typedescription])) ? $this->sqltype_typeno[$typedescription] : 99; |
|
6395 | 6395 | |
6396 | - if ( $includeSpecials ) return $r; |
|
6396 | + if ($includeSpecials) return $r; |
|
6397 | 6397 | |
6398 | - if ( $r >= QueryWriter::C_DATATYPE_RANGE_SPECIAL ) { |
|
6398 | + if ($r >= QueryWriter::C_DATATYPE_RANGE_SPECIAL) { |
|
6399 | 6399 | return self::C_DATATYPE_SPECIFIED; |
6400 | 6400 | } |
6401 | 6401 | |
@@ -6405,35 +6405,35 @@ discard block |
||
6405 | 6405 | /** |
6406 | 6406 | * @see QueryWriter::widenColumn |
6407 | 6407 | */ |
6408 | - public function widenColumn( $type, $column, $datatype ) |
|
6408 | + public function widenColumn($type, $column, $datatype) |
|
6409 | 6409 | { |
6410 | 6410 | $table = $type; |
6411 | 6411 | $type = $datatype; |
6412 | 6412 | |
6413 | - $table = $this->esc( $table ); |
|
6414 | - $column = $this->esc( $column ); |
|
6413 | + $table = $this->esc($table); |
|
6414 | + $column = $this->esc($column); |
|
6415 | 6415 | |
6416 | 6416 | $newtype = $this->typeno_sqltype[$type]; |
6417 | 6417 | |
6418 | - $this->adapter->exec( "ALTER TABLE $table \n\t ALTER COLUMN $column TYPE $newtype " ); |
|
6418 | + $this->adapter->exec("ALTER TABLE $table \n\t ALTER COLUMN $column TYPE $newtype "); |
|
6419 | 6419 | } |
6420 | 6420 | |
6421 | 6421 | /** |
6422 | 6422 | * @see QueryWriter::addUniqueIndex |
6423 | 6423 | */ |
6424 | - public function addUniqueConstraint( $type, $properties ) |
|
6424 | + public function addUniqueConstraint($type, $properties) |
|
6425 | 6425 | { |
6426 | - $tableNoQ = $this->esc( $type, TRUE ); |
|
6426 | + $tableNoQ = $this->esc($type, TRUE); |
|
6427 | 6427 | $columns = array(); |
6428 | - foreach( $properties as $key => $column ) $columns[$key] = $this->esc( $column ); |
|
6429 | - $table = $this->esc( $type ); |
|
6430 | - sort( $columns ); //else we get multiple indexes due to order-effects |
|
6431 | - $name = "UQ_" . sha1( $table . implode( ',', $columns ) ); |
|
6428 | + foreach ($properties as $key => $column) $columns[$key] = $this->esc($column); |
|
6429 | + $table = $this->esc($type); |
|
6430 | + sort($columns); //else we get multiple indexes due to order-effects |
|
6431 | + $name = "UQ_" . sha1($table . implode(',', $columns)); |
|
6432 | 6432 | $sql = "ALTER TABLE {$table} |
6433 | - ADD CONSTRAINT $name UNIQUE (" . implode( ',', $columns ) . ")"; |
|
6433 | + ADD CONSTRAINT $name UNIQUE (" . implode(',', $columns) . ")"; |
|
6434 | 6434 | try { |
6435 | - $this->adapter->exec( $sql ); |
|
6436 | - } catch( SQLException $e ) { |
|
6435 | + $this->adapter->exec($sql); |
|
6436 | + } catch (SQLException $e) { |
|
6437 | 6437 | return FALSE; |
6438 | 6438 | } |
6439 | 6439 | return TRUE; |
@@ -6442,7 +6442,7 @@ discard block |
||
6442 | 6442 | /** |
6443 | 6443 | * @see QueryWriter::sqlStateIn |
6444 | 6444 | */ |
6445 | - public function sqlStateIn( $state, $list ) |
|
6445 | + public function sqlStateIn($state, $list) |
|
6446 | 6446 | { |
6447 | 6447 | $stateMap = array( |
6448 | 6448 | '42P01' => QueryWriter::C_SQLSTATE_NO_SUCH_TABLE, |
@@ -6450,22 +6450,22 @@ discard block |
||
6450 | 6450 | '23505' => QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION |
6451 | 6451 | ); |
6452 | 6452 | |
6453 | - return in_array( ( isset( $stateMap[$state] ) ? $stateMap[$state] : '0' ), $list ); |
|
6453 | + return in_array((isset($stateMap[$state]) ? $stateMap[$state] : '0'), $list); |
|
6454 | 6454 | } |
6455 | 6455 | |
6456 | 6456 | /** |
6457 | 6457 | * @see QueryWriter::addIndex |
6458 | 6458 | */ |
6459 | - public function addIndex( $type, $name, $property ) |
|
6459 | + public function addIndex($type, $name, $property) |
|
6460 | 6460 | { |
6461 | - $table = $this->esc( $type ); |
|
6462 | - $name = preg_replace( '/\W/', '', $name ); |
|
6463 | - $column = $this->esc( $property ); |
|
6461 | + $table = $this->esc($type); |
|
6462 | + $name = preg_replace('/\W/', '', $name); |
|
6463 | + $column = $this->esc($property); |
|
6464 | 6464 | |
6465 | 6465 | try { |
6466 | - $this->adapter->exec( "CREATE INDEX {$name} ON $table ({$column}) " ); |
|
6466 | + $this->adapter->exec("CREATE INDEX {$name} ON $table ({$column}) "); |
|
6467 | 6467 | return TRUE; |
6468 | - } catch ( SQLException $e ) { |
|
6468 | + } catch (SQLException $e) { |
|
6469 | 6469 | return FALSE; |
6470 | 6470 | } |
6471 | 6471 | } |
@@ -6473,22 +6473,22 @@ discard block |
||
6473 | 6473 | /** |
6474 | 6474 | * @see QueryWriter::addFK |
6475 | 6475 | */ |
6476 | - public function addFK( $type, $targetType, $property, $targetProperty, $isDep = FALSE ) |
|
6477 | - { |
|
6478 | - $table = $this->esc( $type ); |
|
6479 | - $targetTable = $this->esc( $targetType ); |
|
6480 | - $field = $this->esc( $property ); |
|
6481 | - $targetField = $this->esc( $targetProperty ); |
|
6482 | - $tableNoQ = $this->esc( $type, TRUE ); |
|
6483 | - $fieldNoQ = $this->esc( $property, TRUE ); |
|
6484 | - if ( !is_null( $this->getForeignKeyForTypeProperty( $tableNoQ, $fieldNoQ ) ) ) return FALSE; |
|
6485 | - try{ |
|
6486 | - $delRule = ( $isDep ? 'CASCADE' : 'SET NULL' ); |
|
6487 | - $this->adapter->exec( "ALTER TABLE {$table} |
|
6476 | + public function addFK($type, $targetType, $property, $targetProperty, $isDep = FALSE) |
|
6477 | + { |
|
6478 | + $table = $this->esc($type); |
|
6479 | + $targetTable = $this->esc($targetType); |
|
6480 | + $field = $this->esc($property); |
|
6481 | + $targetField = $this->esc($targetProperty); |
|
6482 | + $tableNoQ = $this->esc($type, TRUE); |
|
6483 | + $fieldNoQ = $this->esc($property, TRUE); |
|
6484 | + if (!is_null($this->getForeignKeyForTypeProperty($tableNoQ, $fieldNoQ))) return FALSE; |
|
6485 | + try { |
|
6486 | + $delRule = ($isDep ? 'CASCADE' : 'SET NULL'); |
|
6487 | + $this->adapter->exec("ALTER TABLE {$table} |
|
6488 | 6488 | ADD FOREIGN KEY ( {$field} ) REFERENCES {$targetTable} |
6489 | - ({$targetField}) ON DELETE {$delRule} ON UPDATE {$delRule} DEFERRABLE ;" ); |
|
6489 | + ({$targetField}) ON DELETE {$delRule} ON UPDATE {$delRule} DEFERRABLE ;"); |
|
6490 | 6490 | return TRUE; |
6491 | - } catch ( SQLException $e ) { |
|
6491 | + } catch (SQLException $e) { |
|
6492 | 6492 | return FALSE; |
6493 | 6493 | } |
6494 | 6494 | } |
@@ -6498,15 +6498,15 @@ discard block |
||
6498 | 6498 | */ |
6499 | 6499 | public function wipeAll() |
6500 | 6500 | { |
6501 | - $this->adapter->exec( 'SET CONSTRAINTS ALL DEFERRED' ); |
|
6501 | + $this->adapter->exec('SET CONSTRAINTS ALL DEFERRED'); |
|
6502 | 6502 | |
6503 | - foreach ( $this->getTables() as $t ) { |
|
6504 | - $t = $this->esc( $t ); |
|
6503 | + foreach ($this->getTables() as $t) { |
|
6504 | + $t = $this->esc($t); |
|
6505 | 6505 | |
6506 | - $this->adapter->exec( "DROP TABLE IF EXISTS $t CASCADE " ); |
|
6506 | + $this->adapter->exec("DROP TABLE IF EXISTS $t CASCADE "); |
|
6507 | 6507 | } |
6508 | 6508 | |
6509 | - $this->adapter->exec( 'SET CONSTRAINTS ALL IMMEDIATE' ); |
|
6509 | + $this->adapter->exec('SET CONSTRAINTS ALL IMMEDIATE'); |
|
6510 | 6510 | } |
6511 | 6511 | } |
6512 | 6512 | } |
@@ -6573,7 +6573,7 @@ discard block |
||
6573 | 6573 | * |
6574 | 6574 | * @return void |
6575 | 6575 | */ |
6576 | - public function setSQLState( $sqlState ) |
|
6576 | + public function setSQLState($sqlState) |
|
6577 | 6577 | { |
6578 | 6578 | $this->sqlState = $sqlState; |
6579 | 6579 | } |
@@ -6585,7 +6585,7 @@ discard block |
||
6585 | 6585 | */ |
6586 | 6586 | public function __toString() |
6587 | 6587 | { |
6588 | - return '[' . $this->getSQLState() . '] - ' . $this->getMessage()."\n". |
|
6588 | + return '[' . $this->getSQLState() . '] - ' . $this->getMessage() . "\n" . |
|
6589 | 6589 | 'trace: ' . $this->getTraceAsString(); |
6590 | 6590 | } |
6591 | 6591 | } |
@@ -6650,37 +6650,37 @@ discard block |
||
6650 | 6650 | * |
6651 | 6651 | * @return void |
6652 | 6652 | */ |
6653 | - protected function storeBeanWithLists( OODBBean $bean ) |
|
6653 | + protected function storeBeanWithLists(OODBBean $bean) |
|
6654 | 6654 | { |
6655 | 6655 | $sharedAdditions = $sharedTrashcan = $sharedresidue = $sharedItems = $ownAdditions = $ownTrashcan = $ownresidue = $embeddedBeans = array(); //Define groups |
6656 | - foreach ( $bean as $property => $value ) { |
|
6657 | - $value = ( $value instanceof SimpleModel ) ? $value->unbox() : $value; |
|
6658 | - if ( $value instanceof OODBBean ) { |
|
6659 | - $this->processEmbeddedBean( $embeddedBeans, $bean, $property, $value ); |
|
6656 | + foreach ($bean as $property => $value) { |
|
6657 | + $value = ($value instanceof SimpleModel) ? $value->unbox() : $value; |
|
6658 | + if ($value instanceof OODBBean) { |
|
6659 | + $this->processEmbeddedBean($embeddedBeans, $bean, $property, $value); |
|
6660 | 6660 | $bean->setMeta("sys.typeof.{$property}", $value->getMeta('type')); |
6661 | - } elseif ( is_array( $value ) ) { |
|
6662 | - $originals = $bean->moveMeta( 'sys.shadow.' . $property, array() ); |
|
6663 | - if ( strpos( $property, 'own' ) === 0 ) { |
|
6664 | - list( $ownAdditions, $ownTrashcan, $ownresidue ) = $this->processGroups( $originals, $value, $ownAdditions, $ownTrashcan, $ownresidue ); |
|
6665 | - $listName = lcfirst( substr( $property, 3 ) ); |
|
6666 | - if ($bean->moveMeta( 'sys.exclusive-'. $listName ) ) { |
|
6667 | - OODBBean::setMetaAll( $ownTrashcan, 'sys.garbage', TRUE ); |
|
6668 | - OODBBean::setMetaAll( $ownAdditions, 'sys.buildcommand.fkdependson', $bean->getMeta( 'type' ) ); |
|
6661 | + } elseif (is_array($value)) { |
|
6662 | + $originals = $bean->moveMeta('sys.shadow.' . $property, array()); |
|
6663 | + if (strpos($property, 'own') === 0) { |
|
6664 | + list($ownAdditions, $ownTrashcan, $ownresidue) = $this->processGroups($originals, $value, $ownAdditions, $ownTrashcan, $ownresidue); |
|
6665 | + $listName = lcfirst(substr($property, 3)); |
|
6666 | + if ($bean->moveMeta('sys.exclusive-' . $listName)) { |
|
6667 | + OODBBean::setMetaAll($ownTrashcan, 'sys.garbage', TRUE); |
|
6668 | + OODBBean::setMetaAll($ownAdditions, 'sys.buildcommand.fkdependson', $bean->getMeta('type')); |
|
6669 | 6669 | } |
6670 | - unset( $bean->$property ); |
|
6671 | - } elseif ( strpos( $property, 'shared' ) === 0 ) { |
|
6672 | - list( $sharedAdditions, $sharedTrashcan, $sharedresidue ) = $this->processGroups( $originals, $value, $sharedAdditions, $sharedTrashcan, $sharedresidue ); |
|
6673 | - unset( $bean->$property ); |
|
6670 | + unset($bean->$property); |
|
6671 | + } elseif (strpos($property, 'shared') === 0) { |
|
6672 | + list($sharedAdditions, $sharedTrashcan, $sharedresidue) = $this->processGroups($originals, $value, $sharedAdditions, $sharedTrashcan, $sharedresidue); |
|
6673 | + unset($bean->$property); |
|
6674 | 6674 | } |
6675 | 6675 | } |
6676 | 6676 | } |
6677 | - $this->storeBean( $bean ); |
|
6678 | - $this->processTrashcan( $bean, $ownTrashcan ); |
|
6679 | - $this->processAdditions( $bean, $ownAdditions ); |
|
6680 | - $this->processResidue( $ownresidue ); |
|
6681 | - $this->processSharedTrashcan( $bean, $sharedTrashcan ); |
|
6682 | - $this->processSharedAdditions( $bean, $sharedAdditions ); |
|
6683 | - $this->processSharedResidue( $bean, $sharedresidue ); |
|
6677 | + $this->storeBean($bean); |
|
6678 | + $this->processTrashcan($bean, $ownTrashcan); |
|
6679 | + $this->processAdditions($bean, $ownAdditions); |
|
6680 | + $this->processResidue($ownresidue); |
|
6681 | + $this->processSharedTrashcan($bean, $sharedTrashcan); |
|
6682 | + $this->processSharedAdditions($bean, $sharedAdditions); |
|
6683 | + $this->processSharedResidue($bean, $sharedresidue); |
|
6684 | 6684 | } |
6685 | 6685 | |
6686 | 6686 | /** |
@@ -6698,12 +6698,12 @@ discard block |
||
6698 | 6698 | * |
6699 | 6699 | * @return array |
6700 | 6700 | */ |
6701 | - protected function processGroups( $originals, $current, $additions, $trashcan, $residue ) |
|
6701 | + protected function processGroups($originals, $current, $additions, $trashcan, $residue) |
|
6702 | 6702 | { |
6703 | 6703 | return array( |
6704 | - array_merge( $additions, array_diff( $current, $originals ) ), |
|
6705 | - array_merge( $trashcan, array_diff( $originals, $current ) ), |
|
6706 | - array_merge( $residue, array_intersect( $current, $originals ) ) |
|
6704 | + array_merge($additions, array_diff($current, $originals)), |
|
6705 | + array_merge($trashcan, array_diff($originals, $current)), |
|
6706 | + array_merge($residue, array_intersect($current, $originals)) |
|
6707 | 6707 | ); |
6708 | 6708 | } |
6709 | 6709 | |
@@ -6714,10 +6714,10 @@ discard block |
||
6714 | 6714 | * |
6715 | 6715 | * @return integer |
6716 | 6716 | */ |
6717 | - protected function prepareEmbeddedBean( $embeddedBean ) |
|
6717 | + protected function prepareEmbeddedBean($embeddedBean) |
|
6718 | 6718 | { |
6719 | - if ( !$embeddedBean->id || $embeddedBean->getMeta( 'tainted' ) ) { |
|
6720 | - $this->store( $embeddedBean ); |
|
6719 | + if (!$embeddedBean->id || $embeddedBean->getMeta('tainted')) { |
|
6720 | + $this->store($embeddedBean); |
|
6721 | 6721 | } |
6722 | 6722 | |
6723 | 6723 | return $embeddedBean->id; |
@@ -6734,13 +6734,13 @@ discard block |
||
6734 | 6734 | * |
6735 | 6735 | * @throws Security |
6736 | 6736 | */ |
6737 | - protected function processSharedAdditions( $bean, $sharedAdditions ) |
|
6737 | + protected function processSharedAdditions($bean, $sharedAdditions) |
|
6738 | 6738 | { |
6739 | - foreach ( $sharedAdditions as $addition ) { |
|
6740 | - if ( $addition instanceof OODBBean ) { |
|
6741 | - $this->oodb->getAssociationManager()->associate( $addition, $bean ); |
|
6739 | + foreach ($sharedAdditions as $addition) { |
|
6740 | + if ($addition instanceof OODBBean) { |
|
6741 | + $this->oodb->getAssociationManager()->associate($addition, $bean); |
|
6742 | 6742 | } else { |
6743 | - throw new RedException( 'Array may only contain OODBBeans' ); |
|
6743 | + throw new RedException('Array may only contain OODBBeans'); |
|
6744 | 6744 | } |
6745 | 6745 | } |
6746 | 6746 | } |
@@ -6757,11 +6757,11 @@ discard block |
||
6757 | 6757 | * |
6758 | 6758 | * @return void |
6759 | 6759 | */ |
6760 | - protected function processResidue( $ownresidue ) |
|
6760 | + protected function processResidue($ownresidue) |
|
6761 | 6761 | { |
6762 | - foreach ( $ownresidue as $residue ) { |
|
6763 | - if ( $residue->getMeta( 'tainted' ) ) { |
|
6764 | - $this->store( $residue ); |
|
6762 | + foreach ($ownresidue as $residue) { |
|
6763 | + if ($residue->getMeta('tainted')) { |
|
6764 | + $this->store($residue); |
|
6765 | 6765 | } |
6766 | 6766 | } |
6767 | 6767 | } |
@@ -6780,20 +6780,20 @@ discard block |
||
6780 | 6780 | * |
6781 | 6781 | * @return void |
6782 | 6782 | */ |
6783 | - protected function processTrashcan( $bean, $ownTrashcan ) |
|
6783 | + protected function processTrashcan($bean, $ownTrashcan) |
|
6784 | 6784 | { |
6785 | 6785 | |
6786 | - foreach ( $ownTrashcan as $trash ) { |
|
6786 | + foreach ($ownTrashcan as $trash) { |
|
6787 | 6787 | |
6788 | - $myFieldLink = $bean->getMeta( 'type' ) . '_id'; |
|
6789 | - $alias = $bean->getMeta( 'sys.alias.' . $trash->getMeta( 'type' ) ); |
|
6790 | - if ( $alias ) $myFieldLink = $alias . '_id'; |
|
6788 | + $myFieldLink = $bean->getMeta('type') . '_id'; |
|
6789 | + $alias = $bean->getMeta('sys.alias.' . $trash->getMeta('type')); |
|
6790 | + if ($alias) $myFieldLink = $alias . '_id'; |
|
6791 | 6791 | |
6792 | - if ( $trash->getMeta( 'sys.garbage' ) === true ) { |
|
6793 | - $this->trash( $trash ); |
|
6792 | + if ($trash->getMeta('sys.garbage') === true) { |
|
6793 | + $this->trash($trash); |
|
6794 | 6794 | } else { |
6795 | 6795 | $trash->$myFieldLink = NULL; |
6796 | - $this->store( $trash ); |
|
6796 | + $this->store($trash); |
|
6797 | 6797 | } |
6798 | 6798 | } |
6799 | 6799 | } |
@@ -6806,10 +6806,10 @@ discard block |
||
6806 | 6806 | * |
6807 | 6807 | * @return void |
6808 | 6808 | */ |
6809 | - protected function processSharedTrashcan( $bean, $sharedTrashcan ) |
|
6809 | + protected function processSharedTrashcan($bean, $sharedTrashcan) |
|
6810 | 6810 | { |
6811 | - foreach ( $sharedTrashcan as $trash ) { |
|
6812 | - $this->oodb->getAssociationManager()->unassociate( $trash, $bean ); |
|
6811 | + foreach ($sharedTrashcan as $trash) { |
|
6812 | + $this->oodb->getAssociationManager()->unassociate($trash, $bean); |
|
6813 | 6813 | } |
6814 | 6814 | } |
6815 | 6815 | |
@@ -6821,10 +6821,10 @@ discard block |
||
6821 | 6821 | * |
6822 | 6822 | * @return void |
6823 | 6823 | */ |
6824 | - protected function processSharedResidue( $bean, $sharedresidue ) |
|
6824 | + protected function processSharedResidue($bean, $sharedresidue) |
|
6825 | 6825 | { |
6826 | - foreach ( $sharedresidue as $residue ) { |
|
6827 | - $this->store( $residue ); |
|
6826 | + foreach ($sharedresidue as $residue) { |
|
6827 | + $this->store($residue); |
|
6828 | 6828 | } |
6829 | 6829 | } |
6830 | 6830 | |
@@ -6837,11 +6837,11 @@ discard block |
||
6837 | 6837 | * |
6838 | 6838 | * @return boolean |
6839 | 6839 | */ |
6840 | - protected function hasListsOrObjects( OODBBean $bean ) |
|
6840 | + protected function hasListsOrObjects(OODBBean $bean) |
|
6841 | 6841 | { |
6842 | 6842 | $processLists = FALSE; |
6843 | - foreach ( $bean as $value ) { |
|
6844 | - if ( is_array( $value ) || is_object( $value ) ) { |
|
6843 | + foreach ($bean as $value) { |
|
6844 | + if (is_array($value) || is_object($value)) { |
|
6845 | 6845 | $processLists = TRUE; |
6846 | 6846 | break; |
6847 | 6847 | } |
@@ -6860,14 +6860,14 @@ discard block |
||
6860 | 6860 | * @param string $property property that contains the embedded bean |
6861 | 6861 | * @param OODBBean $value embedded bean itself |
6862 | 6862 | */ |
6863 | - protected function processEmbeddedBean( &$embeddedBeans, $bean, $property, OODBBean $value ) |
|
6863 | + protected function processEmbeddedBean(&$embeddedBeans, $bean, $property, OODBBean $value) |
|
6864 | 6864 | { |
6865 | - $linkField = $property . '_id'; |
|
6866 | - $id = $this->prepareEmbeddedBean( $value ); |
|
6865 | + $linkField = $property . '_id'; |
|
6866 | + $id = $this->prepareEmbeddedBean($value); |
|
6867 | 6867 | if ($bean->$linkField != $id) $bean->$linkField = $id; |
6868 | - $bean->setMeta( 'cast.' . $linkField, 'id' ); |
|
6868 | + $bean->setMeta('cast.' . $linkField, 'id'); |
|
6869 | 6869 | $embeddedBeans[$linkField] = $value; |
6870 | - unset( $bean->$property ); |
|
6870 | + unset($bean->$property); |
|
6871 | 6871 | } |
6872 | 6872 | |
6873 | 6873 | |
@@ -6876,7 +6876,7 @@ discard block |
||
6876 | 6876 | * |
6877 | 6877 | * @param QueryWriter $writer writer |
6878 | 6878 | */ |
6879 | - public function __construct( OODB $oodb, QueryWriter $writer ) |
|
6879 | + public function __construct(OODB $oodb, QueryWriter $writer) |
|
6880 | 6880 | { |
6881 | 6881 | $this->writer = $writer; |
6882 | 6882 | $this->oodb = $oodb; |
@@ -6893,33 +6893,33 @@ discard block |
||
6893 | 6893 | * |
6894 | 6894 | * @throws Security $exception |
6895 | 6895 | */ |
6896 | - public function check( OODBBean $bean ) |
|
6896 | + public function check(OODBBean $bean) |
|
6897 | 6897 | { |
6898 | 6898 | //Is all meta information present? |
6899 | - if ( !isset( $bean->id ) ) { |
|
6900 | - throw new RedException( 'Bean has incomplete Meta Information id ' ); |
|
6899 | + if (!isset($bean->id)) { |
|
6900 | + throw new RedException('Bean has incomplete Meta Information id '); |
|
6901 | 6901 | } |
6902 | - if ( !( $bean->getMeta( 'type' ) ) ) { |
|
6903 | - throw new RedException( 'Bean has incomplete Meta Information II' ); |
|
6902 | + if (!($bean->getMeta('type'))) { |
|
6903 | + throw new RedException('Bean has incomplete Meta Information II'); |
|
6904 | 6904 | } |
6905 | 6905 | //Pattern of allowed characters |
6906 | 6906 | $pattern = '/[^a-z0-9_]/i'; |
6907 | 6907 | //Does the type contain invalid characters? |
6908 | - if ( preg_match( $pattern, $bean->getMeta( 'type' ) ) ) { |
|
6909 | - throw new RedException( 'Bean Type is invalid' ); |
|
6908 | + if (preg_match($pattern, $bean->getMeta('type'))) { |
|
6909 | + throw new RedException('Bean Type is invalid'); |
|
6910 | 6910 | } |
6911 | 6911 | //Are the properties and values valid? |
6912 | - foreach ( $bean as $prop => $value ) { |
|
6912 | + foreach ($bean as $prop => $value) { |
|
6913 | 6913 | if ( |
6914 | - is_array( $value ) |
|
6915 | - || ( is_object( $value ) ) |
|
6914 | + is_array($value) |
|
6915 | + || (is_object($value)) |
|
6916 | 6916 | ) { |
6917 | - throw new RedException( "Invalid Bean value: property $prop" ); |
|
6917 | + throw new RedException("Invalid Bean value: property $prop"); |
|
6918 | 6918 | } else if ( |
6919 | - strlen( $prop ) < 1 |
|
6920 | - || preg_match( $pattern, $prop ) |
|
6919 | + strlen($prop) < 1 |
|
6920 | + || preg_match($pattern, $prop) |
|
6921 | 6921 | ) { |
6922 | - throw new RedException( "Invalid Bean property: property $prop" ); |
|
6922 | + throw new RedException("Invalid Bean property: property $prop"); |
|
6923 | 6923 | } |
6924 | 6924 | } |
6925 | 6925 | } |
@@ -6949,21 +6949,21 @@ discard block |
||
6949 | 6949 | * @return array |
6950 | 6950 | * |
6951 | 6951 | */ |
6952 | - public function find( $type, $conditions = array(), $sql = NULL, $bindings = array() ) |
|
6952 | + public function find($type, $conditions = array(), $sql = NULL, $bindings = array()) |
|
6953 | 6953 | { |
6954 | 6954 | //for backward compatibility, allow mismatch arguments: |
6955 | - if ( is_array( $sql ) ) { |
|
6956 | - if ( isset( $sql[1] ) ) { |
|
6955 | + if (is_array($sql)) { |
|
6956 | + if (isset($sql[1])) { |
|
6957 | 6957 | $bindings = $sql[1]; |
6958 | 6958 | } |
6959 | 6959 | $sql = $sql[0]; |
6960 | 6960 | } |
6961 | 6961 | try { |
6962 | - $beans = $this->convertToBeans( $type, $this->writer->queryRecord( $type, $conditions, $sql, $bindings ) ); |
|
6962 | + $beans = $this->convertToBeans($type, $this->writer->queryRecord($type, $conditions, $sql, $bindings)); |
|
6963 | 6963 | |
6964 | 6964 | return $beans; |
6965 | - } catch ( SQLException $exception ) { |
|
6966 | - $this->handleException( $exception ); |
|
6965 | + } catch (SQLException $exception) { |
|
6966 | + $this->handleException($exception); |
|
6967 | 6967 | } |
6968 | 6968 | |
6969 | 6969 | return array(); |
@@ -6978,15 +6978,15 @@ discard block |
||
6978 | 6978 | * |
6979 | 6979 | * @return BeanCollection |
6980 | 6980 | */ |
6981 | - public function findCollection( $type, $sql, $bindings = array() ) |
|
6981 | + public function findCollection($type, $sql, $bindings = array()) |
|
6982 | 6982 | { |
6983 | 6983 | try { |
6984 | - $cursor = $this->writer->queryRecordWithCursor( $type, $sql, $bindings ); |
|
6985 | - return new BeanCollection( $type, $this, $cursor ); |
|
6986 | - } catch ( SQLException $exception ) { |
|
6987 | - $this->handleException( $exception ); |
|
6984 | + $cursor = $this->writer->queryRecordWithCursor($type, $sql, $bindings); |
|
6985 | + return new BeanCollection($type, $this, $cursor); |
|
6986 | + } catch (SQLException $exception) { |
|
6987 | + $this->handleException($exception); |
|
6988 | 6988 | } |
6989 | - return new BeanCollection( $type, $this, new NullCursor ); |
|
6989 | + return new BeanCollection($type, $this, new NullCursor); |
|
6990 | 6990 | } |
6991 | 6991 | |
6992 | 6992 | /** |
@@ -7009,22 +7009,22 @@ discard block |
||
7009 | 7009 | * |
7010 | 7010 | * @return integer|string |
7011 | 7011 | */ |
7012 | - public function store( $bean ) |
|
7012 | + public function store($bean) |
|
7013 | 7013 | { |
7014 | - $processLists = $this->hasListsOrObjects( $bean ); |
|
7015 | - if ( !$processLists && !$bean->getMeta( 'tainted' ) ) { |
|
7014 | + $processLists = $this->hasListsOrObjects($bean); |
|
7015 | + if (!$processLists && !$bean->getMeta('tainted')) { |
|
7016 | 7016 | return $bean->getID(); //bail out! |
7017 | 7017 | } |
7018 | - $this->oodb->signal( 'update', $bean ); |
|
7019 | - $processLists = $this->hasListsOrObjects( $bean ); //check again, might have changed by model! |
|
7020 | - if ( $processLists ) { |
|
7021 | - $this->storeBeanWithLists( $bean ); |
|
7018 | + $this->oodb->signal('update', $bean); |
|
7019 | + $processLists = $this->hasListsOrObjects($bean); //check again, might have changed by model! |
|
7020 | + if ($processLists) { |
|
7021 | + $this->storeBeanWithLists($bean); |
|
7022 | 7022 | } else { |
7023 | - $this->storeBean( $bean ); |
|
7023 | + $this->storeBean($bean); |
|
7024 | 7024 | } |
7025 | - $this->oodb->signal( 'after_update', $bean ); |
|
7025 | + $this->oodb->signal('after_update', $bean); |
|
7026 | 7026 | |
7027 | - return ( (string) $bean->id === (string) (int) $bean->id ) ? (int) $bean->id : (string) $bean->id; |
|
7027 | + return ((string) $bean->id === (string) (int) $bean->id) ? (int) $bean->id : (string) $bean->id; |
|
7028 | 7028 | } |
7029 | 7029 | |
7030 | 7030 | /** |
@@ -7041,27 +7041,27 @@ discard block |
||
7041 | 7041 | * |
7042 | 7042 | * @return array |
7043 | 7043 | */ |
7044 | - public function batch( $type, $ids ) |
|
7044 | + public function batch($type, $ids) |
|
7045 | 7045 | { |
7046 | - if ( !$ids ) { |
|
7046 | + if (!$ids) { |
|
7047 | 7047 | return array(); |
7048 | 7048 | } |
7049 | 7049 | $collection = array(); |
7050 | 7050 | try { |
7051 | - $rows = $this->writer->queryRecord( $type, array( 'id' => $ids ) ); |
|
7052 | - } catch ( SQLException $e ) { |
|
7053 | - $this->handleException( $e ); |
|
7051 | + $rows = $this->writer->queryRecord($type, array('id' => $ids)); |
|
7052 | + } catch (SQLException $e) { |
|
7053 | + $this->handleException($e); |
|
7054 | 7054 | $rows = FALSE; |
7055 | 7055 | } |
7056 | 7056 | $this->stash[$this->nesting] = array(); |
7057 | - if ( !$rows ) { |
|
7057 | + if (!$rows) { |
|
7058 | 7058 | return array(); |
7059 | 7059 | } |
7060 | - foreach ( $rows as $row ) { |
|
7060 | + foreach ($rows as $row) { |
|
7061 | 7061 | $this->stash[$this->nesting][$row['id']] = $row; |
7062 | 7062 | } |
7063 | - foreach ( $ids as $id ) { |
|
7064 | - $collection[$id] = $this->load( $type, $id ); |
|
7063 | + foreach ($ids as $id) { |
|
7064 | + $collection[$id] = $this->load($type, $id); |
|
7065 | 7065 | } |
7066 | 7066 | $this->stash[$this->nesting] = NULL; |
7067 | 7067 | |
@@ -7079,14 +7079,14 @@ discard block |
||
7079 | 7079 | * |
7080 | 7080 | * @return array |
7081 | 7081 | */ |
7082 | - public function convertToBeans( $type, $rows ) |
|
7082 | + public function convertToBeans($type, $rows) |
|
7083 | 7083 | { |
7084 | 7084 | $collection = array(); |
7085 | 7085 | $this->stash[$this->nesting] = array(); |
7086 | - foreach ( $rows as $row ) { |
|
7086 | + foreach ($rows as $row) { |
|
7087 | 7087 | $id = $row['id']; |
7088 | 7088 | $this->stash[$this->nesting][$id] = $row; |
7089 | - $collection[$id] = $this->load( $type, $id ); |
|
7089 | + $collection[$id] = $this->load($type, $id); |
|
7090 | 7090 | } |
7091 | 7091 | $this->stash[$this->nesting] = NULL; |
7092 | 7092 | |
@@ -7106,19 +7106,19 @@ discard block |
||
7106 | 7106 | * |
7107 | 7107 | * @throws SQLException |
7108 | 7108 | */ |
7109 | - public function count( $type, $addSQL = '', $bindings = array() ) |
|
7109 | + public function count($type, $addSQL = '', $bindings = array()) |
|
7110 | 7110 | { |
7111 | - $type = AQueryWriter::camelsSnake( $type ); |
|
7112 | - if ( count( explode( '_', $type ) ) > 2 ) { |
|
7113 | - throw new RedException( 'Invalid type for count.' ); |
|
7111 | + $type = AQueryWriter::camelsSnake($type); |
|
7112 | + if (count(explode('_', $type)) > 2) { |
|
7113 | + throw new RedException('Invalid type for count.'); |
|
7114 | 7114 | } |
7115 | 7115 | |
7116 | 7116 | try { |
7117 | - return (int) $this->writer->queryRecordCount( $type, array(), $addSQL, $bindings ); |
|
7118 | - } catch ( SQLException $exception ) { |
|
7119 | - if ( !$this->writer->sqlStateIn( $exception->getSQLState(), array( |
|
7117 | + return (int) $this->writer->queryRecordCount($type, array(), $addSQL, $bindings); |
|
7118 | + } catch (SQLException $exception) { |
|
7119 | + if (!$this->writer->sqlStateIn($exception->getSQLState(), array( |
|
7120 | 7120 | QueryWriter::C_SQLSTATE_NO_SUCH_TABLE, |
7121 | - QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN ) ) ) { |
|
7121 | + QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN ))) { |
|
7122 | 7122 | throw $exception; |
7123 | 7123 | } |
7124 | 7124 | } |
@@ -7137,28 +7137,28 @@ discard block |
||
7137 | 7137 | * |
7138 | 7138 | * @throws SQLException |
7139 | 7139 | */ |
7140 | - public function trash( $bean ) |
|
7140 | + public function trash($bean) |
|
7141 | 7141 | { |
7142 | - $this->oodb->signal( 'delete', $bean ); |
|
7143 | - foreach ( $bean as $property => $value ) { |
|
7144 | - if ( $value instanceof OODBBean ) { |
|
7145 | - unset( $bean->$property ); |
|
7142 | + $this->oodb->signal('delete', $bean); |
|
7143 | + foreach ($bean as $property => $value) { |
|
7144 | + if ($value instanceof OODBBean) { |
|
7145 | + unset($bean->$property); |
|
7146 | 7146 | } |
7147 | - if ( is_array( $value ) ) { |
|
7148 | - if ( strpos( $property, 'own' ) === 0 ) { |
|
7149 | - unset( $bean->$property ); |
|
7150 | - } elseif ( strpos( $property, 'shared' ) === 0 ) { |
|
7151 | - unset( $bean->$property ); |
|
7147 | + if (is_array($value)) { |
|
7148 | + if (strpos($property, 'own') === 0) { |
|
7149 | + unset($bean->$property); |
|
7150 | + } elseif (strpos($property, 'shared') === 0) { |
|
7151 | + unset($bean->$property); |
|
7152 | 7152 | } |
7153 | 7153 | } |
7154 | 7154 | } |
7155 | 7155 | try { |
7156 | - $this->writer->deleteRecord( $bean->getMeta( 'type' ), array( 'id' => array( $bean->id ) ), NULL ); |
|
7157 | - } catch ( SQLException $exception ) { |
|
7158 | - $this->handleException( $exception ); |
|
7156 | + $this->writer->deleteRecord($bean->getMeta('type'), array('id' => array($bean->id)), NULL); |
|
7157 | + } catch (SQLException $exception) { |
|
7158 | + $this->handleException($exception); |
|
7159 | 7159 | } |
7160 | 7160 | $bean->id = 0; |
7161 | - $this->oodb->signal( 'after_delete', $bean ); |
|
7161 | + $this->oodb->signal('after_delete', $bean); |
|
7162 | 7162 | } |
7163 | 7163 | |
7164 | 7164 | /** |
@@ -7171,9 +7171,9 @@ discard block |
||
7171 | 7171 | * |
7172 | 7172 | * @return boolean |
7173 | 7173 | */ |
7174 | - public function tableExists( $table ) |
|
7174 | + public function tableExists($table) |
|
7175 | 7175 | { |
7176 | - return $this->writer->tableExists( $table ); |
|
7176 | + return $this->writer->tableExists($table); |
|
7177 | 7177 | } |
7178 | 7178 | |
7179 | 7179 | /** |
@@ -7185,14 +7185,14 @@ discard block |
||
7185 | 7185 | * |
7186 | 7186 | * @throws SQLException |
7187 | 7187 | */ |
7188 | - public function wipe( $type ) |
|
7188 | + public function wipe($type) |
|
7189 | 7189 | { |
7190 | 7190 | try { |
7191 | - $this->writer->wipe( $type ); |
|
7191 | + $this->writer->wipe($type); |
|
7192 | 7192 | |
7193 | 7193 | return TRUE; |
7194 | - } catch ( SQLException $exception ) { |
|
7195 | - if ( !$this->writer->sqlStateIn( $exception->getSQLState(), array( QueryWriter::C_SQLSTATE_NO_SUCH_TABLE ) ) ) { |
|
7194 | + } catch (SQLException $exception) { |
|
7195 | + if (!$this->writer->sqlStateIn($exception->getSQLState(), array(QueryWriter::C_SQLSTATE_NO_SUCH_TABLE))) { |
|
7196 | 7196 | throw $exception; |
7197 | 7197 | } |
7198 | 7198 | |
@@ -7246,16 +7246,16 @@ discard block |
||
7246 | 7246 | * |
7247 | 7247 | * @throws Security |
7248 | 7248 | */ |
7249 | - private function getTypeFromCast( $cast ) |
|
7249 | + private function getTypeFromCast($cast) |
|
7250 | 7250 | { |
7251 | - if ( $cast == 'string' ) { |
|
7252 | - $typeno = $this->writer->scanType( 'STRING' ); |
|
7253 | - } elseif ( $cast == 'id' ) { |
|
7251 | + if ($cast == 'string') { |
|
7252 | + $typeno = $this->writer->scanType('STRING'); |
|
7253 | + } elseif ($cast == 'id') { |
|
7254 | 7254 | $typeno = $this->writer->getTypeForID(); |
7255 | - } elseif ( isset( $this->writer->sqltype_typeno[$cast] ) ) { |
|
7255 | + } elseif (isset($this->writer->sqltype_typeno[$cast])) { |
|
7256 | 7256 | $typeno = $this->writer->sqltype_typeno[$cast]; |
7257 | 7257 | } else { |
7258 | - throw new RedException( 'Invalid Cast' ); |
|
7258 | + throw new RedException('Invalid Cast'); |
|
7259 | 7259 | } |
7260 | 7260 | |
7261 | 7261 | return $typeno; |
@@ -7270,12 +7270,12 @@ discard block |
||
7270 | 7270 | * |
7271 | 7271 | * @return void |
7272 | 7272 | */ |
7273 | - private function createTableIfNotExists( OODBBean $bean, $table ) |
|
7273 | + private function createTableIfNotExists(OODBBean $bean, $table) |
|
7274 | 7274 | { |
7275 | 7275 | //Does table exist? If not, create |
7276 | - if ( !$this->tableExists( $this->writer->esc( $table, TRUE ) ) ) { |
|
7277 | - $this->writer->createTable( $table ); |
|
7278 | - $bean->setMeta( 'buildreport.flags.created', TRUE ); |
|
7276 | + if (!$this->tableExists($this->writer->esc($table, TRUE))) { |
|
7277 | + $this->writer->createTable($table); |
|
7278 | + $bean->setMeta('buildreport.flags.created', TRUE); |
|
7279 | 7279 | } |
7280 | 7280 | } |
7281 | 7281 | |
@@ -7295,48 +7295,48 @@ discard block |
||
7295 | 7295 | * |
7296 | 7296 | * @return void |
7297 | 7297 | */ |
7298 | - private function modifySchema( OODBBean $bean, $property, $value ) |
|
7298 | + private function modifySchema(OODBBean $bean, $property, $value) |
|
7299 | 7299 | { |
7300 | 7300 | $doFKStuff = FALSE; |
7301 | - $table = $bean->getMeta( 'type' ); |
|
7302 | - $columns = $this->writer->getColumns( $table ); |
|
7303 | - $columnNoQ = $this->writer->esc( $property, TRUE ); |
|
7304 | - if ( !$this->oodb->isChilled( $bean->getMeta( 'type' ) ) ) { |
|
7305 | - if ( $bean->getMeta( "cast.$property", -1 ) !== -1 ) { //check for explicitly specified types |
|
7306 | - $cast = $bean->getMeta( "cast.$property" ); |
|
7307 | - $typeno = $this->getTypeFromCast( $cast ); |
|
7301 | + $table = $bean->getMeta('type'); |
|
7302 | + $columns = $this->writer->getColumns($table); |
|
7303 | + $columnNoQ = $this->writer->esc($property, TRUE); |
|
7304 | + if (!$this->oodb->isChilled($bean->getMeta('type'))) { |
|
7305 | + if ($bean->getMeta("cast.$property", -1) !== -1) { //check for explicitly specified types |
|
7306 | + $cast = $bean->getMeta("cast.$property"); |
|
7307 | + $typeno = $this->getTypeFromCast($cast); |
|
7308 | 7308 | } else { |
7309 | 7309 | $cast = FALSE; |
7310 | - $typeno = $this->writer->scanType( $value, TRUE ); |
|
7310 | + $typeno = $this->writer->scanType($value, TRUE); |
|
7311 | 7311 | } |
7312 | - if ( isset( $columns[$this->writer->esc( $property, TRUE )] ) ) { //Is this property represented in the table ? |
|
7313 | - if ( !$cast ) { //rescan without taking into account special types >80 |
|
7314 | - $typeno = $this->writer->scanType( $value, FALSE ); |
|
7312 | + if (isset($columns[$this->writer->esc($property, TRUE)])) { //Is this property represented in the table ? |
|
7313 | + if (!$cast) { //rescan without taking into account special types >80 |
|
7314 | + $typeno = $this->writer->scanType($value, FALSE); |
|
7315 | 7315 | } |
7316 | - $sqlt = $this->writer->code( $columns[$this->writer->esc( $property, TRUE )] ); |
|
7317 | - if ( $typeno > $sqlt ) { //no, we have to widen the database column type |
|
7318 | - $this->writer->widenColumn( $table, $property, $typeno ); |
|
7319 | - $bean->setMeta( 'buildreport.flags.widen', TRUE ); |
|
7316 | + $sqlt = $this->writer->code($columns[$this->writer->esc($property, TRUE)]); |
|
7317 | + if ($typeno > $sqlt) { //no, we have to widen the database column type |
|
7318 | + $this->writer->widenColumn($table, $property, $typeno); |
|
7319 | + $bean->setMeta('buildreport.flags.widen', TRUE); |
|
7320 | 7320 | $doFKStuff = TRUE; |
7321 | 7321 | } |
7322 | 7322 | } else { |
7323 | - $this->writer->addColumn( $table, $property, $typeno ); |
|
7324 | - $bean->setMeta( 'buildreport.flags.addcolumn', TRUE ); |
|
7323 | + $this->writer->addColumn($table, $property, $typeno); |
|
7324 | + $bean->setMeta('buildreport.flags.addcolumn', TRUE); |
|
7325 | 7325 | $doFKStuff = TRUE; |
7326 | 7326 | } |
7327 | 7327 | if ($doFKStuff) { |
7328 | - if (strrpos($columnNoQ, '_id')===(strlen($columnNoQ)-3)) { |
|
7329 | - $destinationColumnNoQ = substr($columnNoQ, 0, strlen($columnNoQ)-3); |
|
7328 | + if (strrpos($columnNoQ, '_id') === (strlen($columnNoQ) - 3)) { |
|
7329 | + $destinationColumnNoQ = substr($columnNoQ, 0, strlen($columnNoQ) - 3); |
|
7330 | 7330 | $indexName = "index_foreignkey_{$table}_{$destinationColumnNoQ}"; |
7331 | 7331 | $this->writer->addIndex($table, $indexName, $columnNoQ); |
7332 | 7332 | $typeof = $bean->getMeta("sys.typeof.{$destinationColumnNoQ}", $destinationColumnNoQ); |
7333 | - $isLink = $bean->getMeta( 'sys.buildcommand.unique', FALSE ); |
|
7333 | + $isLink = $bean->getMeta('sys.buildcommand.unique', FALSE); |
|
7334 | 7334 | //Make FK CASCADING if part of exclusive list (dependson=typeof) or if link bean |
7335 | - $isDep = ( $bean->moveMeta( 'sys.buildcommand.fkdependson' ) === $typeof || is_array( $isLink ) ); |
|
7336 | - $result = $this->writer->addFK( $table, $typeof, $columnNoQ, 'id', $isDep ); |
|
7335 | + $isDep = ($bean->moveMeta('sys.buildcommand.fkdependson') === $typeof || is_array($isLink)); |
|
7336 | + $result = $this->writer->addFK($table, $typeof, $columnNoQ, 'id', $isDep); |
|
7337 | 7337 | //If this is a link bean and all unique columns have been added already, then apply unique constraint |
7338 | - if ( is_array( $isLink ) && !count( array_diff( $isLink, array_keys( $this->writer->getColumns( $table ) ) ) ) ) { |
|
7339 | - $this->writer->addUniqueConstraint( $table, $bean->moveMeta('sys.buildcommand.unique') ); |
|
7338 | + if (is_array($isLink) && !count(array_diff($isLink, array_keys($this->writer->getColumns($table))))) { |
|
7339 | + $this->writer->addUniqueConstraint($table, $bean->moveMeta('sys.buildcommand.unique')); |
|
7340 | 7340 | $bean->setMeta("sys.typeof.{$destinationColumnNoQ}", NULL); |
7341 | 7341 | } |
7342 | 7342 | } |
@@ -7358,29 +7358,29 @@ discard block |
||
7358 | 7358 | * |
7359 | 7359 | * @throws Security |
7360 | 7360 | */ |
7361 | - protected function processAdditions( $bean, $ownAdditions ) |
|
7361 | + protected function processAdditions($bean, $ownAdditions) |
|
7362 | 7362 | { |
7363 | - $beanType = $bean->getMeta( 'type' ); |
|
7363 | + $beanType = $bean->getMeta('type'); |
|
7364 | 7364 | |
7365 | - foreach ( $ownAdditions as $addition ) { |
|
7366 | - if ( $addition instanceof OODBBean ) { |
|
7365 | + foreach ($ownAdditions as $addition) { |
|
7366 | + if ($addition instanceof OODBBean) { |
|
7367 | 7367 | |
7368 | 7368 | $myFieldLink = $beanType . '_id'; |
7369 | - $alias = $bean->getMeta( 'sys.alias.' . $addition->getMeta( 'type' ) ); |
|
7370 | - if ( $alias ) $myFieldLink = $alias . '_id'; |
|
7369 | + $alias = $bean->getMeta('sys.alias.' . $addition->getMeta('type')); |
|
7370 | + if ($alias) $myFieldLink = $alias . '_id'; |
|
7371 | 7371 | |
7372 | 7372 | $addition->$myFieldLink = $bean->id; |
7373 | - $addition->setMeta( 'cast.' . $myFieldLink, 'id' ); |
|
7373 | + $addition->setMeta('cast.' . $myFieldLink, 'id'); |
|
7374 | 7374 | |
7375 | 7375 | if ($alias) { |
7376 | - $addition->setMeta( "sys.typeof.{$alias}", $beanType ); |
|
7376 | + $addition->setMeta("sys.typeof.{$alias}", $beanType); |
|
7377 | 7377 | } else { |
7378 | - $addition->setMeta( "sys.typeof.{$beanType}", $beanType ); |
|
7378 | + $addition->setMeta("sys.typeof.{$beanType}", $beanType); |
|
7379 | 7379 | } |
7380 | 7380 | |
7381 | - $this->store( $addition ); |
|
7381 | + $this->store($addition); |
|
7382 | 7382 | } else { |
7383 | - throw new RedException( 'Array may only contain OODBBeans' ); |
|
7383 | + throw new RedException('Array may only contain OODBBeans'); |
|
7384 | 7384 | } |
7385 | 7385 | } |
7386 | 7386 | } |
@@ -7395,27 +7395,27 @@ discard block |
||
7395 | 7395 | * |
7396 | 7396 | * @return void |
7397 | 7397 | */ |
7398 | - protected function storeBean( OODBBean $bean ) |
|
7398 | + protected function storeBean(OODBBean $bean) |
|
7399 | 7399 | { |
7400 | - if ( $bean->getMeta( 'changed' ) ) { |
|
7401 | - $this->check( $bean ); |
|
7402 | - $table = $bean->getMeta( 'type' ); |
|
7403 | - $this->createTableIfNotExists( $bean, $table ); |
|
7400 | + if ($bean->getMeta('changed')) { |
|
7401 | + $this->check($bean); |
|
7402 | + $table = $bean->getMeta('type'); |
|
7403 | + $this->createTableIfNotExists($bean, $table); |
|
7404 | 7404 | |
7405 | 7405 | $updateValues = array(); |
7406 | - foreach ( $bean as $property => $value ) { |
|
7407 | - if ( $property !== 'id' ) { |
|
7408 | - $this->modifySchema( $bean, $property, $value ); |
|
7406 | + foreach ($bean as $property => $value) { |
|
7407 | + if ($property !== 'id') { |
|
7408 | + $this->modifySchema($bean, $property, $value); |
|
7409 | 7409 | } |
7410 | - if ( $property !== 'id' ) { |
|
7411 | - $updateValues[] = array( 'property' => $property, 'value' => $value ); |
|
7410 | + if ($property !== 'id') { |
|
7411 | + $updateValues[] = array('property' => $property, 'value' => $value); |
|
7412 | 7412 | } |
7413 | 7413 | } |
7414 | 7414 | |
7415 | - $bean->id = $this->writer->updateRecord( $table, $updateValues, $bean->id ); |
|
7416 | - $bean->setMeta( 'changed', FALSE ); |
|
7415 | + $bean->id = $this->writer->updateRecord($table, $updateValues, $bean->id); |
|
7416 | + $bean->setMeta('changed', FALSE); |
|
7417 | 7417 | } |
7418 | - $bean->setMeta( 'tainted', FALSE ); |
|
7418 | + $bean->setMeta('tainted', FALSE); |
|
7419 | 7419 | } |
7420 | 7420 | |
7421 | 7421 | /** |
@@ -7427,12 +7427,12 @@ discard block |
||
7427 | 7427 | * |
7428 | 7428 | * @throws\Exception |
7429 | 7429 | */ |
7430 | - protected function handleException( \Exception $exception ) |
|
7430 | + protected function handleException(\Exception $exception) |
|
7431 | 7431 | { |
7432 | - if ( !$this->writer->sqlStateIn( $exception->getSQLState(), |
|
7432 | + if (!$this->writer->sqlStateIn($exception->getSQLState(), |
|
7433 | 7433 | array( |
7434 | 7434 | QueryWriter::C_SQLSTATE_NO_SUCH_TABLE, |
7435 | - QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN ) ) |
|
7435 | + QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN )) |
|
7436 | 7436 | ) { |
7437 | 7437 | throw $exception; |
7438 | 7438 | } |
@@ -7453,19 +7453,19 @@ discard block |
||
7453 | 7453 | * |
7454 | 7454 | * @return OODBBean |
7455 | 7455 | */ |
7456 | - public function dispense( $type, $number = 1, $alwaysReturnArray = FALSE ) |
|
7456 | + public function dispense($type, $number = 1, $alwaysReturnArray = FALSE) |
|
7457 | 7457 | { |
7458 | - $OODBBEAN = defined( 'REDBEAN_OODBBEAN_CLASS' ) ? REDBEAN_OODBBEAN_CLASS : '\RedBeanPHP\OODBBean'; |
|
7458 | + $OODBBEAN = defined('REDBEAN_OODBBEAN_CLASS') ? REDBEAN_OODBBEAN_CLASS : '\RedBeanPHP\OODBBean'; |
|
7459 | 7459 | $beans = array(); |
7460 | - for ( $i = 0; $i < $number; $i++ ) { |
|
7460 | + for ($i = 0; $i < $number; $i++) { |
|
7461 | 7461 | $bean = new $OODBBEAN; |
7462 | - $bean->initializeForDispense( $type, $this->oodb->getBeanHelper() ); |
|
7463 | - $this->check( $bean ); |
|
7464 | - $this->oodb->signal( 'dispense', $bean ); |
|
7462 | + $bean->initializeForDispense($type, $this->oodb->getBeanHelper()); |
|
7463 | + $this->check($bean); |
|
7464 | + $this->oodb->signal('dispense', $bean); |
|
7465 | 7465 | $beans[] = $bean; |
7466 | 7466 | } |
7467 | 7467 | |
7468 | - return ( count( $beans ) === 1 && !$alwaysReturnArray ) ? array_pop( $beans ) : $beans; |
|
7468 | + return (count($beans) === 1 && !$alwaysReturnArray) ? array_pop($beans) : $beans; |
|
7469 | 7469 | } |
7470 | 7470 | |
7471 | 7471 | /** |
@@ -7493,16 +7493,16 @@ discard block |
||
7493 | 7493 | * @return OODBBean |
7494 | 7494 | * |
7495 | 7495 | */ |
7496 | - public function load( $type, $id ) |
|
7496 | + public function load($type, $id) |
|
7497 | 7497 | { |
7498 | - $bean = $this->dispense( $type ); |
|
7499 | - if ( isset( $this->stash[$this->nesting][$id] ) ) { |
|
7498 | + $bean = $this->dispense($type); |
|
7499 | + if (isset($this->stash[$this->nesting][$id])) { |
|
7500 | 7500 | $row = $this->stash[$this->nesting][$id]; |
7501 | 7501 | } else { |
7502 | 7502 | try { |
7503 | - $rows = $this->writer->queryRecord( $type, array( 'id' => array( $id ) ) ); |
|
7504 | - } catch ( SQLException $exception ) { |
|
7505 | - if ( $this->writer->sqlStateIn( $exception->getSQLState(), |
|
7503 | + $rows = $this->writer->queryRecord($type, array('id' => array($id))); |
|
7504 | + } catch (SQLException $exception) { |
|
7505 | + if ($this->writer->sqlStateIn($exception->getSQLState(), |
|
7506 | 7506 | array( |
7507 | 7507 | QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN, |
7508 | 7508 | QueryWriter::C_SQLSTATE_NO_SUCH_TABLE ) |
@@ -7512,17 +7512,17 @@ discard block |
||
7512 | 7512 | |
7513 | 7513 | } |
7514 | 7514 | } |
7515 | - if ( empty( $rows ) ) { |
|
7515 | + if (empty($rows)) { |
|
7516 | 7516 | return $bean; |
7517 | 7517 | } |
7518 | - $row = array_pop( $rows ); |
|
7518 | + $row = array_pop($rows); |
|
7519 | 7519 | } |
7520 | - $bean->importRow( $row ); |
|
7520 | + $bean->importRow($row); |
|
7521 | 7521 | $this->nesting++; |
7522 | - $this->oodb->signal( 'open', $bean ); |
|
7522 | + $this->oodb->signal('open', $bean); |
|
7523 | 7523 | $this->nesting--; |
7524 | 7524 | |
7525 | - return $bean->setMeta( 'tainted', FALSE ); |
|
7525 | + return $bean->setMeta('tainted', FALSE); |
|
7526 | 7526 | } |
7527 | 7527 | } |
7528 | 7528 | } |
@@ -7571,7 +7571,7 @@ discard block |
||
7571 | 7571 | * |
7572 | 7572 | * @throws \Exception |
7573 | 7573 | */ |
7574 | - protected function handleException( \Exception $exception ) |
|
7574 | + protected function handleException(\Exception $exception) |
|
7575 | 7575 | { |
7576 | 7576 | throw $exception; |
7577 | 7577 | } |
@@ -7586,23 +7586,23 @@ discard block |
||
7586 | 7586 | * |
7587 | 7587 | * @return void |
7588 | 7588 | */ |
7589 | - protected function storeBean( OODBBean $bean ) |
|
7589 | + protected function storeBean(OODBBean $bean) |
|
7590 | 7590 | { |
7591 | - if ( $bean->getMeta( 'changed' ) ) { |
|
7591 | + if ($bean->getMeta('changed')) { |
|
7592 | 7592 | |
7593 | - list( $properties, $table ) = $bean->getPropertiesAndType(); |
|
7593 | + list($properties, $table) = $bean->getPropertiesAndType(); |
|
7594 | 7594 | $id = $properties['id']; |
7595 | 7595 | unset($properties['id']); |
7596 | 7596 | $updateValues = array(); |
7597 | 7597 | $k1 = 'property'; |
7598 | 7598 | $k2 = 'value'; |
7599 | - foreach( $properties as $key => $value ) { |
|
7600 | - $updateValues[] = array( $k1 => $key, $k2 => $value ); |
|
7599 | + foreach ($properties as $key => $value) { |
|
7600 | + $updateValues[] = array($k1 => $key, $k2 => $value); |
|
7601 | 7601 | } |
7602 | - $bean->id = $this->writer->updateRecord( $table, $updateValues, $id ); |
|
7603 | - $bean->setMeta( 'changed', FALSE ); |
|
7602 | + $bean->id = $this->writer->updateRecord($table, $updateValues, $id); |
|
7603 | + $bean->setMeta('changed', FALSE); |
|
7604 | 7604 | } |
7605 | - $bean->setMeta( 'tainted', FALSE ); |
|
7605 | + $bean->setMeta('tainted', FALSE); |
|
7606 | 7606 | } |
7607 | 7607 | |
7608 | 7608 | /** |
@@ -7619,24 +7619,24 @@ discard block |
||
7619 | 7619 | * |
7620 | 7620 | * @throws Security |
7621 | 7621 | */ |
7622 | - protected function processAdditions( $bean, $ownAdditions ) |
|
7622 | + protected function processAdditions($bean, $ownAdditions) |
|
7623 | 7623 | { |
7624 | - $beanType = $bean->getMeta( 'type' ); |
|
7624 | + $beanType = $bean->getMeta('type'); |
|
7625 | 7625 | |
7626 | 7626 | $cachedIndex = array(); |
7627 | - foreach ( $ownAdditions as $addition ) { |
|
7628 | - if ( $addition instanceof OODBBean ) { |
|
7627 | + foreach ($ownAdditions as $addition) { |
|
7628 | + if ($addition instanceof OODBBean) { |
|
7629 | 7629 | |
7630 | 7630 | $myFieldLink = $beanType . '_id'; |
7631 | - $alias = $bean->getMeta( 'sys.alias.' . $addition->getMeta( 'type' ) ); |
|
7632 | - if ( $alias ) $myFieldLink = $alias . '_id'; |
|
7631 | + $alias = $bean->getMeta('sys.alias.' . $addition->getMeta('type')); |
|
7632 | + if ($alias) $myFieldLink = $alias . '_id'; |
|
7633 | 7633 | |
7634 | 7634 | $addition->$myFieldLink = $bean->id; |
7635 | - $addition->setMeta( 'cast.' . $myFieldLink, 'id' ); |
|
7636 | - $this->store( $addition ); |
|
7635 | + $addition->setMeta('cast.' . $myFieldLink, 'id'); |
|
7636 | + $this->store($addition); |
|
7637 | 7637 | |
7638 | 7638 | } else { |
7639 | - throw new RedException( 'Array may only contain OODBBeans' ); |
|
7639 | + throw new RedException('Array may only contain OODBBeans'); |
|
7640 | 7640 | } |
7641 | 7641 | } |
7642 | 7642 | } |
@@ -7656,18 +7656,18 @@ discard block |
||
7656 | 7656 | * |
7657 | 7657 | * @return OODBBean |
7658 | 7658 | */ |
7659 | - public function dispense( $type, $number = 1, $alwaysReturnArray = FALSE ) |
|
7659 | + public function dispense($type, $number = 1, $alwaysReturnArray = FALSE) |
|
7660 | 7660 | { |
7661 | - $OODBBEAN = defined( 'REDBEAN_OODBBEAN_CLASS' ) ? REDBEAN_OODBBEAN_CLASS : '\RedBeanPHP\OODBBean'; |
|
7661 | + $OODBBEAN = defined('REDBEAN_OODBBEAN_CLASS') ? REDBEAN_OODBBEAN_CLASS : '\RedBeanPHP\OODBBean'; |
|
7662 | 7662 | $beans = array(); |
7663 | - for ( $i = 0; $i < $number; $i++ ) { |
|
7663 | + for ($i = 0; $i < $number; $i++) { |
|
7664 | 7664 | $bean = new $OODBBEAN; |
7665 | - $bean->initializeForDispense( $type, $this->oodb->getBeanHelper() ); |
|
7666 | - $this->oodb->signal( 'dispense', $bean ); |
|
7665 | + $bean->initializeForDispense($type, $this->oodb->getBeanHelper()); |
|
7666 | + $this->oodb->signal('dispense', $bean); |
|
7667 | 7667 | $beans[] = $bean; |
7668 | 7668 | } |
7669 | 7669 | |
7670 | - return ( count( $beans ) === 1 && !$alwaysReturnArray ) ? array_pop( $beans ) : $beans; |
|
7670 | + return (count($beans) === 1 && !$alwaysReturnArray) ? array_pop($beans) : $beans; |
|
7671 | 7671 | } |
7672 | 7672 | |
7673 | 7673 | /** |
@@ -7695,16 +7695,16 @@ discard block |
||
7695 | 7695 | * @return OODBBean |
7696 | 7696 | * |
7697 | 7697 | */ |
7698 | - public function load( $type, $id ) |
|
7698 | + public function load($type, $id) |
|
7699 | 7699 | { |
7700 | - $bean = $this->dispense( $type ); |
|
7701 | - if ( isset( $this->stash[$this->nesting][$id] ) ) { |
|
7700 | + $bean = $this->dispense($type); |
|
7701 | + if (isset($this->stash[$this->nesting][$id])) { |
|
7702 | 7702 | $row = $this->stash[$this->nesting][$id]; |
7703 | 7703 | } else { |
7704 | 7704 | try { |
7705 | - $rows = $this->writer->queryRecord( $type, array( 'id' => array( $id ) ) ); |
|
7706 | - } catch ( SQLException $exception ) { |
|
7707 | - if ( $this->writer->sqlStateIn( $exception->getSQLState(), |
|
7705 | + $rows = $this->writer->queryRecord($type, array('id' => array($id))); |
|
7706 | + } catch (SQLException $exception) { |
|
7707 | + if ($this->writer->sqlStateIn($exception->getSQLState(), |
|
7708 | 7708 | array( |
7709 | 7709 | QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN, |
7710 | 7710 | QueryWriter::C_SQLSTATE_NO_SUCH_TABLE ) |
@@ -7713,17 +7713,17 @@ discard block |
||
7713 | 7713 | throw $exception; //only throw if frozen |
7714 | 7714 | } |
7715 | 7715 | } |
7716 | - if ( empty( $rows ) ) { |
|
7716 | + if (empty($rows)) { |
|
7717 | 7717 | return $bean; |
7718 | 7718 | } |
7719 | - $row = array_pop( $rows ); |
|
7719 | + $row = array_pop($rows); |
|
7720 | 7720 | } |
7721 | - $bean->importRow( $row ); |
|
7721 | + $bean->importRow($row); |
|
7722 | 7722 | $this->nesting++; |
7723 | - $this->oodb->signal( 'open', $bean ); |
|
7723 | + $this->oodb->signal('open', $bean); |
|
7724 | 7724 | $this->nesting--; |
7725 | 7725 | |
7726 | - return $bean->setMeta( 'tainted', FALSE ); |
|
7726 | + return $bean->setMeta('tainted', FALSE); |
|
7727 | 7727 | } |
7728 | 7728 | } |
7729 | 7729 | } |
@@ -7830,13 +7830,13 @@ discard block |
||
7830 | 7830 | * |
7831 | 7831 | * @throws Security |
7832 | 7832 | */ |
7833 | - protected function unboxIfNeeded( $bean ) |
|
7833 | + protected function unboxIfNeeded($bean) |
|
7834 | 7834 | { |
7835 | - if ( $bean instanceof SimpleModel ) { |
|
7835 | + if ($bean instanceof SimpleModel) { |
|
7836 | 7836 | $bean = $bean->unbox(); |
7837 | 7837 | } |
7838 | - if ( !( $bean instanceof OODBBean ) ) { |
|
7839 | - throw new RedException( 'OODB Store requires a bean, got: ' . gettype( $bean ) ); |
|
7838 | + if (!($bean instanceof OODBBean)) { |
|
7839 | + throw new RedException('OODB Store requires a bean, got: ' . gettype($bean)); |
|
7840 | 7840 | } |
7841 | 7841 | |
7842 | 7842 | return $bean; |
@@ -7848,13 +7848,13 @@ discard block |
||
7848 | 7848 | * @param QueryWriter $writer writer |
7849 | 7849 | * @param array|boolean $frozen mode of operation: TRUE (frozen), FALSE (default, fluid) or ARRAY (chilled) |
7850 | 7850 | */ |
7851 | - public function __construct( QueryWriter $writer, $frozen = FALSE ) |
|
7851 | + public function __construct(QueryWriter $writer, $frozen = FALSE) |
|
7852 | 7852 | { |
7853 | - if ( $writer instanceof QueryWriter ) { |
|
7853 | + if ($writer instanceof QueryWriter) { |
|
7854 | 7854 | $this->writer = $writer; |
7855 | 7855 | } |
7856 | 7856 | |
7857 | - $this->freeze( $frozen ); |
|
7857 | + $this->freeze($frozen); |
|
7858 | 7858 | } |
7859 | 7859 | |
7860 | 7860 | /** |
@@ -7870,32 +7870,32 @@ discard block |
||
7870 | 7870 | * |
7871 | 7871 | * @return void |
7872 | 7872 | */ |
7873 | - public function freeze( $toggle ) |
|
7873 | + public function freeze($toggle) |
|
7874 | 7874 | { |
7875 | - if ( is_array( $toggle ) ) { |
|
7875 | + if (is_array($toggle)) { |
|
7876 | 7876 | $this->chillList = $toggle; |
7877 | 7877 | $this->isFrozen = FALSE; |
7878 | 7878 | } else { |
7879 | 7879 | $this->isFrozen = (boolean) $toggle; |
7880 | 7880 | } |
7881 | 7881 | |
7882 | - if ( $this->isFrozen ) { |
|
7883 | - if ( !$this->frozenRepository ) { |
|
7884 | - $this->frozenRepository = new FrozenRepo( $this, $this->writer ); |
|
7882 | + if ($this->isFrozen) { |
|
7883 | + if (!$this->frozenRepository) { |
|
7884 | + $this->frozenRepository = new FrozenRepo($this, $this->writer); |
|
7885 | 7885 | } |
7886 | 7886 | |
7887 | 7887 | $this->repository = $this->frozenRepository; |
7888 | 7888 | |
7889 | 7889 | } else { |
7890 | - if ( !$this->fluidRepository ) { |
|
7891 | - $this->fluidRepository = new FluidRepo( $this, $this->writer ); |
|
7890 | + if (!$this->fluidRepository) { |
|
7891 | + $this->fluidRepository = new FluidRepo($this, $this->writer); |
|
7892 | 7892 | } |
7893 | 7893 | |
7894 | 7894 | $this->repository = $this->fluidRepository; |
7895 | 7895 | } |
7896 | 7896 | |
7897 | - if ( count( self::$sqlFilters ) ) { |
|
7898 | - AQueryWriter::setSQLFilters( self::$sqlFilters, ( !$this->isFrozen ) ); |
|
7897 | + if (count(self::$sqlFilters)) { |
|
7898 | + AQueryWriter::setSQLFilters(self::$sqlFilters, (!$this->isFrozen)); |
|
7899 | 7899 | } |
7900 | 7900 | |
7901 | 7901 | } |
@@ -7925,9 +7925,9 @@ discard block |
||
7925 | 7925 | * |
7926 | 7926 | * @return boolean |
7927 | 7927 | */ |
7928 | - public function isChilled( $type ) |
|
7928 | + public function isChilled($type) |
|
7929 | 7929 | { |
7930 | - return (boolean) ( in_array( $type, $this->chillList ) ); |
|
7930 | + return (boolean) (in_array($type, $this->chillList)); |
|
7931 | 7931 | } |
7932 | 7932 | |
7933 | 7933 | /** |
@@ -7945,14 +7945,14 @@ discard block |
||
7945 | 7945 | * |
7946 | 7946 | * @return OODBBean |
7947 | 7947 | */ |
7948 | - public function dispense( $type, $number = 1, $alwaysReturnArray = FALSE ) |
|
7948 | + public function dispense($type, $number = 1, $alwaysReturnArray = FALSE) |
|
7949 | 7949 | { |
7950 | - if ( $number < 1 ) { |
|
7951 | - if ( $alwaysReturnArray ) return array(); |
|
7950 | + if ($number < 1) { |
|
7951 | + if ($alwaysReturnArray) return array(); |
|
7952 | 7952 | return NULL; |
7953 | 7953 | } |
7954 | 7954 | |
7955 | - return $this->repository->dispense( $type, $number, $alwaysReturnArray ); |
|
7955 | + return $this->repository->dispense($type, $number, $alwaysReturnArray); |
|
7956 | 7956 | } |
7957 | 7957 | |
7958 | 7958 | /** |
@@ -7963,7 +7963,7 @@ discard block |
||
7963 | 7963 | * |
7964 | 7964 | * @return void |
7965 | 7965 | */ |
7966 | - public function setBeanHelper( BeanHelper $beanhelper ) |
|
7966 | + public function setBeanHelper(BeanHelper $beanhelper) |
|
7967 | 7967 | { |
7968 | 7968 | $this->beanhelper = $beanhelper; |
7969 | 7969 | } |
@@ -7990,9 +7990,9 @@ discard block |
||
7990 | 7990 | * |
7991 | 7991 | * @throws Security $exception |
7992 | 7992 | */ |
7993 | - public function check( OODBBean $bean ) |
|
7993 | + public function check(OODBBean $bean) |
|
7994 | 7994 | { |
7995 | - $this->repository->check( $bean ); |
|
7995 | + $this->repository->check($bean); |
|
7996 | 7996 | } |
7997 | 7997 | |
7998 | 7998 | /** |
@@ -8021,9 +8021,9 @@ discard block |
||
8021 | 8021 | * |
8022 | 8022 | * @throws SQL |
8023 | 8023 | */ |
8024 | - public function find( $type, $conditions = array(), $sql = NULL, $bindings = array() ) |
|
8024 | + public function find($type, $conditions = array(), $sql = NULL, $bindings = array()) |
|
8025 | 8025 | { |
8026 | - return $this->repository->find( $type, $conditions, $sql, $bindings ); |
|
8026 | + return $this->repository->find($type, $conditions, $sql, $bindings); |
|
8027 | 8027 | } |
8028 | 8028 | |
8029 | 8029 | /** |
@@ -8037,9 +8037,9 @@ discard block |
||
8037 | 8037 | * |
8038 | 8038 | * @throws SQL |
8039 | 8039 | */ |
8040 | - public function findCollection( $type, $sql = NULL, $bindings = array() ) |
|
8040 | + public function findCollection($type, $sql = NULL, $bindings = array()) |
|
8041 | 8041 | { |
8042 | - return $this->repository->findCollection( $type, $sql, $bindings ); |
|
8042 | + return $this->repository->findCollection($type, $sql, $bindings); |
|
8043 | 8043 | } |
8044 | 8044 | |
8045 | 8045 | /** |
@@ -8052,9 +8052,9 @@ discard block |
||
8052 | 8052 | * |
8053 | 8053 | * @return boolean |
8054 | 8054 | */ |
8055 | - public function tableExists( $table ) |
|
8055 | + public function tableExists($table) |
|
8056 | 8056 | { |
8057 | - return $this->repository->tableExists( $table ); |
|
8057 | + return $this->repository->tableExists($table); |
|
8058 | 8058 | } |
8059 | 8059 | |
8060 | 8060 | /** |
@@ -8079,10 +8079,10 @@ discard block |
||
8079 | 8079 | * |
8080 | 8080 | * @throws Security |
8081 | 8081 | */ |
8082 | - public function store( $bean ) |
|
8082 | + public function store($bean) |
|
8083 | 8083 | { |
8084 | - $bean = $this->unboxIfNeeded( $bean ); |
|
8085 | - return $this->repository->store( $bean ); |
|
8084 | + $bean = $this->unboxIfNeeded($bean); |
|
8085 | + return $this->repository->store($bean); |
|
8086 | 8086 | } |
8087 | 8087 | |
8088 | 8088 | /** |
@@ -8110,9 +8110,9 @@ discard block |
||
8110 | 8110 | * @return OODBBean |
8111 | 8111 | * |
8112 | 8112 | */ |
8113 | - public function load( $type, $id ) |
|
8113 | + public function load($type, $id) |
|
8114 | 8114 | { |
8115 | - return $this->repository->load( $type, $id ); |
|
8115 | + return $this->repository->load($type, $id); |
|
8116 | 8116 | } |
8117 | 8117 | |
8118 | 8118 | /** |
@@ -8126,10 +8126,10 @@ discard block |
||
8126 | 8126 | * |
8127 | 8127 | * @throws Security |
8128 | 8128 | */ |
8129 | - public function trash( $bean ) |
|
8129 | + public function trash($bean) |
|
8130 | 8130 | { |
8131 | - $bean = $this->unboxIfNeeded( $bean ); |
|
8132 | - return $this->repository->trash( $bean ); |
|
8131 | + $bean = $this->unboxIfNeeded($bean); |
|
8132 | + return $this->repository->trash($bean); |
|
8133 | 8133 | } |
8134 | 8134 | |
8135 | 8135 | /** |
@@ -8146,9 +8146,9 @@ discard block |
||
8146 | 8146 | * |
8147 | 8147 | * @return array |
8148 | 8148 | */ |
8149 | - public function batch( $type, $ids ) |
|
8149 | + public function batch($type, $ids) |
|
8150 | 8150 | { |
8151 | - return $this->repository->batch( $type, $ids ); |
|
8151 | + return $this->repository->batch($type, $ids); |
|
8152 | 8152 | } |
8153 | 8153 | |
8154 | 8154 | /** |
@@ -8162,9 +8162,9 @@ discard block |
||
8162 | 8162 | * |
8163 | 8163 | * @return array |
8164 | 8164 | */ |
8165 | - public function convertToBeans( $type, $rows ) |
|
8165 | + public function convertToBeans($type, $rows) |
|
8166 | 8166 | { |
8167 | - return $this->repository->convertToBeans( $type, $rows ); |
|
8167 | + return $this->repository->convertToBeans($type, $rows); |
|
8168 | 8168 | } |
8169 | 8169 | |
8170 | 8170 | /** |
@@ -8180,9 +8180,9 @@ discard block |
||
8180 | 8180 | * |
8181 | 8181 | * @throws SQL |
8182 | 8182 | */ |
8183 | - public function count( $type, $addSQL = '', $bindings = array() ) |
|
8183 | + public function count($type, $addSQL = '', $bindings = array()) |
|
8184 | 8184 | { |
8185 | - return $this->repository->count( $type, $addSQL, $bindings ); |
|
8185 | + return $this->repository->count($type, $addSQL, $bindings); |
|
8186 | 8186 | } |
8187 | 8187 | |
8188 | 8188 | /** |
@@ -8194,9 +8194,9 @@ discard block |
||
8194 | 8194 | * |
8195 | 8195 | * @throws SQL |
8196 | 8196 | */ |
8197 | - public function wipe( $type ) |
|
8197 | + public function wipe($type) |
|
8198 | 8198 | { |
8199 | - return $this->repository->wipe( $type ); |
|
8199 | + return $this->repository->wipe($type); |
|
8200 | 8200 | } |
8201 | 8201 | |
8202 | 8202 | /** |
@@ -8210,8 +8210,8 @@ discard block |
||
8210 | 8210 | */ |
8211 | 8211 | public function getAssociationManager() |
8212 | 8212 | { |
8213 | - if ( !isset( $this->assocManager ) ) { |
|
8214 | - throw new RedException( 'No association manager available.' ); |
|
8213 | + if (!isset($this->assocManager)) { |
|
8214 | + throw new RedException('No association manager available.'); |
|
8215 | 8215 | } |
8216 | 8216 | |
8217 | 8217 | return $this->assocManager; |
@@ -8226,7 +8226,7 @@ discard block |
||
8226 | 8226 | * |
8227 | 8227 | * @return void |
8228 | 8228 | */ |
8229 | - public function setAssociationManager( AssociationManager $assocManager ) |
|
8229 | + public function setAssociationManager(AssociationManager $assocManager) |
|
8230 | 8230 | { |
8231 | 8231 | $this->assocManager = $assocManager; |
8232 | 8232 | } |
@@ -8253,25 +8253,25 @@ discard block |
||
8253 | 8253 | * @param string $field |
8254 | 8254 | * @param string $function |
8255 | 8255 | */ |
8256 | - public function bindFunc( $mode, $field, $function ) |
|
8256 | + public function bindFunc($mode, $field, $function) |
|
8257 | 8257 | { |
8258 | - list( $type, $property ) = explode( '.', $field ); |
|
8258 | + list($type, $property) = explode('.', $field); |
|
8259 | 8259 | $mode = ($mode === 'write') ? QueryWriter::C_SQLFILTER_WRITE : QueryWriter::C_SQLFILTER_READ; |
8260 | 8260 | |
8261 | - if ( !isset( self::$sqlFilters[$mode] ) ) self::$sqlFilters[$mode] = array(); |
|
8262 | - if ( !isset( self::$sqlFilters[$mode][$type] ) ) self::$sqlFilters[$mode][$type] = array(); |
|
8261 | + if (!isset(self::$sqlFilters[$mode])) self::$sqlFilters[$mode] = array(); |
|
8262 | + if (!isset(self::$sqlFilters[$mode][$type])) self::$sqlFilters[$mode][$type] = array(); |
|
8263 | 8263 | |
8264 | - if ( is_null( $function ) ) { |
|
8265 | - unset( self::$sqlFilters[$mode][$type][$property] ); |
|
8264 | + if (is_null($function)) { |
|
8265 | + unset(self::$sqlFilters[$mode][$type][$property]); |
|
8266 | 8266 | } else { |
8267 | 8267 | if ($mode === QueryWriter::C_SQLFILTER_WRITE) { |
8268 | - self::$sqlFilters[$mode][$type][$property] = $function.'(?)'; |
|
8268 | + self::$sqlFilters[$mode][$type][$property] = $function . '(?)'; |
|
8269 | 8269 | } else { |
8270 | - self::$sqlFilters[$mode][$type][$property] = $function."($field)"; |
|
8270 | + self::$sqlFilters[$mode][$type][$property] = $function . "($field)"; |
|
8271 | 8271 | } |
8272 | 8272 | } |
8273 | 8273 | |
8274 | - AQueryWriter::setSQLFilters( self::$sqlFilters, ( !$this->isFrozen ) ); |
|
8274 | + AQueryWriter::setSQLFilters(self::$sqlFilters, (!$this->isFrozen)); |
|
8275 | 8275 | } |
8276 | 8276 | } |
8277 | 8277 | } |
@@ -8333,7 +8333,7 @@ discard block |
||
8333 | 8333 | * |
8334 | 8334 | * @return ToolBox |
8335 | 8335 | */ |
8336 | - public function __construct( OODB $oodb, Adapter $adapter, QueryWriter $writer ) |
|
8336 | + public function __construct(OODB $oodb, Adapter $adapter, QueryWriter $writer) |
|
8337 | 8337 | { |
8338 | 8338 | $this->oodb = $oodb; |
8339 | 8339 | $this->adapter = $adapter; |
@@ -8422,7 +8422,7 @@ discard block |
||
8422 | 8422 | * |
8423 | 8423 | * @param ToolBox $toolbox |
8424 | 8424 | */ |
8425 | - public function __construct( ToolBox $toolbox ) |
|
8425 | + public function __construct(ToolBox $toolbox) |
|
8426 | 8426 | { |
8427 | 8427 | $this->toolbox = $toolbox; |
8428 | 8428 | $this->redbean = $toolbox->getRedBean(); |
@@ -8443,15 +8443,15 @@ discard block |
||
8443 | 8443 | * |
8444 | 8444 | * @throws Security |
8445 | 8445 | */ |
8446 | - public function find( $type, $sql = NULL, $bindings = array() ) |
|
8446 | + public function find($type, $sql = NULL, $bindings = array()) |
|
8447 | 8447 | { |
8448 | - if ( !is_array( $bindings ) ) { |
|
8448 | + if (!is_array($bindings)) { |
|
8449 | 8449 | throw new RedException( |
8450 | - 'Expected array, ' . gettype( $bindings ) . ' given.' |
|
8450 | + 'Expected array, ' . gettype($bindings) . ' given.' |
|
8451 | 8451 | ); |
8452 | 8452 | } |
8453 | 8453 | |
8454 | - return $this->redbean->find( $type, array(), $sql, $bindings ); |
|
8454 | + return $this->redbean->find($type, array(), $sql, $bindings); |
|
8455 | 8455 | } |
8456 | 8456 | |
8457 | 8457 | /** |
@@ -8465,10 +8465,10 @@ discard block |
||
8465 | 8465 | * |
8466 | 8466 | * @return array |
8467 | 8467 | */ |
8468 | - public function findAndExport( $type, $sql = NULL, $bindings = array() ) |
|
8468 | + public function findAndExport($type, $sql = NULL, $bindings = array()) |
|
8469 | 8469 | { |
8470 | 8470 | $arr = array(); |
8471 | - foreach ( $this->find( $type, $sql, $bindings ) as $key => $item ) { |
|
8471 | + foreach ($this->find($type, $sql, $bindings) as $key => $item) { |
|
8472 | 8472 | $arr[] = $item->export(); |
8473 | 8473 | } |
8474 | 8474 | |
@@ -8487,17 +8487,17 @@ discard block |
||
8487 | 8487 | * |
8488 | 8488 | * @return OODBBean |
8489 | 8489 | */ |
8490 | - public function findOne( $type, $sql = NULL, $bindings = array() ) |
|
8490 | + public function findOne($type, $sql = NULL, $bindings = array()) |
|
8491 | 8491 | { |
8492 | - $sql = $this->toolbox->getWriter()->glueLimitOne( $sql ); |
|
8492 | + $sql = $this->toolbox->getWriter()->glueLimitOne($sql); |
|
8493 | 8493 | |
8494 | - $items = $this->find( $type, $sql, $bindings ); |
|
8494 | + $items = $this->find($type, $sql, $bindings); |
|
8495 | 8495 | |
8496 | - if ( empty($items) ) { |
|
8496 | + if (empty($items)) { |
|
8497 | 8497 | return NULL; |
8498 | 8498 | } |
8499 | 8499 | |
8500 | - return reset( $items ); |
|
8500 | + return reset($items); |
|
8501 | 8501 | } |
8502 | 8502 | |
8503 | 8503 | /** |
@@ -8512,15 +8512,15 @@ discard block |
||
8512 | 8512 | * |
8513 | 8513 | * @return OODBBean |
8514 | 8514 | */ |
8515 | - public function findLast( $type, $sql = NULL, $bindings = array() ) |
|
8515 | + public function findLast($type, $sql = NULL, $bindings = array()) |
|
8516 | 8516 | { |
8517 | - $items = $this->find( $type, $sql, $bindings ); |
|
8517 | + $items = $this->find($type, $sql, $bindings); |
|
8518 | 8518 | |
8519 | - if ( empty($items) ) { |
|
8519 | + if (empty($items)) { |
|
8520 | 8520 | return NULL; |
8521 | 8521 | } |
8522 | 8522 | |
8523 | - return end( $items ); |
|
8523 | + return end($items); |
|
8524 | 8524 | } |
8525 | 8525 | |
8526 | 8526 | /** |
@@ -8535,12 +8535,12 @@ discard block |
||
8535 | 8535 | * |
8536 | 8536 | * @return array |
8537 | 8537 | */ |
8538 | - public function findOrDispense( $type, $sql = NULL, $bindings = array() ) |
|
8538 | + public function findOrDispense($type, $sql = NULL, $bindings = array()) |
|
8539 | 8539 | { |
8540 | - $foundBeans = $this->find( $type, $sql, $bindings ); |
|
8540 | + $foundBeans = $this->find($type, $sql, $bindings); |
|
8541 | 8541 | |
8542 | - if ( empty( $foundBeans ) ) { |
|
8543 | - return array( $this->redbean->dispense( $type ) ); |
|
8542 | + if (empty($foundBeans)) { |
|
8543 | + return array($this->redbean->dispense($type)); |
|
8544 | 8544 | } else { |
8545 | 8545 | return $foundBeans; |
8546 | 8546 | } |
@@ -8558,9 +8558,9 @@ discard block |
||
8558 | 8558 | * |
8559 | 8559 | * @return BeanCollection |
8560 | 8560 | */ |
8561 | - public function findCollection( $type, $sql, $bindings = array() ) |
|
8561 | + public function findCollection($type, $sql, $bindings = array()) |
|
8562 | 8562 | { |
8563 | - return $this->redbean->findCollection( $type, $sql, $bindings ); |
|
8563 | + return $this->redbean->findCollection($type, $sql, $bindings); |
|
8564 | 8564 | } |
8565 | 8565 | |
8566 | 8566 | /** |
@@ -8580,17 +8580,17 @@ discard block |
||
8580 | 8580 | * |
8581 | 8581 | * @return OODBBean |
8582 | 8582 | */ |
8583 | - public function findOrCreate( $type, $like = array() ) |
|
8583 | + public function findOrCreate($type, $like = array()) |
|
8584 | 8584 | { |
8585 | - $beans = $this->findLike( $type, $like ); |
|
8586 | - if ( count( $beans ) ) { |
|
8587 | - $bean = reset( $beans ); |
|
8585 | + $beans = $this->findLike($type, $like); |
|
8586 | + if (count($beans)) { |
|
8587 | + $bean = reset($beans); |
|
8588 | 8588 | return $bean; |
8589 | 8589 | } |
8590 | 8590 | |
8591 | - $bean = $this->redbean->dispense( $type ); |
|
8592 | - $bean->import( $like ); |
|
8593 | - $this->redbean->store( $bean ); |
|
8591 | + $bean = $this->redbean->dispense($type); |
|
8592 | + $bean->import($like); |
|
8593 | + $this->redbean->store($bean); |
|
8594 | 8594 | return $bean; |
8595 | 8595 | } |
8596 | 8596 | |
@@ -8615,15 +8615,15 @@ discard block |
||
8615 | 8615 | * |
8616 | 8616 | * @return array |
8617 | 8617 | */ |
8618 | - public function findLike( $type, $conditions = array(), $sql = '' ) |
|
8618 | + public function findLike($type, $conditions = array(), $sql = '') |
|
8619 | 8619 | { |
8620 | - if ( count( $conditions ) > 0 ) { |
|
8621 | - foreach( $conditions as $key => $condition ) { |
|
8622 | - if ( !count( $condition ) ) unset( $conditions[$key] ); |
|
8620 | + if (count($conditions) > 0) { |
|
8621 | + foreach ($conditions as $key => $condition) { |
|
8622 | + if (!count($condition)) unset($conditions[$key]); |
|
8623 | 8623 | } |
8624 | 8624 | } |
8625 | 8625 | |
8626 | - return $this->redbean->find( $type, $conditions, $sql ); |
|
8626 | + return $this->redbean->find($type, $conditions, $sql); |
|
8627 | 8627 | } |
8628 | 8628 | |
8629 | 8629 | /** |
@@ -8692,67 +8692,67 @@ discard block |
||
8692 | 8692 | * |
8693 | 8693 | * @return array |
8694 | 8694 | */ |
8695 | - public function findMulti( $types, $sql, $bindings = array(), $remappings = array(), $queryTemplate = ' %s.%s AS %s__%s' ) |
|
8695 | + public function findMulti($types, $sql, $bindings = array(), $remappings = array(), $queryTemplate = ' %s.%s AS %s__%s') |
|
8696 | 8696 | { |
8697 | - if ( !is_array( $types ) ) $types = explode( ',', $types ); |
|
8698 | - if ( !is_array( $sql ) ) { |
|
8697 | + if (!is_array($types)) $types = explode(',', $types); |
|
8698 | + if (!is_array($sql)) { |
|
8699 | 8699 | $writer = $this->toolbox->getWriter(); |
8700 | 8700 | $adapter = $this->toolbox->getDatabaseAdapter(); |
8701 | 8701 | |
8702 | 8702 | //Repair the query, replace book.* with book.id AS book_id etc.. |
8703 | - foreach( $types as $type ) { |
|
8703 | + foreach ($types as $type) { |
|
8704 | 8704 | $pattern = " {$type}.*"; |
8705 | - if ( strpos( $sql, $pattern ) !== FALSE ) { |
|
8705 | + if (strpos($sql, $pattern) !== FALSE) { |
|
8706 | 8706 | $newSelectorArray = array(); |
8707 | - $columns = $writer->getColumns( $type ); |
|
8708 | - foreach( $columns as $column => $definition ) { |
|
8709 | - $newSelectorArray[] = sprintf( $queryTemplate, $type, $column, $type, $column ); |
|
8707 | + $columns = $writer->getColumns($type); |
|
8708 | + foreach ($columns as $column => $definition) { |
|
8709 | + $newSelectorArray[] = sprintf($queryTemplate, $type, $column, $type, $column); |
|
8710 | 8710 | } |
8711 | - $newSelector = implode( ',', $newSelectorArray ); |
|
8712 | - $sql = str_replace( $pattern, $newSelector, $sql ); |
|
8711 | + $newSelector = implode(',', $newSelectorArray); |
|
8712 | + $sql = str_replace($pattern, $newSelector, $sql); |
|
8713 | 8713 | } |
8714 | 8714 | } |
8715 | 8715 | |
8716 | - $rows = $adapter->get( $sql, $bindings ); |
|
8716 | + $rows = $adapter->get($sql, $bindings); |
|
8717 | 8717 | } else { |
8718 | 8718 | $rows = $sql; |
8719 | 8719 | } |
8720 | 8720 | |
8721 | 8721 | //Gather the bean data from the query results using the prefix |
8722 | 8722 | $wannaBeans = array(); |
8723 | - foreach( $types as $type ) { |
|
8723 | + foreach ($types as $type) { |
|
8724 | 8724 | $wannaBeans[$type] = array(); |
8725 | 8725 | $prefix = "{$type}__"; |
8726 | - foreach( $rows as $rowkey=>$row ) { |
|
8726 | + foreach ($rows as $rowkey=>$row) { |
|
8727 | 8727 | $wannaBean = array(); |
8728 | - foreach( $row as $cell => $value ) { |
|
8729 | - if ( strpos( $cell, $prefix ) === 0 ) { |
|
8730 | - $property = substr( $cell, strlen( $prefix ) ); |
|
8731 | - unset( $rows[$rowkey][$cell] ); |
|
8728 | + foreach ($row as $cell => $value) { |
|
8729 | + if (strpos($cell, $prefix) === 0) { |
|
8730 | + $property = substr($cell, strlen($prefix)); |
|
8731 | + unset($rows[$rowkey][$cell]); |
|
8732 | 8732 | $wannaBean[$property] = $value; |
8733 | 8733 | } |
8734 | 8734 | } |
8735 | - if ( !isset( $wannaBean['id'] ) ) continue; |
|
8736 | - if ( is_null( $wannaBean['id'] ) ) continue; |
|
8735 | + if (!isset($wannaBean['id'])) continue; |
|
8736 | + if (is_null($wannaBean['id'])) continue; |
|
8737 | 8737 | $wannaBeans[$type][$wannaBean['id']] = $wannaBean; |
8738 | 8738 | } |
8739 | 8739 | } |
8740 | 8740 | |
8741 | 8741 | //Turn the rows into beans |
8742 | 8742 | $beans = array(); |
8743 | - foreach( $wannaBeans as $type => $wannabees ) { |
|
8744 | - $beans[$type] = $this->redbean->convertToBeans( $type, $wannabees ); |
|
8743 | + foreach ($wannaBeans as $type => $wannabees) { |
|
8744 | + $beans[$type] = $this->redbean->convertToBeans($type, $wannabees); |
|
8745 | 8745 | } |
8746 | 8746 | |
8747 | 8747 | //Apply additional re-mappings |
8748 | - foreach($remappings as $remapping) { |
|
8748 | + foreach ($remappings as $remapping) { |
|
8749 | 8749 | $a = $remapping['a']; |
8750 | 8750 | $b = $remapping['b']; |
8751 | 8751 | $matcher = $remapping['matcher']; |
8752 | 8752 | $do = $remapping['do']; |
8753 | - foreach( $beans[$a] as $bean ) { |
|
8754 | - foreach( $beans[$b] as $putBean ) { |
|
8755 | - if ( $matcher( $bean, $putBean, $beans ) ) $do( $bean, $putBean, $beans, $remapping ); |
|
8753 | + foreach ($beans[$a] as $bean) { |
|
8754 | + foreach ($beans[$b] as $putBean) { |
|
8755 | + if ($matcher($bean, $putBean, $beans)) $do($bean, $putBean, $beans, $remapping); |
|
8756 | 8756 | } |
8757 | 8757 | } |
8758 | 8758 | } |
@@ -8812,9 +8812,9 @@ discard block |
||
8812 | 8812 | * |
8813 | 8813 | * @throws\Exception |
8814 | 8814 | */ |
8815 | - private function handleException(\Exception $exception ) |
|
8815 | + private function handleException(\Exception $exception) |
|
8816 | 8816 | { |
8817 | - if ( $this->oodb->isFrozen() || !$this->writer->sqlStateIn( $exception->getSQLState(), |
|
8817 | + if ($this->oodb->isFrozen() || !$this->writer->sqlStateIn($exception->getSQLState(), |
|
8818 | 8818 | array( |
8819 | 8819 | QueryWriter::C_SQLSTATE_NO_SUCH_TABLE, |
8820 | 8820 | QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN ) |
@@ -8839,14 +8839,14 @@ discard block |
||
8839 | 8839 | * @throws Security |
8840 | 8840 | * @throws SQL |
8841 | 8841 | */ |
8842 | - private function relatedRows( $bean, $type, $sql = '', $bindings = array() ) |
|
8842 | + private function relatedRows($bean, $type, $sql = '', $bindings = array()) |
|
8843 | 8843 | { |
8844 | - $ids = array( $bean->id ); |
|
8845 | - $sourceType = $bean->getMeta( 'type' ); |
|
8844 | + $ids = array($bean->id); |
|
8845 | + $sourceType = $bean->getMeta('type'); |
|
8846 | 8846 | try { |
8847 | - return $this->writer->queryRecordRelated( $sourceType, $type, $ids, $sql, $bindings ); |
|
8848 | - } catch ( SQLException $exception ) { |
|
8849 | - $this->handleException( $exception ); |
|
8847 | + return $this->writer->queryRecordRelated($sourceType, $type, $ids, $sql, $bindings); |
|
8848 | + } catch (SQLException $exception) { |
|
8849 | + $this->handleException($exception); |
|
8850 | 8850 | return array(); |
8851 | 8851 | } |
8852 | 8852 | } |
@@ -8865,34 +8865,34 @@ discard block |
||
8865 | 8865 | * |
8866 | 8866 | * @return mixed |
8867 | 8867 | */ |
8868 | - protected function associateBeans( OODBBean $bean1, OODBBean $bean2, OODBBean $bean ) |
|
8868 | + protected function associateBeans(OODBBean $bean1, OODBBean $bean2, OODBBean $bean) |
|
8869 | 8869 | { |
8870 | - $type = $bean->getMeta( 'type' ); |
|
8871 | - $property1 = $bean1->getMeta( 'type' ) . '_id'; |
|
8872 | - $property2 = $bean2->getMeta( 'type' ) . '_id'; |
|
8870 | + $type = $bean->getMeta('type'); |
|
8871 | + $property1 = $bean1->getMeta('type') . '_id'; |
|
8872 | + $property2 = $bean2->getMeta('type') . '_id'; |
|
8873 | 8873 | |
8874 | - if ( $property1 == $property2 ) { |
|
8875 | - $property2 = $bean2->getMeta( 'type' ) . '2_id'; |
|
8874 | + if ($property1 == $property2) { |
|
8875 | + $property2 = $bean2->getMeta('type') . '2_id'; |
|
8876 | 8876 | } |
8877 | 8877 | |
8878 | - $this->oodb->store( $bean1 ); |
|
8879 | - $this->oodb->store( $bean2 ); |
|
8878 | + $this->oodb->store($bean1); |
|
8879 | + $this->oodb->store($bean2); |
|
8880 | 8880 | |
8881 | - $bean->setMeta( "cast.$property1", "id" ); |
|
8882 | - $bean->setMeta( "cast.$property2", "id" ); |
|
8883 | - $bean->setMeta( 'sys.buildcommand.unique', array( $property1, $property2 ) ); |
|
8881 | + $bean->setMeta("cast.$property1", "id"); |
|
8882 | + $bean->setMeta("cast.$property2", "id"); |
|
8883 | + $bean->setMeta('sys.buildcommand.unique', array($property1, $property2)); |
|
8884 | 8884 | |
8885 | 8885 | $bean->$property1 = $bean1->id; |
8886 | 8886 | $bean->$property2 = $bean2->id; |
8887 | 8887 | |
8888 | - $results = array(); |
|
8888 | + $results = array(); |
|
8889 | 8889 | |
8890 | 8890 | try { |
8891 | - $id = $this->oodb->store( $bean ); |
|
8891 | + $id = $this->oodb->store($bean); |
|
8892 | 8892 | $results[] = $id; |
8893 | - } catch ( SQLException $exception ) { |
|
8894 | - if ( !$this->writer->sqlStateIn( $exception->getSQLState(), |
|
8895 | - array( QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION ) ) |
|
8893 | + } catch (SQLException $exception) { |
|
8894 | + if (!$this->writer->sqlStateIn($exception->getSQLState(), |
|
8895 | + array(QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION)) |
|
8896 | 8896 | ) { |
8897 | 8897 | throw $exception; |
8898 | 8898 | } |
@@ -8906,7 +8906,7 @@ discard block |
||
8906 | 8906 | * |
8907 | 8907 | * @param ToolBox $tools toolbox |
8908 | 8908 | */ |
8909 | - public function __construct( ToolBox $tools ) |
|
8909 | + public function __construct(ToolBox $tools) |
|
8910 | 8910 | { |
8911 | 8911 | $this->oodb = $tools->getRedBean(); |
8912 | 8912 | $this->adapter = $tools->getDatabaseAdapter(); |
@@ -8925,9 +8925,9 @@ discard block |
||
8925 | 8925 | * |
8926 | 8926 | * @return string |
8927 | 8927 | */ |
8928 | - public function getTable( $types ) |
|
8928 | + public function getTable($types) |
|
8929 | 8929 | { |
8930 | - return $this->writer->getAssocTable( $types ); |
|
8930 | + return $this->writer->getAssocTable($types); |
|
8931 | 8931 | } |
8932 | 8932 | |
8933 | 8933 | /** |
@@ -8941,26 +8941,26 @@ discard block |
||
8941 | 8941 | * |
8942 | 8942 | * @return array |
8943 | 8943 | */ |
8944 | - public function associate( $beans1, $beans2 ) |
|
8944 | + public function associate($beans1, $beans2) |
|
8945 | 8945 | { |
8946 | - if ( !is_array( $beans1 ) ) { |
|
8947 | - $beans1 = array( $beans1 ); |
|
8946 | + if (!is_array($beans1)) { |
|
8947 | + $beans1 = array($beans1); |
|
8948 | 8948 | } |
8949 | 8949 | |
8950 | - if ( !is_array( $beans2 ) ) { |
|
8951 | - $beans2 = array( $beans2 ); |
|
8950 | + if (!is_array($beans2)) { |
|
8951 | + $beans2 = array($beans2); |
|
8952 | 8952 | } |
8953 | 8953 | |
8954 | 8954 | $results = array(); |
8955 | - foreach ( $beans1 as $bean1 ) { |
|
8956 | - foreach ( $beans2 as $bean2 ) { |
|
8957 | - $table = $this->getTable( array( $bean1->getMeta( 'type' ), $bean2->getMeta( 'type' ) ) ); |
|
8958 | - $bean = $this->oodb->dispense( $table ); |
|
8959 | - $results[] = $this->associateBeans( $bean1, $bean2, $bean ); |
|
8955 | + foreach ($beans1 as $bean1) { |
|
8956 | + foreach ($beans2 as $bean2) { |
|
8957 | + $table = $this->getTable(array($bean1->getMeta('type'), $bean2->getMeta('type'))); |
|
8958 | + $bean = $this->oodb->dispense($table); |
|
8959 | + $results[] = $this->associateBeans($bean1, $bean2, $bean); |
|
8960 | 8960 | } |
8961 | 8961 | } |
8962 | 8962 | |
8963 | - return ( count( $results ) > 1 ) ? $results : reset( $results ); |
|
8963 | + return (count($results) > 1) ? $results : reset($results); |
|
8964 | 8964 | } |
8965 | 8965 | |
8966 | 8966 | /** |
@@ -8978,24 +8978,24 @@ discard block |
||
8978 | 8978 | * |
8979 | 8979 | * @throws Security |
8980 | 8980 | */ |
8981 | - public function relatedCount( $bean, $type, $sql = NULL, $bindings = array() ) |
|
8981 | + public function relatedCount($bean, $type, $sql = NULL, $bindings = array()) |
|
8982 | 8982 | { |
8983 | - if ( !( $bean instanceof OODBBean ) ) { |
|
8983 | + if (!($bean instanceof OODBBean)) { |
|
8984 | 8984 | throw new RedException( |
8985 | - 'Expected array or OODBBean but got:' . gettype( $bean ) |
|
8985 | + 'Expected array or OODBBean but got:' . gettype($bean) |
|
8986 | 8986 | ); |
8987 | 8987 | } |
8988 | 8988 | |
8989 | - if ( !$bean->id ) { |
|
8989 | + if (!$bean->id) { |
|
8990 | 8990 | return 0; |
8991 | 8991 | } |
8992 | 8992 | |
8993 | - $beanType = $bean->getMeta( 'type' ); |
|
8993 | + $beanType = $bean->getMeta('type'); |
|
8994 | 8994 | |
8995 | 8995 | try { |
8996 | - return $this->writer->queryRecordCountRelated( $beanType, $type, $bean->id, $sql, $bindings ); |
|
8997 | - } catch ( SQLException $exception ) { |
|
8998 | - $this->handleException( $exception ); |
|
8996 | + return $this->writer->queryRecordCountRelated($beanType, $type, $bean->id, $sql, $bindings); |
|
8997 | + } catch (SQLException $exception) { |
|
8998 | + $this->handleException($exception); |
|
8999 | 8999 | |
9000 | 9000 | return 0; |
9001 | 9001 | } |
@@ -9016,37 +9016,37 @@ discard block |
||
9016 | 9016 | * |
9017 | 9017 | * @return void |
9018 | 9018 | */ |
9019 | - public function unassociate( $beans1, $beans2, $fast = NULL ) |
|
9019 | + public function unassociate($beans1, $beans2, $fast = NULL) |
|
9020 | 9020 | { |
9021 | - $beans1 = ( !is_array( $beans1 ) ) ? array( $beans1 ) : $beans1; |
|
9022 | - $beans2 = ( !is_array( $beans2 ) ) ? array( $beans2 ) : $beans2; |
|
9021 | + $beans1 = (!is_array($beans1)) ? array($beans1) : $beans1; |
|
9022 | + $beans2 = (!is_array($beans2)) ? array($beans2) : $beans2; |
|
9023 | 9023 | |
9024 | - foreach ( $beans1 as $bean1 ) { |
|
9025 | - foreach ( $beans2 as $bean2 ) { |
|
9024 | + foreach ($beans1 as $bean1) { |
|
9025 | + foreach ($beans2 as $bean2) { |
|
9026 | 9026 | try { |
9027 | - $this->oodb->store( $bean1 ); |
|
9028 | - $this->oodb->store( $bean2 ); |
|
9027 | + $this->oodb->store($bean1); |
|
9028 | + $this->oodb->store($bean2); |
|
9029 | 9029 | |
9030 | - $type1 = $bean1->getMeta( 'type' ); |
|
9031 | - $type2 = $bean2->getMeta( 'type' ); |
|
9030 | + $type1 = $bean1->getMeta('type'); |
|
9031 | + $type2 = $bean2->getMeta('type'); |
|
9032 | 9032 | |
9033 | - $row = $this->writer->queryRecordLink( $type1, $type2, $bean1->id, $bean2->id ); |
|
9034 | - $linkType = $this->getTable( array( $type1, $type2 ) ); |
|
9033 | + $row = $this->writer->queryRecordLink($type1, $type2, $bean1->id, $bean2->id); |
|
9034 | + $linkType = $this->getTable(array($type1, $type2)); |
|
9035 | 9035 | |
9036 | - if ( $fast ) { |
|
9037 | - $this->writer->deleteRecord( $linkType, array( 'id' => $row['id'] ) ); |
|
9036 | + if ($fast) { |
|
9037 | + $this->writer->deleteRecord($linkType, array('id' => $row['id'])); |
|
9038 | 9038 | |
9039 | 9039 | return; |
9040 | 9040 | } |
9041 | 9041 | |
9042 | - $beans = $this->oodb->convertToBeans( $linkType, array( $row ) ); |
|
9042 | + $beans = $this->oodb->convertToBeans($linkType, array($row)); |
|
9043 | 9043 | |
9044 | - if ( count( $beans ) > 0 ) { |
|
9045 | - $bean = reset( $beans ); |
|
9046 | - $this->oodb->trash( $bean ); |
|
9044 | + if (count($beans) > 0) { |
|
9045 | + $bean = reset($beans); |
|
9046 | + $this->oodb->trash($bean); |
|
9047 | 9047 | } |
9048 | - } catch ( SQLException $exception ) { |
|
9049 | - $this->handleException( $exception ); |
|
9048 | + } catch (SQLException $exception) { |
|
9049 | + $this->handleException($exception); |
|
9050 | 9050 | } |
9051 | 9051 | } |
9052 | 9052 | } |
@@ -9064,13 +9064,13 @@ discard block |
||
9064 | 9064 | * |
9065 | 9065 | * @return void |
9066 | 9066 | */ |
9067 | - public function clearRelations( OODBBean $bean, $type ) |
|
9067 | + public function clearRelations(OODBBean $bean, $type) |
|
9068 | 9068 | { |
9069 | - $this->oodb->store( $bean ); |
|
9069 | + $this->oodb->store($bean); |
|
9070 | 9070 | try { |
9071 | - $this->writer->deleteRelations( $bean->getMeta( 'type' ), $type, $bean->id ); |
|
9072 | - } catch ( SQLException $exception ) { |
|
9073 | - $this->handleException( $exception ); |
|
9071 | + $this->writer->deleteRelations($bean->getMeta('type'), $type, $bean->id); |
|
9072 | + } catch (SQLException $exception) { |
|
9073 | + $this->handleException($exception); |
|
9074 | 9074 | } |
9075 | 9075 | } |
9076 | 9076 | |
@@ -9097,27 +9097,27 @@ discard block |
||
9097 | 9097 | * |
9098 | 9098 | * @return array |
9099 | 9099 | */ |
9100 | - public function related( $bean, $type, $sql = '', $bindings = array() ) |
|
9100 | + public function related($bean, $type, $sql = '', $bindings = array()) |
|
9101 | 9101 | { |
9102 | - $sql = $this->writer->glueSQLCondition( $sql ); |
|
9102 | + $sql = $this->writer->glueSQLCondition($sql); |
|
9103 | 9103 | |
9104 | - $rows = $this->relatedRows( $bean, $type, $sql, $bindings ); |
|
9104 | + $rows = $this->relatedRows($bean, $type, $sql, $bindings); |
|
9105 | 9105 | |
9106 | 9106 | $links = array(); |
9107 | - foreach ( $rows as $key => $row ) { |
|
9108 | - if ( !isset( $links[$row['id']] ) ) { |
|
9107 | + foreach ($rows as $key => $row) { |
|
9108 | + if (!isset($links[$row['id']])) { |
|
9109 | 9109 | $links[$row['id']] = array(); |
9110 | 9110 | } |
9111 | 9111 | |
9112 | 9112 | $links[$row['id']][] = $row['linked_by']; |
9113 | 9113 | |
9114 | - unset( $rows[$key]['linked_by'] ); |
|
9114 | + unset($rows[$key]['linked_by']); |
|
9115 | 9115 | } |
9116 | 9116 | |
9117 | - $beans = $this->oodb->convertToBeans( $type, $rows ); |
|
9117 | + $beans = $this->oodb->convertToBeans($type, $rows); |
|
9118 | 9118 | |
9119 | - foreach ( $beans as $bean ) { |
|
9120 | - $bean->setMeta( 'sys.belongs-to', $links[$bean->id] ); |
|
9119 | + foreach ($beans as $bean) { |
|
9120 | + $bean->setMeta('sys.belongs-to', $links[$bean->id]); |
|
9121 | 9121 | } |
9122 | 9122 | |
9123 | 9123 | return $beans; |
@@ -9175,7 +9175,7 @@ discard block |
||
9175 | 9175 | * |
9176 | 9176 | * @return string |
9177 | 9177 | */ |
9178 | - public function getModelForBean( OODBBean $bean ); |
|
9178 | + public function getModelForBean(OODBBean $bean); |
|
9179 | 9179 | } |
9180 | 9180 | } |
9181 | 9181 | |
@@ -9219,10 +9219,10 @@ discard block |
||
9219 | 9219 | * |
9220 | 9220 | * @return SimpleModel |
9221 | 9221 | */ |
9222 | - public static function factory( $modelClassName ) |
|
9222 | + public static function factory($modelClassName) |
|
9223 | 9223 | { |
9224 | 9224 | $factory = self::$factory; |
9225 | - return ( $factory ) ? $factory( $modelClassName ) : new $modelClassName(); |
|
9225 | + return ($factory) ? $factory($modelClassName) : new $modelClassName(); |
|
9226 | 9226 | } |
9227 | 9227 | |
9228 | 9228 | /** |
@@ -9233,7 +9233,7 @@ discard block |
||
9233 | 9233 | * |
9234 | 9234 | * @return void |
9235 | 9235 | */ |
9236 | - public static function setFactoryFunction( $factory ) |
|
9236 | + public static function setFactoryFunction($factory) |
|
9237 | 9237 | { |
9238 | 9238 | self::$factory = $factory; |
9239 | 9239 | } |
@@ -9249,37 +9249,37 @@ discard block |
||
9249 | 9249 | /** |
9250 | 9250 | * @see BeanHelper::getModelForBean |
9251 | 9251 | */ |
9252 | - public function getModelForBean( OODBBean $bean ) |
|
9252 | + public function getModelForBean(OODBBean $bean) |
|
9253 | 9253 | { |
9254 | - $model = $bean->getMeta( 'type' ); |
|
9255 | - $prefix = defined( 'REDBEAN_MODEL_PREFIX' ) ? REDBEAN_MODEL_PREFIX : '\\Model_'; |
|
9254 | + $model = $bean->getMeta('type'); |
|
9255 | + $prefix = defined('REDBEAN_MODEL_PREFIX') ? REDBEAN_MODEL_PREFIX : '\\Model_'; |
|
9256 | 9256 | |
9257 | - if ( strpos( $model, '_' ) !== FALSE ) { |
|
9258 | - $modelParts = explode( '_', $model ); |
|
9257 | + if (strpos($model, '_') !== FALSE) { |
|
9258 | + $modelParts = explode('_', $model); |
|
9259 | 9259 | $modelName = ''; |
9260 | - foreach( $modelParts as $part ) { |
|
9261 | - $modelName .= ucfirst( $part ); |
|
9260 | + foreach ($modelParts as $part) { |
|
9261 | + $modelName .= ucfirst($part); |
|
9262 | 9262 | } |
9263 | 9263 | $modelName = $prefix . $modelName; |
9264 | 9264 | |
9265 | - if ( !class_exists( $modelName ) ) { |
|
9265 | + if (!class_exists($modelName)) { |
|
9266 | 9266 | //second try |
9267 | - $modelName = $prefix . ucfirst( $model ); |
|
9267 | + $modelName = $prefix . ucfirst($model); |
|
9268 | 9268 | |
9269 | - if ( !class_exists( $modelName ) ) { |
|
9269 | + if (!class_exists($modelName)) { |
|
9270 | 9270 | return NULL; |
9271 | 9271 | } |
9272 | 9272 | } |
9273 | 9273 | |
9274 | 9274 | } else { |
9275 | 9275 | |
9276 | - $modelName = $prefix . ucfirst( $model ); |
|
9277 | - if ( !class_exists( $modelName ) ) { |
|
9276 | + $modelName = $prefix . ucfirst($model); |
|
9277 | + if (!class_exists($modelName)) { |
|
9278 | 9278 | return NULL; |
9279 | 9279 | } |
9280 | 9280 | } |
9281 | - $obj = self::factory( $modelName ); |
|
9282 | - $obj->loadBean( $bean ); |
|
9281 | + $obj = self::factory($modelName); |
|
9282 | + $obj->loadBean($bean); |
|
9283 | 9283 | |
9284 | 9284 | return $obj; |
9285 | 9285 | } |
@@ -9330,7 +9330,7 @@ discard block |
||
9330 | 9330 | * |
9331 | 9331 | * @return void |
9332 | 9332 | */ |
9333 | - public function loadBean( OODBBean $bean ) |
|
9333 | + public function loadBean(OODBBean $bean) |
|
9334 | 9334 | { |
9335 | 9335 | $this->bean = $bean; |
9336 | 9336 | } |
@@ -9346,7 +9346,7 @@ discard block |
||
9346 | 9346 | * |
9347 | 9347 | * @return mixed |
9348 | 9348 | */ |
9349 | - public function __get( $prop ) |
|
9349 | + public function __get($prop) |
|
9350 | 9350 | { |
9351 | 9351 | return $this->bean->$prop; |
9352 | 9352 | } |
@@ -9360,7 +9360,7 @@ discard block |
||
9360 | 9360 | * |
9361 | 9361 | * @return void |
9362 | 9362 | */ |
9363 | - public function __set( $prop, $value ) |
|
9363 | + public function __set($prop, $value) |
|
9364 | 9364 | { |
9365 | 9365 | $this->bean->$prop = $value; |
9366 | 9366 | } |
@@ -9373,9 +9373,9 @@ discard block |
||
9373 | 9373 | * |
9374 | 9374 | * @return boolean |
9375 | 9375 | */ |
9376 | - public function __isset( $key ) |
|
9376 | + public function __isset($key) |
|
9377 | 9377 | { |
9378 | - return isset( $this->bean->$key ); |
|
9378 | + return isset($this->bean->$key); |
|
9379 | 9379 | } |
9380 | 9380 | |
9381 | 9381 | /** |
@@ -9434,7 +9434,7 @@ discard block |
||
9434 | 9434 | /** |
9435 | 9435 | * @see Observer::onEvent |
9436 | 9436 | */ |
9437 | - public function onEvent( $eventName, $bean ) |
|
9437 | + public function onEvent($eventName, $bean) |
|
9438 | 9438 | { |
9439 | 9439 | $bean->$eventName(); |
9440 | 9440 | } |
@@ -9449,10 +9449,10 @@ discard block |
||
9449 | 9449 | * |
9450 | 9450 | * @return void |
9451 | 9451 | */ |
9452 | - public function attachEventListeners( Observable $observable ) |
|
9452 | + public function attachEventListeners(Observable $observable) |
|
9453 | 9453 | { |
9454 | - foreach ( array( 'update', 'open', 'delete', 'after_delete', 'after_update', 'dispense' ) as $e ) { |
|
9455 | - $observable->addEventListener( $e, $this ); |
|
9454 | + foreach (array('update', 'open', 'delete', 'after_delete', 'after_update', 'dispense') as $e) { |
|
9455 | + $observable->addEventListener($e, $this); |
|
9456 | 9456 | } |
9457 | 9457 | } |
9458 | 9458 | } |
@@ -9508,10 +9508,10 @@ discard block |
||
9508 | 9508 | * |
9509 | 9509 | * @return array |
9510 | 9510 | */ |
9511 | - private function extractTagsIfNeeded( $tagList ) |
|
9511 | + private function extractTagsIfNeeded($tagList) |
|
9512 | 9512 | { |
9513 | - if ( $tagList !== FALSE && !is_array( $tagList ) ) { |
|
9514 | - $tags = explode( ',', (string) $tagList ); |
|
9513 | + if ($tagList !== FALSE && !is_array($tagList)) { |
|
9514 | + $tags = explode(',', (string) $tagList); |
|
9515 | 9515 | } else { |
9516 | 9516 | $tags = $tagList; |
9517 | 9517 | } |
@@ -9527,12 +9527,12 @@ discard block |
||
9527 | 9527 | * |
9528 | 9528 | * @return OODBBean |
9529 | 9529 | */ |
9530 | - protected function findTagByTitle( $title ) |
|
9530 | + protected function findTagByTitle($title) |
|
9531 | 9531 | { |
9532 | - $beans = $this->redbean->find( 'tag', array( 'title' => array( $title ) ) ); |
|
9532 | + $beans = $this->redbean->find('tag', array('title' => array($title))); |
|
9533 | 9533 | |
9534 | - if ( $beans ) { |
|
9535 | - $bean = reset( $beans ); |
|
9534 | + if ($beans) { |
|
9535 | + $bean = reset($beans); |
|
9536 | 9536 | |
9537 | 9537 | return $bean; |
9538 | 9538 | } |
@@ -9547,7 +9547,7 @@ discard block |
||
9547 | 9547 | * |
9548 | 9548 | * @param ToolBox $toolbox |
9549 | 9549 | */ |
9550 | - public function __construct( ToolBox $toolbox ) |
|
9550 | + public function __construct(ToolBox $toolbox) |
|
9551 | 9551 | { |
9552 | 9552 | $this->toolbox = $toolbox; |
9553 | 9553 | $this->redbean = $toolbox->getRedBean(); |
@@ -9573,18 +9573,18 @@ discard block |
||
9573 | 9573 | * |
9574 | 9574 | * @return boolean |
9575 | 9575 | */ |
9576 | - public function hasTag( $bean, $tags, $all = FALSE ) |
|
9576 | + public function hasTag($bean, $tags, $all = FALSE) |
|
9577 | 9577 | { |
9578 | - $foundtags = $this->tag( $bean ); |
|
9578 | + $foundtags = $this->tag($bean); |
|
9579 | 9579 | |
9580 | - $tags = $this->extractTagsIfNeeded( $tags ); |
|
9581 | - $same = array_intersect( $tags, $foundtags ); |
|
9580 | + $tags = $this->extractTagsIfNeeded($tags); |
|
9581 | + $same = array_intersect($tags, $foundtags); |
|
9582 | 9582 | |
9583 | - if ( $all ) { |
|
9584 | - return ( implode( ',', $same ) === implode( ',', $tags ) ); |
|
9583 | + if ($all) { |
|
9584 | + return (implode(',', $same) === implode(',', $tags)); |
|
9585 | 9585 | } |
9586 | 9586 | |
9587 | - return (bool) ( count( $same ) > 0 ); |
|
9587 | + return (bool) (count($same) > 0); |
|
9588 | 9588 | } |
9589 | 9589 | |
9590 | 9590 | /** |
@@ -9599,13 +9599,13 @@ discard block |
||
9599 | 9599 | * |
9600 | 9600 | * @return void |
9601 | 9601 | */ |
9602 | - public function untag( $bean, $tagList ) |
|
9602 | + public function untag($bean, $tagList) |
|
9603 | 9603 | { |
9604 | - $tags = $this->extractTagsIfNeeded( $tagList ); |
|
9604 | + $tags = $this->extractTagsIfNeeded($tagList); |
|
9605 | 9605 | |
9606 | - foreach ( $tags as $tag ) { |
|
9607 | - if ( $t = $this->findTagByTitle( $tag ) ) { |
|
9608 | - $this->associationManager->unassociate( $bean, $t ); |
|
9606 | + foreach ($tags as $tag) { |
|
9607 | + if ($t = $this->findTagByTitle($tag)) { |
|
9608 | + $this->associationManager->unassociate($bean, $t); |
|
9609 | 9609 | } |
9610 | 9610 | } |
9611 | 9611 | } |
@@ -9626,22 +9626,22 @@ discard block |
||
9626 | 9626 | * |
9627 | 9627 | * @return array |
9628 | 9628 | */ |
9629 | - public function tag( OODBBean $bean, $tagList = NULL ) |
|
9629 | + public function tag(OODBBean $bean, $tagList = NULL) |
|
9630 | 9630 | { |
9631 | - if ( is_null( $tagList ) ) { |
|
9631 | + if (is_null($tagList)) { |
|
9632 | 9632 | |
9633 | 9633 | $tags = $bean->sharedTag; |
9634 | 9634 | $foundTags = array(); |
9635 | 9635 | |
9636 | - foreach ( $tags as $tag ) { |
|
9636 | + foreach ($tags as $tag) { |
|
9637 | 9637 | $foundTags[] = $tag->title; |
9638 | 9638 | } |
9639 | 9639 | |
9640 | 9640 | return $foundTags; |
9641 | 9641 | } |
9642 | 9642 | |
9643 | - $this->associationManager->clearRelations( $bean, 'tag' ); |
|
9644 | - $this->addTags( $bean, $tagList ); |
|
9643 | + $this->associationManager->clearRelations($bean, 'tag'); |
|
9644 | + $this->addTags($bean, $tagList); |
|
9645 | 9645 | |
9646 | 9646 | return $tagList; |
9647 | 9647 | } |
@@ -9660,23 +9660,23 @@ discard block |
||
9660 | 9660 | * |
9661 | 9661 | * @return void |
9662 | 9662 | */ |
9663 | - public function addTags( OODBBean $bean, $tagList ) |
|
9663 | + public function addTags(OODBBean $bean, $tagList) |
|
9664 | 9664 | { |
9665 | - $tags = $this->extractTagsIfNeeded( $tagList ); |
|
9665 | + $tags = $this->extractTagsIfNeeded($tagList); |
|
9666 | 9666 | |
9667 | - if ( $tagList === FALSE ) { |
|
9667 | + if ($tagList === FALSE) { |
|
9668 | 9668 | return; |
9669 | 9669 | } |
9670 | 9670 | |
9671 | - foreach ( $tags as $tag ) { |
|
9672 | - if ( !$t = $this->findTagByTitle( $tag ) ) { |
|
9673 | - $t = $this->redbean->dispense( 'tag' ); |
|
9671 | + foreach ($tags as $tag) { |
|
9672 | + if (!$t = $this->findTagByTitle($tag)) { |
|
9673 | + $t = $this->redbean->dispense('tag'); |
|
9674 | 9674 | $t->title = $tag; |
9675 | 9675 | |
9676 | - $this->redbean->store( $t ); |
|
9676 | + $this->redbean->store($t); |
|
9677 | 9677 | } |
9678 | 9678 | |
9679 | - $this->associationManager->associate( $bean, $t ); |
|
9679 | + $this->associationManager->associate($bean, $t); |
|
9680 | 9680 | } |
9681 | 9681 | } |
9682 | 9682 | |
@@ -9694,12 +9694,12 @@ discard block |
||
9694 | 9694 | * |
9695 | 9695 | * @return array |
9696 | 9696 | */ |
9697 | - public function tagged( $beanType, $tagList, $sql = '', $bindings = array() ) |
|
9697 | + public function tagged($beanType, $tagList, $sql = '', $bindings = array()) |
|
9698 | 9698 | { |
9699 | - $tags = $this->extractTagsIfNeeded( $tagList ); |
|
9700 | - $records = $this->toolbox->getWriter()->queryTagged( $beanType, $tags, FALSE, $sql, $bindings ); |
|
9699 | + $tags = $this->extractTagsIfNeeded($tagList); |
|
9700 | + $records = $this->toolbox->getWriter()->queryTagged($beanType, $tags, FALSE, $sql, $bindings); |
|
9701 | 9701 | |
9702 | - return $this->redbean->convertToBeans( $beanType, $records ); |
|
9702 | + return $this->redbean->convertToBeans($beanType, $records); |
|
9703 | 9703 | } |
9704 | 9704 | |
9705 | 9705 | /** |
@@ -9713,12 +9713,12 @@ discard block |
||
9713 | 9713 | * |
9714 | 9714 | * @return array |
9715 | 9715 | */ |
9716 | - public function taggedAll( $beanType, $tagList, $sql = '', $bindings = array() ) |
|
9716 | + public function taggedAll($beanType, $tagList, $sql = '', $bindings = array()) |
|
9717 | 9717 | { |
9718 | - $tags = $this->extractTagsIfNeeded( $tagList ); |
|
9719 | - $records = $this->toolbox->getWriter()->queryTagged( $beanType, $tags, TRUE, $sql, $bindings ); |
|
9718 | + $tags = $this->extractTagsIfNeeded($tagList); |
|
9719 | + $records = $this->toolbox->getWriter()->queryTagged($beanType, $tags, TRUE, $sql, $bindings); |
|
9720 | 9720 | |
9721 | - return $this->redbean->convertToBeans( $beanType, $records ); |
|
9721 | + return $this->redbean->convertToBeans($beanType, $records); |
|
9722 | 9722 | } |
9723 | 9723 | } |
9724 | 9724 | } |
@@ -9757,7 +9757,7 @@ discard block |
||
9757 | 9757 | * |
9758 | 9758 | * @param ToolBox $toolbox |
9759 | 9759 | */ |
9760 | - public function __construct( ToolBox $toolbox ) |
|
9760 | + public function __construct(ToolBox $toolbox) |
|
9761 | 9761 | { |
9762 | 9762 | $this->toolbox = $toolbox; |
9763 | 9763 | } |
@@ -9775,11 +9775,11 @@ discard block |
||
9775 | 9775 | * |
9776 | 9776 | * @return array |
9777 | 9777 | */ |
9778 | - public function dispenseLabels( $type, $labels ) |
|
9778 | + public function dispenseLabels($type, $labels) |
|
9779 | 9779 | { |
9780 | 9780 | $labelBeans = array(); |
9781 | - foreach ( $labels as $label ) { |
|
9782 | - $labelBean = $this->toolbox->getRedBean()->dispense( $type ); |
|
9781 | + foreach ($labels as $label) { |
|
9782 | + $labelBean = $this->toolbox->getRedBean()->dispense($type); |
|
9783 | 9783 | $labelBean->name = $label; |
9784 | 9784 | $labelBeans[] = $labelBean; |
9785 | 9785 | } |
@@ -9805,15 +9805,15 @@ discard block |
||
9805 | 9805 | * |
9806 | 9806 | * @return array |
9807 | 9807 | */ |
9808 | - public function gatherLabels( $beans ) |
|
9808 | + public function gatherLabels($beans) |
|
9809 | 9809 | { |
9810 | 9810 | $labels = array(); |
9811 | 9811 | |
9812 | - foreach ( $beans as $bean ) { |
|
9812 | + foreach ($beans as $bean) { |
|
9813 | 9813 | $labels[] = $bean->name; |
9814 | 9814 | } |
9815 | 9815 | |
9816 | - sort( $labels ); |
|
9816 | + sort($labels); |
|
9817 | 9817 | |
9818 | 9818 | return $labels; |
9819 | 9819 | } |
@@ -9846,32 +9846,32 @@ discard block |
||
9846 | 9846 | * |
9847 | 9847 | * @return array|OODBBean |
9848 | 9848 | */ |
9849 | - public function enum( $enum ) |
|
9849 | + public function enum($enum) |
|
9850 | 9850 | { |
9851 | 9851 | $oodb = $this->toolbox->getRedBean(); |
9852 | 9852 | |
9853 | - if ( strpos( $enum, ':' ) === FALSE ) { |
|
9853 | + if (strpos($enum, ':') === FALSE) { |
|
9854 | 9854 | $type = $enum; |
9855 | 9855 | $value = FALSE; |
9856 | 9856 | } else { |
9857 | - list( $type, $value ) = explode( ':', $enum ); |
|
9858 | - $value = preg_replace( '/\W+/', '_', strtoupper( trim( $value ) ) ); |
|
9857 | + list($type, $value) = explode(':', $enum); |
|
9858 | + $value = preg_replace('/\W+/', '_', strtoupper(trim($value))); |
|
9859 | 9859 | } |
9860 | 9860 | |
9861 | - $values = $oodb->find( $type ); |
|
9861 | + $values = $oodb->find($type); |
|
9862 | 9862 | |
9863 | - if ( $value === FALSE ) { |
|
9863 | + if ($value === FALSE) { |
|
9864 | 9864 | return $values; |
9865 | 9865 | } |
9866 | 9866 | |
9867 | - foreach( $values as $enumItem ) { |
|
9868 | - if ( $enumItem->name === $value ) return $enumItem; |
|
9867 | + foreach ($values as $enumItem) { |
|
9868 | + if ($enumItem->name === $value) return $enumItem; |
|
9869 | 9869 | } |
9870 | 9870 | |
9871 | - $newEnumItems = $this->dispenseLabels( $type, array( $value ) ); |
|
9872 | - $newEnumItem = reset( $newEnumItems ); |
|
9871 | + $newEnumItems = $this->dispenseLabels($type, array($value)); |
|
9872 | + $newEnumItem = reset($newEnumItems); |
|
9873 | 9873 | |
9874 | - $oodb->store( $newEnumItem ); |
|
9874 | + $oodb->store($newEnumItem); |
|
9875 | 9875 | |
9876 | 9876 | return $newEnumItem; |
9877 | 9877 | } |
@@ -10016,19 +10016,19 @@ discard block |
||
10016 | 10016 | * |
10017 | 10017 | * @return array |
10018 | 10018 | */ |
10019 | - private static function query( $method, $sql, $bindings ) |
|
10019 | + private static function query($method, $sql, $bindings) |
|
10020 | 10020 | { |
10021 | - if ( !self::$redbean->isFrozen() ) { |
|
10021 | + if (!self::$redbean->isFrozen()) { |
|
10022 | 10022 | try { |
10023 | - $rs = Facade::$adapter->$method( $sql, $bindings ); |
|
10024 | - } catch ( SQLException $exception ) { |
|
10025 | - if ( self::$writer->sqlStateIn( $exception->getSQLState(), |
|
10023 | + $rs = Facade::$adapter->$method($sql, $bindings); |
|
10024 | + } catch (SQLException $exception) { |
|
10025 | + if (self::$writer->sqlStateIn($exception->getSQLState(), |
|
10026 | 10026 | array( |
10027 | 10027 | QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN, |
10028 | 10028 | QueryWriter::C_SQLSTATE_NO_SUCH_TABLE ) |
10029 | 10029 | ) |
10030 | 10030 | ) { |
10031 | - return ( $method === 'getCell' ) ? NULL : array(); |
|
10031 | + return ($method === 'getCell') ? NULL : array(); |
|
10032 | 10032 | } else { |
10033 | 10033 | throw $exception; |
10034 | 10034 | } |
@@ -10036,7 +10036,7 @@ discard block |
||
10036 | 10036 | |
10037 | 10037 | return $rs; |
10038 | 10038 | } else { |
10039 | - return Facade::$adapter->$method( $sql, $bindings ); |
|
10039 | + return Facade::$adapter->$method($sql, $bindings); |
|
10040 | 10040 | } |
10041 | 10041 | } |
10042 | 10042 | |
@@ -10062,12 +10062,12 @@ discard block |
||
10062 | 10062 | */ |
10063 | 10063 | public static function testConnection() |
10064 | 10064 | { |
10065 | - if ( !isset( self::$adapter ) ) return FALSE; |
|
10065 | + if (!isset(self::$adapter)) return FALSE; |
|
10066 | 10066 | |
10067 | 10067 | $database = self::$adapter->getDatabase(); |
10068 | 10068 | try { |
10069 | 10069 | @$database->connect(); |
10070 | - } catch ( \Exception $e ) {} |
|
10070 | + } catch (\Exception $e) {} |
|
10071 | 10071 | return $database->isConnected(); |
10072 | 10072 | } |
10073 | 10073 | |
@@ -10083,14 +10083,14 @@ discard block |
||
10083 | 10083 | * |
10084 | 10084 | * @return ToolBox |
10085 | 10085 | */ |
10086 | - public static function setup( $dsn = NULL, $username = NULL, $password = NULL, $frozen = FALSE ) |
|
10086 | + public static function setup($dsn = NULL, $username = NULL, $password = NULL, $frozen = FALSE) |
|
10087 | 10087 | { |
10088 | - if ( is_null( $dsn ) ) { |
|
10088 | + if (is_null($dsn)) { |
|
10089 | 10089 | $dsn = 'sqlite:/' . sys_get_temp_dir() . '/red.db'; |
10090 | 10090 | } |
10091 | 10091 | |
10092 | - self::addDatabase( 'default', $dsn, $username, $password, $frozen ); |
|
10093 | - self::selectDatabase( 'default' ); |
|
10092 | + self::addDatabase('default', $dsn, $username, $password, $frozen); |
|
10093 | + self::selectDatabase('default'); |
|
10094 | 10094 | |
10095 | 10095 | return self::$toolbox; |
10096 | 10096 | } |
@@ -10103,9 +10103,9 @@ discard block |
||
10103 | 10103 | * |
10104 | 10104 | * @return void |
10105 | 10105 | */ |
10106 | - public static function setNarrowFieldMode( $mode ) |
|
10106 | + public static function setNarrowFieldMode($mode) |
|
10107 | 10107 | { |
10108 | - AQueryWriter::setNarrowFieldMode( $mode ); |
|
10108 | + AQueryWriter::setNarrowFieldMode($mode); |
|
10109 | 10109 | } |
10110 | 10110 | |
10111 | 10111 | /** |
@@ -10139,27 +10139,27 @@ discard block |
||
10139 | 10139 | * @return mixed |
10140 | 10140 | * |
10141 | 10141 | */ |
10142 | - public static function transaction( $callback ) |
|
10142 | + public static function transaction($callback) |
|
10143 | 10143 | { |
10144 | - if ( !is_callable( $callback ) ) { |
|
10145 | - throw new RedException( 'R::transaction needs a valid callback.' ); |
|
10144 | + if (!is_callable($callback)) { |
|
10145 | + throw new RedException('R::transaction needs a valid callback.'); |
|
10146 | 10146 | } |
10147 | 10147 | |
10148 | 10148 | static $depth = 0; |
10149 | 10149 | $result = null; |
10150 | 10150 | try { |
10151 | - if ( $depth == 0 ) { |
|
10151 | + if ($depth == 0) { |
|
10152 | 10152 | self::begin(); |
10153 | 10153 | } |
10154 | 10154 | $depth++; |
10155 | - $result = call_user_func( $callback ); //maintain 5.2 compatibility |
|
10155 | + $result = call_user_func($callback); //maintain 5.2 compatibility |
|
10156 | 10156 | $depth--; |
10157 | - if ( $depth == 0 ) { |
|
10157 | + if ($depth == 0) { |
|
10158 | 10158 | self::commit(); |
10159 | 10159 | } |
10160 | - } catch (\Exception $exception ) { |
|
10160 | + } catch (\Exception $exception) { |
|
10161 | 10161 | $depth--; |
10162 | - if ( $depth == 0 ) { |
|
10162 | + if ($depth == 0) { |
|
10163 | 10163 | self::rollback(); |
10164 | 10164 | } |
10165 | 10165 | throw $exception; |
@@ -10187,23 +10187,23 @@ discard block |
||
10187 | 10187 | * |
10188 | 10188 | * @return void |
10189 | 10189 | */ |
10190 | - public static function addDatabase( $key, $dsn, $user = NULL, $pass = NULL, $frozen = FALSE ) |
|
10190 | + public static function addDatabase($key, $dsn, $user = NULL, $pass = NULL, $frozen = FALSE) |
|
10191 | 10191 | { |
10192 | - if ( isset( self::$toolboxes[$key] ) ) { |
|
10193 | - throw new RedException( 'A database has already be specified for this key.' ); |
|
10192 | + if (isset(self::$toolboxes[$key])) { |
|
10193 | + throw new RedException('A database has already be specified for this key.'); |
|
10194 | 10194 | } |
10195 | 10195 | |
10196 | - if ( is_object($dsn) ) { |
|
10197 | - $db = new RPDO( $dsn ); |
|
10196 | + if (is_object($dsn)) { |
|
10197 | + $db = new RPDO($dsn); |
|
10198 | 10198 | $dbType = $db->getDatabaseType(); |
10199 | 10199 | } else { |
10200 | - $db = new RPDO( $dsn, $user, $pass, TRUE ); |
|
10201 | - $dbType = substr( $dsn, 0, strpos( $dsn, ':' ) ); |
|
10200 | + $db = new RPDO($dsn, $user, $pass, TRUE); |
|
10201 | + $dbType = substr($dsn, 0, strpos($dsn, ':')); |
|
10202 | 10202 | } |
10203 | 10203 | |
10204 | - $adapter = new DBAdapter( $db ); |
|
10204 | + $adapter = new DBAdapter($db); |
|
10205 | 10205 | |
10206 | - $writers = array( |
|
10206 | + $writers = array( |
|
10207 | 10207 | 'pgsql' => 'PostgreSQL', |
10208 | 10208 | 'sqlite' => 'SQLiteT', |
10209 | 10209 | 'cubrid' => 'CUBRID', |
@@ -10211,13 +10211,13 @@ discard block |
||
10211 | 10211 | 'sqlsrv' => 'SQLServer', |
10212 | 10212 | ); |
10213 | 10213 | |
10214 | - $wkey = trim( strtolower( $dbType ) ); |
|
10215 | - if ( !isset( $writers[$wkey] ) ) trigger_error( 'Unsupported DSN: '.$wkey ); |
|
10216 | - $writerClass = '\\RedBeanPHP\\QueryWriter\\'.$writers[$wkey]; |
|
10217 | - $writer = new $writerClass( $adapter ); |
|
10218 | - $redbean = new OODB( $writer, $frozen ); |
|
10214 | + $wkey = trim(strtolower($dbType)); |
|
10215 | + if (!isset($writers[$wkey])) trigger_error('Unsupported DSN: ' . $wkey); |
|
10216 | + $writerClass = '\\RedBeanPHP\\QueryWriter\\' . $writers[$wkey]; |
|
10217 | + $writer = new $writerClass($adapter); |
|
10218 | + $redbean = new OODB($writer, $frozen); |
|
10219 | 10219 | |
10220 | - self::$toolboxes[$key] = new ToolBox( $redbean, $adapter, $writer ); |
|
10220 | + self::$toolboxes[$key] = new ToolBox($redbean, $adapter, $writer); |
|
10221 | 10221 | } |
10222 | 10222 | |
10223 | 10223 | /** |
@@ -10234,13 +10234,13 @@ discard block |
||
10234 | 10234 | * |
10235 | 10235 | * @return boolean |
10236 | 10236 | */ |
10237 | - public static function selectDatabase( $key ) |
|
10237 | + public static function selectDatabase($key) |
|
10238 | 10238 | { |
10239 | - if ( self::$currentDB === $key ) { |
|
10239 | + if (self::$currentDB === $key) { |
|
10240 | 10240 | return FALSE; |
10241 | 10241 | } |
10242 | 10242 | |
10243 | - self::configureFacadeWithToolbox( self::$toolboxes[$key] ); |
|
10243 | + self::configureFacadeWithToolbox(self::$toolboxes[$key]); |
|
10244 | 10244 | self::$currentDB = $key; |
10245 | 10245 | |
10246 | 10246 | return TRUE; |
@@ -10261,7 +10261,7 @@ discard block |
||
10261 | 10261 | * |
10262 | 10262 | * @return Logger\RDefault |
10263 | 10263 | */ |
10264 | - public static function debug( $tf = TRUE, $mode = 0 ) |
|
10264 | + public static function debug($tf = TRUE, $mode = 0) |
|
10265 | 10265 | { |
10266 | 10266 | if ($mode > 1) { |
10267 | 10267 | $mode -= 2; |
@@ -10270,11 +10270,11 @@ discard block |
||
10270 | 10270 | $logger = new RDefault; |
10271 | 10271 | } |
10272 | 10272 | |
10273 | - if ( !isset( self::$adapter ) ) { |
|
10274 | - throw new RedException( 'Use R::setup() first.' ); |
|
10273 | + if (!isset(self::$adapter)) { |
|
10274 | + throw new RedException('Use R::setup() first.'); |
|
10275 | 10275 | } |
10276 | 10276 | $logger->setMode($mode); |
10277 | - self::$adapter->getDatabase()->setDebugMode( $tf, $logger ); |
|
10277 | + self::$adapter->getDatabase()->setDebugMode($tf, $logger); |
|
10278 | 10278 | |
10279 | 10279 | return $logger; |
10280 | 10280 | } |
@@ -10282,9 +10282,9 @@ discard block |
||
10282 | 10282 | /** |
10283 | 10283 | * Turns on the fancy debugger. |
10284 | 10284 | */ |
10285 | - public static function fancyDebug( $toggle ) |
|
10285 | + public static function fancyDebug($toggle) |
|
10286 | 10286 | { |
10287 | - self::debug( $toggle, 2 ); |
|
10287 | + self::debug($toggle, 2); |
|
10288 | 10288 | } |
10289 | 10289 | |
10290 | 10290 | /** |
@@ -10298,9 +10298,9 @@ discard block |
||
10298 | 10298 | * |
10299 | 10299 | * @return array |
10300 | 10300 | */ |
10301 | - public static function inspect( $type = NULL ) |
|
10301 | + public static function inspect($type = NULL) |
|
10302 | 10302 | { |
10303 | - return ($type === NULL) ? self::$writer->getTables() : self::$writer->getColumns( $type ); |
|
10303 | + return ($type === NULL) ? self::$writer->getTables() : self::$writer->getColumns($type); |
|
10304 | 10304 | } |
10305 | 10305 | |
10306 | 10306 | /** |
@@ -10323,9 +10323,9 @@ discard block |
||
10323 | 10323 | * |
10324 | 10324 | * @throws Security |
10325 | 10325 | */ |
10326 | - public static function store( $bean ) |
|
10326 | + public static function store($bean) |
|
10327 | 10327 | { |
10328 | - return self::$redbean->store( $bean ); |
|
10328 | + return self::$redbean->store($bean); |
|
10329 | 10329 | } |
10330 | 10330 | |
10331 | 10331 | /** |
@@ -10339,9 +10339,9 @@ discard block |
||
10339 | 10339 | * |
10340 | 10340 | * @param boolean|array $trueFalse |
10341 | 10341 | */ |
10342 | - public static function freeze( $tf = TRUE ) |
|
10342 | + public static function freeze($tf = TRUE) |
|
10343 | 10343 | { |
10344 | - self::$redbean->freeze( $tf ); |
|
10344 | + self::$redbean->freeze($tf); |
|
10345 | 10345 | } |
10346 | 10346 | |
10347 | 10347 | /** |
@@ -10357,18 +10357,18 @@ discard block |
||
10357 | 10357 | * |
10358 | 10358 | * @return OODBBean |
10359 | 10359 | */ |
10360 | - public static function loadMulti( $types, $id ) |
|
10360 | + public static function loadMulti($types, $id) |
|
10361 | 10361 | { |
10362 | - if ( is_string( $types ) ) { |
|
10363 | - $types = explode( ',', $types ); |
|
10362 | + if (is_string($types)) { |
|
10363 | + $types = explode(',', $types); |
|
10364 | 10364 | } |
10365 | 10365 | |
10366 | - if ( !is_array( $types ) ) { |
|
10366 | + if (!is_array($types)) { |
|
10367 | 10367 | return array(); |
10368 | 10368 | } |
10369 | 10369 | |
10370 | - foreach ( $types as $k => $typeItem ) { |
|
10371 | - $types[$k] = self::$redbean->load( $typeItem, $id ); |
|
10370 | + foreach ($types as $k => $typeItem) { |
|
10371 | + $types[$k] = self::$redbean->load($typeItem, $id); |
|
10372 | 10372 | } |
10373 | 10373 | |
10374 | 10374 | return $types; |
@@ -10398,9 +10398,9 @@ discard block |
||
10398 | 10398 | * |
10399 | 10399 | * @return OODBBean |
10400 | 10400 | */ |
10401 | - public static function load( $type, $id ) |
|
10401 | + public static function load($type, $id) |
|
10402 | 10402 | { |
10403 | - return self::$redbean->load( $type, $id ); |
|
10403 | + return self::$redbean->load($type, $id); |
|
10404 | 10404 | } |
10405 | 10405 | |
10406 | 10406 | /** |
@@ -10417,10 +10417,10 @@ discard block |
||
10417 | 10417 | * |
10418 | 10418 | * @return void |
10419 | 10419 | */ |
10420 | - public static function trash( $beanOrType, $id = NULL ) |
|
10420 | + public static function trash($beanOrType, $id = NULL) |
|
10421 | 10421 | { |
10422 | - if ( is_string( $beanOrType ) ) return self::trash( self::load( $beanOrType, $id ) ); |
|
10423 | - return self::$redbean->trash( $beanOrType ); |
|
10422 | + if (is_string($beanOrType)) return self::trash(self::load($beanOrType, $id)); |
|
10423 | + return self::$redbean->trash($beanOrType); |
|
10424 | 10424 | } |
10425 | 10425 | |
10426 | 10426 | /** |
@@ -10435,32 +10435,32 @@ discard block |
||
10435 | 10435 | * |
10436 | 10436 | * @throws Security |
10437 | 10437 | */ |
10438 | - public static function dispense( $typeOrBeanArray, $num = 1, $alwaysReturnArray = FALSE ) |
|
10438 | + public static function dispense($typeOrBeanArray, $num = 1, $alwaysReturnArray = FALSE) |
|
10439 | 10439 | { |
10440 | - if ( is_array($typeOrBeanArray) ) { |
|
10440 | + if (is_array($typeOrBeanArray)) { |
|
10441 | 10441 | |
10442 | - if ( !isset( $typeOrBeanArray['_type'] ) ) { |
|
10442 | + if (!isset($typeOrBeanArray['_type'])) { |
|
10443 | 10443 | $list = array(); |
10444 | - foreach( $typeOrBeanArray as $beanArray ) if ( !( is_array( $beanArray ) && isset( $beanArray['_type'] ) ) ) throw new RedException( 'Invalid Array Bean' ); |
|
10445 | - foreach( $typeOrBeanArray as $beanArray ) $list[] = self::dispense( $beanArray ); |
|
10444 | + foreach ($typeOrBeanArray as $beanArray) if (!(is_array($beanArray) && isset($beanArray['_type']))) throw new RedException('Invalid Array Bean'); |
|
10445 | + foreach ($typeOrBeanArray as $beanArray) $list[] = self::dispense($beanArray); |
|
10446 | 10446 | return $list; |
10447 | 10447 | } |
10448 | 10448 | |
10449 | 10449 | $import = $typeOrBeanArray; |
10450 | 10450 | $type = $import['_type']; |
10451 | - unset( $import['_type'] ); |
|
10451 | + unset($import['_type']); |
|
10452 | 10452 | } else { |
10453 | 10453 | $type = $typeOrBeanArray; |
10454 | 10454 | } |
10455 | 10455 | |
10456 | - if ( !preg_match( '/^[a-z0-9]+$/', $type ) ) { |
|
10457 | - throw new RedException( 'Invalid type: ' . $type ); |
|
10456 | + if (!preg_match('/^[a-z0-9]+$/', $type)) { |
|
10457 | + throw new RedException('Invalid type: ' . $type); |
|
10458 | 10458 | } |
10459 | 10459 | |
10460 | - $beanOrBeans = self::$redbean->dispense( $type, $num, $alwaysReturnArray ); |
|
10460 | + $beanOrBeans = self::$redbean->dispense($type, $num, $alwaysReturnArray); |
|
10461 | 10461 | |
10462 | - if ( isset( $import ) ) { |
|
10463 | - $beanOrBeans->import( $import ); |
|
10462 | + if (isset($import)) { |
|
10463 | + $beanOrBeans->import($import); |
|
10464 | 10464 | } |
10465 | 10465 | |
10466 | 10466 | return $beanOrBeans; |
@@ -10490,20 +10490,20 @@ discard block |
||
10490 | 10490 | * |
10491 | 10491 | * @return array |
10492 | 10492 | */ |
10493 | - public static function dispenseAll( $order, $onlyArrays = FALSE ) |
|
10493 | + public static function dispenseAll($order, $onlyArrays = FALSE) |
|
10494 | 10494 | { |
10495 | 10495 | |
10496 | 10496 | $list = array(); |
10497 | 10497 | |
10498 | - foreach( explode( ',', $order ) as $order ) { |
|
10499 | - if ( strpos( $order, '*' ) !== false ) { |
|
10500 | - list( $type, $amount ) = explode( '*', $order ); |
|
10498 | + foreach (explode(',', $order) as $order) { |
|
10499 | + if (strpos($order, '*') !== false) { |
|
10500 | + list($type, $amount) = explode('*', $order); |
|
10501 | 10501 | } else { |
10502 | 10502 | $type = $order; |
10503 | 10503 | $amount = 1; |
10504 | 10504 | } |
10505 | 10505 | |
10506 | - $list[] = self::dispense( $type, $amount, $onlyArrays ); |
|
10506 | + $list[] = self::dispense($type, $amount, $onlyArrays); |
|
10507 | 10507 | } |
10508 | 10508 | |
10509 | 10509 | return $list; |
@@ -10519,9 +10519,9 @@ discard block |
||
10519 | 10519 | * |
10520 | 10520 | * @return array |
10521 | 10521 | */ |
10522 | - public static function findOrDispense( $type, $sql = NULL, $bindings = array() ) |
|
10522 | + public static function findOrDispense($type, $sql = NULL, $bindings = array()) |
|
10523 | 10523 | { |
10524 | - return self::$finder->findOrDispense( $type, $sql, $bindings ); |
|
10524 | + return self::$finder->findOrDispense($type, $sql, $bindings); |
|
10525 | 10525 | } |
10526 | 10526 | |
10527 | 10527 | /** |
@@ -10537,9 +10537,9 @@ discard block |
||
10537 | 10537 | * |
10538 | 10538 | * @return array |
10539 | 10539 | */ |
10540 | - public static function find( $type, $sql = NULL, $bindings = array() ) |
|
10540 | + public static function find($type, $sql = NULL, $bindings = array()) |
|
10541 | 10541 | { |
10542 | - return self::$finder->find( $type, $sql, $bindings ); |
|
10542 | + return self::$finder->find($type, $sql, $bindings); |
|
10543 | 10543 | } |
10544 | 10544 | |
10545 | 10545 | /** |
@@ -10557,9 +10557,9 @@ discard block |
||
10557 | 10557 | * |
10558 | 10558 | * @return array |
10559 | 10559 | */ |
10560 | - public static function findAll( $type, $sql = NULL, $bindings = array() ) |
|
10560 | + public static function findAll($type, $sql = NULL, $bindings = array()) |
|
10561 | 10561 | { |
10562 | - return self::$finder->find( $type, $sql, $bindings ); |
|
10562 | + return self::$finder->find($type, $sql, $bindings); |
|
10563 | 10563 | } |
10564 | 10564 | |
10565 | 10565 | /** |
@@ -10572,9 +10572,9 @@ discard block |
||
10572 | 10572 | * |
10573 | 10573 | * @return array |
10574 | 10574 | */ |
10575 | - public static function findAndExport( $type, $sql = NULL, $bindings = array() ) |
|
10575 | + public static function findAndExport($type, $sql = NULL, $bindings = array()) |
|
10576 | 10576 | { |
10577 | - return self::$finder->findAndExport( $type, $sql, $bindings ); |
|
10577 | + return self::$finder->findAndExport($type, $sql, $bindings); |
|
10578 | 10578 | } |
10579 | 10579 | |
10580 | 10580 | /** |
@@ -10587,9 +10587,9 @@ discard block |
||
10587 | 10587 | * |
10588 | 10588 | * @return OODBBean |
10589 | 10589 | */ |
10590 | - public static function findOne( $type, $sql = NULL, $bindings = array() ) |
|
10590 | + public static function findOne($type, $sql = NULL, $bindings = array()) |
|
10591 | 10591 | { |
10592 | - return self::$finder->findOne( $type, $sql, $bindings ); |
|
10592 | + return self::$finder->findOne($type, $sql, $bindings); |
|
10593 | 10593 | } |
10594 | 10594 | |
10595 | 10595 | /** |
@@ -10602,9 +10602,9 @@ discard block |
||
10602 | 10602 | * |
10603 | 10603 | * @return OODBBean |
10604 | 10604 | */ |
10605 | - public static function findLast( $type, $sql = NULL, $bindings = array() ) |
|
10605 | + public static function findLast($type, $sql = NULL, $bindings = array()) |
|
10606 | 10606 | { |
10607 | - return self::$finder->findLast( $type, $sql, $bindings ); |
|
10607 | + return self::$finder->findLast($type, $sql, $bindings); |
|
10608 | 10608 | } |
10609 | 10609 | |
10610 | 10610 | /** |
@@ -10617,9 +10617,9 @@ discard block |
||
10617 | 10617 | * |
10618 | 10618 | * @return BeanCollection |
10619 | 10619 | */ |
10620 | - public static function findCollection( $type, $sql = NULL, $bindings = array() ) |
|
10620 | + public static function findCollection($type, $sql = NULL, $bindings = array()) |
|
10621 | 10621 | { |
10622 | - return self::$finder->findCollection( $type, $sql, $bindings ); |
|
10622 | + return self::$finder->findCollection($type, $sql, $bindings); |
|
10623 | 10623 | } |
10624 | 10624 | |
10625 | 10625 | /** |
@@ -10636,9 +10636,9 @@ discard block |
||
10636 | 10636 | * |
10637 | 10637 | * @return array |
10638 | 10638 | */ |
10639 | - public static function findMulti( $types, $sql, $bindings = array(), $remappings = array() ) |
|
10639 | + public static function findMulti($types, $sql, $bindings = array(), $remappings = array()) |
|
10640 | 10640 | { |
10641 | - return self::$finder->findMulti( $types, $sql, $bindings, $remappings ); |
|
10641 | + return self::$finder->findMulti($types, $sql, $bindings, $remappings); |
|
10642 | 10642 | } |
10643 | 10643 | |
10644 | 10644 | /** |
@@ -10655,9 +10655,9 @@ discard block |
||
10655 | 10655 | * |
10656 | 10656 | * @return array |
10657 | 10657 | */ |
10658 | - public static function batch( $type, $ids ) |
|
10658 | + public static function batch($type, $ids) |
|
10659 | 10659 | { |
10660 | - return self::$redbean->batch( $type, $ids ); |
|
10660 | + return self::$redbean->batch($type, $ids); |
|
10661 | 10661 | } |
10662 | 10662 | |
10663 | 10663 | /** |
@@ -10673,9 +10673,9 @@ discard block |
||
10673 | 10673 | * |
10674 | 10674 | * @return array |
10675 | 10675 | */ |
10676 | - public static function loadAll( $type, $ids ) |
|
10676 | + public static function loadAll($type, $ids) |
|
10677 | 10677 | { |
10678 | - return self::$redbean->batch( $type, $ids ); |
|
10678 | + return self::$redbean->batch($type, $ids); |
|
10679 | 10679 | } |
10680 | 10680 | |
10681 | 10681 | /** |
@@ -10687,9 +10687,9 @@ discard block |
||
10687 | 10687 | * |
10688 | 10688 | * @return integer |
10689 | 10689 | */ |
10690 | - public static function exec( $sql, $bindings = array() ) |
|
10690 | + public static function exec($sql, $bindings = array()) |
|
10691 | 10691 | { |
10692 | - return self::query( 'exec', $sql, $bindings ); |
|
10692 | + return self::query('exec', $sql, $bindings); |
|
10693 | 10693 | } |
10694 | 10694 | |
10695 | 10695 | /** |
@@ -10701,9 +10701,9 @@ discard block |
||
10701 | 10701 | * |
10702 | 10702 | * @return array |
10703 | 10703 | */ |
10704 | - public static function getAll( $sql, $bindings = array() ) |
|
10704 | + public static function getAll($sql, $bindings = array()) |
|
10705 | 10705 | { |
10706 | - return self::query( 'get', $sql, $bindings ); |
|
10706 | + return self::query('get', $sql, $bindings); |
|
10707 | 10707 | } |
10708 | 10708 | |
10709 | 10709 | /** |
@@ -10715,9 +10715,9 @@ discard block |
||
10715 | 10715 | * |
10716 | 10716 | * @return string |
10717 | 10717 | */ |
10718 | - public static function getCell( $sql, $bindings = array() ) |
|
10718 | + public static function getCell($sql, $bindings = array()) |
|
10719 | 10719 | { |
10720 | - return self::query( 'getCell', $sql, $bindings ); |
|
10720 | + return self::query('getCell', $sql, $bindings); |
|
10721 | 10721 | } |
10722 | 10722 | |
10723 | 10723 | /** |
@@ -10729,9 +10729,9 @@ discard block |
||
10729 | 10729 | * |
10730 | 10730 | * @return array |
10731 | 10731 | */ |
10732 | - public static function getRow( $sql, $bindings = array() ) |
|
10732 | + public static function getRow($sql, $bindings = array()) |
|
10733 | 10733 | { |
10734 | - return self::query( 'getRow', $sql, $bindings ); |
|
10734 | + return self::query('getRow', $sql, $bindings); |
|
10735 | 10735 | } |
10736 | 10736 | |
10737 | 10737 | /** |
@@ -10743,9 +10743,9 @@ discard block |
||
10743 | 10743 | * |
10744 | 10744 | * @return array |
10745 | 10745 | */ |
10746 | - public static function getCol( $sql, $bindings = array() ) |
|
10746 | + public static function getCol($sql, $bindings = array()) |
|
10747 | 10747 | { |
10748 | - return self::query( 'getCol', $sql, $bindings ); |
|
10748 | + return self::query('getCol', $sql, $bindings); |
|
10749 | 10749 | } |
10750 | 10750 | |
10751 | 10751 | /** |
@@ -10762,9 +10762,9 @@ discard block |
||
10762 | 10762 | * |
10763 | 10763 | * @return array |
10764 | 10764 | */ |
10765 | - public static function getAssoc( $sql, $bindings = array() ) |
|
10765 | + public static function getAssoc($sql, $bindings = array()) |
|
10766 | 10766 | { |
10767 | - return self::query( 'getAssoc', $sql, $bindings ); |
|
10767 | + return self::query('getAssoc', $sql, $bindings); |
|
10768 | 10768 | } |
10769 | 10769 | |
10770 | 10770 | /** |
@@ -10778,9 +10778,9 @@ discard block |
||
10778 | 10778 | * |
10779 | 10779 | * @return array |
10780 | 10780 | */ |
10781 | - public static function getAssocRow( $sql, $bindings = array() ) |
|
10781 | + public static function getAssocRow($sql, $bindings = array()) |
|
10782 | 10782 | { |
10783 | - return self::query( 'getAssocRow', $sql, $bindings ); |
|
10783 | + return self::query('getAssocRow', $sql, $bindings); |
|
10784 | 10784 | } |
10785 | 10785 | |
10786 | 10786 | /** |
@@ -10820,10 +10820,10 @@ discard block |
||
10820 | 10820 | * |
10821 | 10821 | * @return array |
10822 | 10822 | */ |
10823 | - public static function dup( $bean, $trail = array(), $pid = FALSE, $filters = array() ) |
|
10823 | + public static function dup($bean, $trail = array(), $pid = FALSE, $filters = array()) |
|
10824 | 10824 | { |
10825 | - self::$duplicationManager->setFilters( $filters ); |
|
10826 | - return self::$duplicationManager->dup( $bean, $trail, $pid ); |
|
10825 | + self::$duplicationManager->setFilters($filters); |
|
10826 | + return self::$duplicationManager->dup($bean, $trail, $pid); |
|
10827 | 10827 | } |
10828 | 10828 | |
10829 | 10829 | /** |
@@ -10850,9 +10850,9 @@ discard block |
||
10850 | 10850 | * |
10851 | 10851 | * @return array |
10852 | 10852 | */ |
10853 | - public static function duplicate( $bean, $filters = array() ) |
|
10853 | + public static function duplicate($bean, $filters = array()) |
|
10854 | 10854 | { |
10855 | - return self::dup( $bean, array(), FALSE, $filters ); |
|
10855 | + return self::dup($bean, array(), FALSE, $filters); |
|
10856 | 10856 | } |
10857 | 10857 | |
10858 | 10858 | /** |
@@ -10869,9 +10869,9 @@ discard block |
||
10869 | 10869 | * |
10870 | 10870 | * @return array |
10871 | 10871 | */ |
10872 | - public static function exportAll( $beans, $parents = FALSE, $filters = array()) |
|
10872 | + public static function exportAll($beans, $parents = FALSE, $filters = array()) |
|
10873 | 10873 | { |
10874 | - return self::$duplicationManager->exportAll( $beans, $parents, $filters, self::$exportCaseStyle ); |
|
10874 | + return self::$duplicationManager->exportAll($beans, $parents, $filters, self::$exportCaseStyle); |
|
10875 | 10875 | } |
10876 | 10876 | |
10877 | 10877 | /** |
@@ -10892,9 +10892,9 @@ discard block |
||
10892 | 10892 | * |
10893 | 10893 | * @return void |
10894 | 10894 | */ |
10895 | - public static function useExportCase( $caseStyle = 'default' ) |
|
10895 | + public static function useExportCase($caseStyle = 'default') |
|
10896 | 10896 | { |
10897 | - if ( !in_array( $caseStyle, array( 'default', 'camel', 'dolphin' ) ) ) throw new RedException( 'Invalid case selected.' ); |
|
10897 | + if (!in_array($caseStyle, array('default', 'camel', 'dolphin'))) throw new RedException('Invalid case selected.'); |
|
10898 | 10898 | self::$exportCaseStyle = $caseStyle; |
10899 | 10899 | } |
10900 | 10900 | |
@@ -10910,9 +10910,9 @@ discard block |
||
10910 | 10910 | * |
10911 | 10911 | * @return array |
10912 | 10912 | */ |
10913 | - public static function convertToBeans( $type, $rows ) |
|
10913 | + public static function convertToBeans($type, $rows) |
|
10914 | 10914 | { |
10915 | - return self::$redbean->convertToBeans( $type, $rows ); |
|
10915 | + return self::$redbean->convertToBeans($type, $rows); |
|
10916 | 10916 | } |
10917 | 10917 | |
10918 | 10918 | /** |
@@ -10931,9 +10931,9 @@ discard block |
||
10931 | 10931 | * |
10932 | 10932 | * @return boolean |
10933 | 10933 | */ |
10934 | - public static function hasTag( $bean, $tags, $all = FALSE ) |
|
10934 | + public static function hasTag($bean, $tags, $all = FALSE) |
|
10935 | 10935 | { |
10936 | - return self::$tagManager->hasTag( $bean, $tags, $all ); |
|
10936 | + return self::$tagManager->hasTag($bean, $tags, $all); |
|
10937 | 10937 | } |
10938 | 10938 | |
10939 | 10939 | /** |
@@ -10946,9 +10946,9 @@ discard block |
||
10946 | 10946 | * |
10947 | 10947 | * @return void |
10948 | 10948 | */ |
10949 | - public static function untag( $bean, $tagList ) |
|
10949 | + public static function untag($bean, $tagList) |
|
10950 | 10950 | { |
10951 | - self::$tagManager->untag( $bean, $tagList ); |
|
10951 | + self::$tagManager->untag($bean, $tagList); |
|
10952 | 10952 | } |
10953 | 10953 | |
10954 | 10954 | /** |
@@ -10965,9 +10965,9 @@ discard block |
||
10965 | 10965 | * |
10966 | 10966 | * @return string |
10967 | 10967 | */ |
10968 | - public static function tag( OODBBean $bean, $tagList = NULL ) |
|
10968 | + public static function tag(OODBBean $bean, $tagList = NULL) |
|
10969 | 10969 | { |
10970 | - return self::$tagManager->tag( $bean, $tagList ); |
|
10970 | + return self::$tagManager->tag($bean, $tagList); |
|
10971 | 10971 | } |
10972 | 10972 | |
10973 | 10973 | /** |
@@ -10982,9 +10982,9 @@ discard block |
||
10982 | 10982 | * |
10983 | 10983 | * @return void |
10984 | 10984 | */ |
10985 | - public static function addTags( OODBBean $bean, $tagList ) |
|
10985 | + public static function addTags(OODBBean $bean, $tagList) |
|
10986 | 10986 | { |
10987 | - self::$tagManager->addTags( $bean, $tagList ); |
|
10987 | + self::$tagManager->addTags($bean, $tagList); |
|
10988 | 10988 | } |
10989 | 10989 | |
10990 | 10990 | /** |
@@ -10998,9 +10998,9 @@ discard block |
||
10998 | 10998 | * |
10999 | 10999 | * @return array |
11000 | 11000 | */ |
11001 | - public static function tagged( $beanType, $tagList, $sql = '', $bindings = array() ) |
|
11001 | + public static function tagged($beanType, $tagList, $sql = '', $bindings = array()) |
|
11002 | 11002 | { |
11003 | - return self::$tagManager->tagged( $beanType, $tagList, $sql, $bindings ); |
|
11003 | + return self::$tagManager->tagged($beanType, $tagList, $sql, $bindings); |
|
11004 | 11004 | } |
11005 | 11005 | |
11006 | 11006 | /** |
@@ -11014,9 +11014,9 @@ discard block |
||
11014 | 11014 | * |
11015 | 11015 | * @return array |
11016 | 11016 | */ |
11017 | - public static function taggedAll( $beanType, $tagList, $sql = '', $bindings = array() ) |
|
11017 | + public static function taggedAll($beanType, $tagList, $sql = '', $bindings = array()) |
|
11018 | 11018 | { |
11019 | - return self::$tagManager->taggedAll( $beanType, $tagList, $sql, $bindings ); |
|
11019 | + return self::$tagManager->taggedAll($beanType, $tagList, $sql, $bindings); |
|
11020 | 11020 | } |
11021 | 11021 | |
11022 | 11022 | /** |
@@ -11026,9 +11026,9 @@ discard block |
||
11026 | 11026 | * |
11027 | 11027 | * @return boolean |
11028 | 11028 | */ |
11029 | - public static function wipe( $beanType ) |
|
11029 | + public static function wipe($beanType) |
|
11030 | 11030 | { |
11031 | - return Facade::$redbean->wipe( $beanType ); |
|
11031 | + return Facade::$redbean->wipe($beanType); |
|
11032 | 11032 | } |
11033 | 11033 | |
11034 | 11034 | /** |
@@ -11044,9 +11044,9 @@ discard block |
||
11044 | 11044 | * |
11045 | 11045 | * @throws SQL |
11046 | 11046 | */ |
11047 | - public static function count( $type, $addSQL = '', $bindings = array() ) |
|
11047 | + public static function count($type, $addSQL = '', $bindings = array()) |
|
11048 | 11048 | { |
11049 | - return Facade::$redbean->count( $type, $addSQL, $bindings ); |
|
11049 | + return Facade::$redbean->count($type, $addSQL, $bindings); |
|
11050 | 11050 | } |
11051 | 11051 | |
11052 | 11052 | /** |
@@ -11058,7 +11058,7 @@ discard block |
||
11058 | 11058 | * |
11059 | 11059 | * @return ToolBox |
11060 | 11060 | */ |
11061 | - public static function configureFacadeWithToolbox( ToolBox $tb ) |
|
11061 | + public static function configureFacadeWithToolbox(ToolBox $tb) |
|
11062 | 11062 | { |
11063 | 11063 | $oldTools = self::$toolbox; |
11064 | 11064 | |
@@ -11067,22 +11067,22 @@ discard block |
||
11067 | 11067 | self::$writer = self::$toolbox->getWriter(); |
11068 | 11068 | self::$adapter = self::$toolbox->getDatabaseAdapter(); |
11069 | 11069 | self::$redbean = self::$toolbox->getRedBean(); |
11070 | - self::$finder = new Finder( self::$toolbox ); |
|
11070 | + self::$finder = new Finder(self::$toolbox); |
|
11071 | 11071 | |
11072 | - self::$associationManager = new AssociationManager( self::$toolbox ); |
|
11072 | + self::$associationManager = new AssociationManager(self::$toolbox); |
|
11073 | 11073 | |
11074 | - self::$redbean->setAssociationManager( self::$associationManager ); |
|
11074 | + self::$redbean->setAssociationManager(self::$associationManager); |
|
11075 | 11075 | |
11076 | - self::$labelMaker = new LabelMaker( self::$toolbox ); |
|
11076 | + self::$labelMaker = new LabelMaker(self::$toolbox); |
|
11077 | 11077 | |
11078 | 11078 | $helper = new SimpleModelHelper(); |
11079 | 11079 | |
11080 | - $helper->attachEventListeners( self::$redbean ); |
|
11080 | + $helper->attachEventListeners(self::$redbean); |
|
11081 | 11081 | |
11082 | - self::$redbean->setBeanHelper( new SimpleFacadeBeanHelper ); |
|
11082 | + self::$redbean->setBeanHelper(new SimpleFacadeBeanHelper); |
|
11083 | 11083 | |
11084 | - self::$duplicationManager = new DuplicationManager( self::$toolbox ); |
|
11085 | - self::$tagManager = new TagManager( self::$toolbox ); |
|
11084 | + self::$duplicationManager = new DuplicationManager(self::$toolbox); |
|
11085 | + self::$tagManager = new TagManager(self::$toolbox); |
|
11086 | 11086 | |
11087 | 11087 | return $oldTools; |
11088 | 11088 | } |
@@ -11095,7 +11095,7 @@ discard block |
||
11095 | 11095 | */ |
11096 | 11096 | public static function begin() |
11097 | 11097 | { |
11098 | - if ( !self::$redbean->isFrozen() ) return FALSE; |
|
11098 | + if (!self::$redbean->isFrozen()) return FALSE; |
|
11099 | 11099 | |
11100 | 11100 | self::$adapter->startTransaction(); |
11101 | 11101 | |
@@ -11110,7 +11110,7 @@ discard block |
||
11110 | 11110 | */ |
11111 | 11111 | public static function commit() |
11112 | 11112 | { |
11113 | - if ( !self::$redbean->isFrozen() ) return FALSE; |
|
11113 | + if (!self::$redbean->isFrozen()) return FALSE; |
|
11114 | 11114 | |
11115 | 11115 | self::$adapter->commit(); |
11116 | 11116 | |
@@ -11125,7 +11125,7 @@ discard block |
||
11125 | 11125 | */ |
11126 | 11126 | public static function rollback() |
11127 | 11127 | { |
11128 | - if ( !self::$redbean->isFrozen() ) return FALSE; |
|
11128 | + if (!self::$redbean->isFrozen()) return FALSE; |
|
11129 | 11129 | |
11130 | 11130 | self::$adapter->rollback(); |
11131 | 11131 | |
@@ -11142,9 +11142,9 @@ discard block |
||
11142 | 11142 | * |
11143 | 11143 | * @return array |
11144 | 11144 | */ |
11145 | - public static function getColumns( $table ) |
|
11145 | + public static function getColumns($table) |
|
11146 | 11146 | { |
11147 | - return self::$writer->getColumns( $table ); |
|
11147 | + return self::$writer->getColumns($table); |
|
11148 | 11148 | } |
11149 | 11149 | |
11150 | 11150 | /** |
@@ -11154,10 +11154,10 @@ discard block |
||
11154 | 11154 | * |
11155 | 11155 | * @return string |
11156 | 11156 | */ |
11157 | - public static function genSlots( $array, $template = NULL ) |
|
11157 | + public static function genSlots($array, $template = NULL) |
|
11158 | 11158 | { |
11159 | - $str = count( $array ) ? implode( ',', array_fill( 0, count( $array ), '?' ) ) : ''; |
|
11160 | - return ( is_null( $template ) || $str === '' ) ? $str : sprintf( $template, $str ); |
|
11159 | + $str = count($array) ? implode(',', array_fill(0, count($array), '?')) : ''; |
|
11160 | + return (is_null($template) || $str === '') ? $str : sprintf($template, $str); |
|
11161 | 11161 | } |
11162 | 11162 | |
11163 | 11163 | /** |
@@ -11167,10 +11167,10 @@ discard block |
||
11167 | 11167 | * |
11168 | 11168 | * @return array |
11169 | 11169 | */ |
11170 | - public static function flat( $array, $result = array() ) |
|
11170 | + public static function flat($array, $result = array()) |
|
11171 | 11171 | { |
11172 | - foreach( $array as $value ) { |
|
11173 | - if ( is_array( $value ) ) $result = self::flat( $value, $result ); |
|
11172 | + foreach ($array as $value) { |
|
11173 | + if (is_array($value)) $result = self::flat($value, $result); |
|
11174 | 11174 | else $result[] = $value; |
11175 | 11175 | } |
11176 | 11176 | return $result; |
@@ -11187,7 +11187,7 @@ discard block |
||
11187 | 11187 | */ |
11188 | 11188 | public static function nuke() |
11189 | 11189 | { |
11190 | - if ( !self::$redbean->isFrozen() ) { |
|
11190 | + if (!self::$redbean->isFrozen()) { |
|
11191 | 11191 | self::$writer->wipeAll(); |
11192 | 11192 | } |
11193 | 11193 | } |
@@ -11202,11 +11202,11 @@ discard block |
||
11202 | 11202 | * |
11203 | 11203 | * @return array |
11204 | 11204 | */ |
11205 | - public static function storeAll( $beans ) |
|
11205 | + public static function storeAll($beans) |
|
11206 | 11206 | { |
11207 | 11207 | $ids = array(); |
11208 | - foreach ( $beans as $bean ) { |
|
11209 | - $ids[] = self::store( $bean ); |
|
11208 | + foreach ($beans as $bean) { |
|
11209 | + $ids[] = self::store($bean); |
|
11210 | 11210 | } |
11211 | 11211 | |
11212 | 11212 | return $ids; |
@@ -11221,10 +11221,10 @@ discard block |
||
11221 | 11221 | * |
11222 | 11222 | * @return void |
11223 | 11223 | */ |
11224 | - public static function trashAll( $beans ) |
|
11224 | + public static function trashAll($beans) |
|
11225 | 11225 | { |
11226 | - foreach ( $beans as $bean ) { |
|
11227 | - self::trash( $bean ); |
|
11226 | + foreach ($beans as $bean) { |
|
11227 | + self::trash($bean); |
|
11228 | 11228 | } |
11229 | 11229 | } |
11230 | 11230 | |
@@ -11243,9 +11243,9 @@ discard block |
||
11243 | 11243 | * |
11244 | 11244 | * @return void |
11245 | 11245 | */ |
11246 | - public static function useWriterCache( $yesNo ) |
|
11246 | + public static function useWriterCache($yesNo) |
|
11247 | 11247 | { |
11248 | - self::getWriter()->setUseCache( $yesNo ); |
|
11248 | + self::getWriter()->setUseCache($yesNo); |
|
11249 | 11249 | } |
11250 | 11250 | |
11251 | 11251 | |
@@ -11260,9 +11260,9 @@ discard block |
||
11260 | 11260 | * |
11261 | 11261 | * @return array |
11262 | 11262 | */ |
11263 | - public static function dispenseLabels( $type, $labels ) |
|
11263 | + public static function dispenseLabels($type, $labels) |
|
11264 | 11264 | { |
11265 | - return self::$labelMaker->dispenseLabels( $type, $labels ); |
|
11265 | + return self::$labelMaker->dispenseLabels($type, $labels); |
|
11266 | 11266 | } |
11267 | 11267 | |
11268 | 11268 | /** |
@@ -11290,9 +11290,9 @@ discard block |
||
11290 | 11290 | * |
11291 | 11291 | * @return array|OODBBean |
11292 | 11292 | */ |
11293 | - public static function enum( $enum ) |
|
11293 | + public static function enum($enum) |
|
11294 | 11294 | { |
11295 | - return self::$labelMaker->enum( $enum ); |
|
11295 | + return self::$labelMaker->enum($enum); |
|
11296 | 11296 | } |
11297 | 11297 | |
11298 | 11298 | /** |
@@ -11305,9 +11305,9 @@ discard block |
||
11305 | 11305 | * |
11306 | 11306 | * @return array |
11307 | 11307 | */ |
11308 | - public static function gatherLabels( $beans ) |
|
11308 | + public static function gatherLabels($beans) |
|
11309 | 11309 | { |
11310 | - return self::$labelMaker->gatherLabels( $beans ); |
|
11310 | + return self::$labelMaker->gatherLabels($beans); |
|
11311 | 11311 | } |
11312 | 11312 | |
11313 | 11313 | /** |
@@ -11317,7 +11317,7 @@ discard block |
||
11317 | 11317 | */ |
11318 | 11318 | public static function close() |
11319 | 11319 | { |
11320 | - if ( isset( self::$adapter ) ) { |
|
11320 | + if (isset(self::$adapter)) { |
|
11321 | 11321 | self::$adapter->close(); |
11322 | 11322 | } |
11323 | 11323 | } |
@@ -11330,13 +11330,13 @@ discard block |
||
11330 | 11330 | * |
11331 | 11331 | * @return string |
11332 | 11332 | */ |
11333 | - public static function isoDate( $time = NULL ) |
|
11333 | + public static function isoDate($time = NULL) |
|
11334 | 11334 | { |
11335 | - if ( !$time ) { |
|
11335 | + if (!$time) { |
|
11336 | 11336 | $time = time(); |
11337 | 11337 | } |
11338 | 11338 | |
11339 | - return @date( 'Y-m-d', $time ); |
|
11339 | + return @date('Y-m-d', $time); |
|
11340 | 11340 | } |
11341 | 11341 | |
11342 | 11342 | /** |
@@ -11348,11 +11348,11 @@ discard block |
||
11348 | 11348 | * |
11349 | 11349 | * @return string |
11350 | 11350 | */ |
11351 | - public static function isoDateTime( $time = NULL ) |
|
11351 | + public static function isoDateTime($time = NULL) |
|
11352 | 11352 | { |
11353 | - if ( !$time ) $time = time(); |
|
11353 | + if (!$time) $time = time(); |
|
11354 | 11354 | |
11355 | - return @date( 'Y-m-d H:i:s', $time ); |
|
11355 | + return @date('Y-m-d H:i:s', $time); |
|
11356 | 11356 | } |
11357 | 11357 | |
11358 | 11358 | /** |
@@ -11363,7 +11363,7 @@ discard block |
||
11363 | 11363 | * |
11364 | 11364 | * @return void |
11365 | 11365 | */ |
11366 | - public static function setDatabaseAdapter( Adapter $adapter ) |
|
11366 | + public static function setDatabaseAdapter(Adapter $adapter) |
|
11367 | 11367 | { |
11368 | 11368 | self::$adapter = $adapter; |
11369 | 11369 | } |
@@ -11376,7 +11376,7 @@ discard block |
||
11376 | 11376 | * |
11377 | 11377 | * @return void |
11378 | 11378 | */ |
11379 | - public static function setWriter( QueryWriter $writer ) |
|
11379 | + public static function setWriter(QueryWriter $writer) |
|
11380 | 11380 | { |
11381 | 11381 | self::$writer = $writer; |
11382 | 11382 | } |
@@ -11387,7 +11387,7 @@ discard block |
||
11387 | 11387 | * |
11388 | 11388 | * @param OODB $redbean |
11389 | 11389 | */ |
11390 | - public static function setRedBean( OODB $redbean ) |
|
11390 | + public static function setRedBean(OODB $redbean) |
|
11391 | 11391 | { |
11392 | 11392 | self::$redbean = $redbean; |
11393 | 11393 | } |
@@ -11481,9 +11481,9 @@ discard block |
||
11481 | 11481 | * |
11482 | 11482 | * @return void |
11483 | 11483 | */ |
11484 | - public static function renameAssociation( $from, $to = NULL ) |
|
11484 | + public static function renameAssociation($from, $to = NULL) |
|
11485 | 11485 | { |
11486 | - AQueryWriter::renameAssociation( $from, $to ); |
|
11486 | + AQueryWriter::renameAssociation($from, $to); |
|
11487 | 11487 | } |
11488 | 11488 | |
11489 | 11489 | /** |
@@ -11497,10 +11497,10 @@ discard block |
||
11497 | 11497 | * |
11498 | 11498 | * @return array |
11499 | 11499 | */ |
11500 | - public static function beansToArray( $beans ) |
|
11500 | + public static function beansToArray($beans) |
|
11501 | 11501 | { |
11502 | 11502 | $list = array(); |
11503 | - foreach( $beans as $bean ) { |
|
11503 | + foreach ($beans as $bean) { |
|
11504 | 11504 | $list[] = $bean->export(); |
11505 | 11505 | } |
11506 | 11506 | return $list; |
@@ -11532,9 +11532,9 @@ discard block |
||
11532 | 11532 | * |
11533 | 11533 | * @return array |
11534 | 11534 | */ |
11535 | - public static function setErrorHandlingFUSE( $mode, $func = NULL ) |
|
11535 | + public static function setErrorHandlingFUSE($mode, $func = NULL) |
|
11536 | 11536 | { |
11537 | - return OODBBean::setErrorHandlingFUSE( $mode, $func ); |
|
11537 | + return OODBBean::setErrorHandlingFUSE($mode, $func); |
|
11538 | 11538 | } |
11539 | 11539 | |
11540 | 11540 | /** |
@@ -11548,23 +11548,23 @@ discard block |
||
11548 | 11548 | * @return array |
11549 | 11549 | * |
11550 | 11550 | */ |
11551 | - public static function dump( $data ) |
|
11551 | + public static function dump($data) |
|
11552 | 11552 | { |
11553 | 11553 | $array = array(); |
11554 | 11554 | |
11555 | - if ( $data instanceof OODBBean ) { |
|
11556 | - $str = strval( $data ); |
|
11555 | + if ($data instanceof OODBBean) { |
|
11556 | + $str = strval($data); |
|
11557 | 11557 | if (strlen($str) > 35) { |
11558 | - $beanStr = substr( $str, 0, 35 ).'... '; |
|
11558 | + $beanStr = substr($str, 0, 35) . '... '; |
|
11559 | 11559 | } else { |
11560 | 11560 | $beanStr = $str; |
11561 | 11561 | } |
11562 | 11562 | return $beanStr; |
11563 | 11563 | } |
11564 | 11564 | |
11565 | - if ( is_array( $data ) ) { |
|
11566 | - foreach( $data as $key => $item ) { |
|
11567 | - $array[$key] = self::dump( $item ); |
|
11565 | + if (is_array($data)) { |
|
11566 | + foreach ($data as $key => $item) { |
|
11567 | + $array[$key] = self::dump($item); |
|
11568 | 11568 | } |
11569 | 11569 | } |
11570 | 11570 | |
@@ -11591,9 +11591,9 @@ discard block |
||
11591 | 11591 | * @param string $function |
11592 | 11592 | * |
11593 | 11593 | */ |
11594 | - public static function bindFunc( $mode, $field, $function ) |
|
11594 | + public static function bindFunc($mode, $field, $function) |
|
11595 | 11595 | { |
11596 | - self::$redbean->bindFunc( $mode, $field, $function ); |
|
11596 | + self::$redbean->bindFunc($mode, $field, $function); |
|
11597 | 11597 | } |
11598 | 11598 | |
11599 | 11599 | /** |
@@ -11603,9 +11603,9 @@ discard block |
||
11603 | 11603 | * |
11604 | 11604 | * @return void |
11605 | 11605 | */ |
11606 | - public static function aliases( $list ) |
|
11606 | + public static function aliases($list) |
|
11607 | 11607 | { |
11608 | - OODBBean::aliases( $list ); |
|
11608 | + OODBBean::aliases($list); |
|
11609 | 11609 | } |
11610 | 11610 | |
11611 | 11611 | /** |
@@ -11621,9 +11621,9 @@ discard block |
||
11621 | 11621 | * |
11622 | 11622 | * @return OODBBean |
11623 | 11623 | */ |
11624 | - public static function findOrCreate( $type, $like = array() ) |
|
11624 | + public static function findOrCreate($type, $like = array()) |
|
11625 | 11625 | { |
11626 | - return self::$finder->findOrCreate( $type, $like ); |
|
11626 | + return self::$finder->findOrCreate($type, $like); |
|
11627 | 11627 | } |
11628 | 11628 | |
11629 | 11629 | /** |
@@ -11639,9 +11639,9 @@ discard block |
||
11639 | 11639 | * |
11640 | 11640 | * @return array |
11641 | 11641 | */ |
11642 | - public static function findLike( $type, $like = array(), $sql = '' ) |
|
11642 | + public static function findLike($type, $like = array(), $sql = '') |
|
11643 | 11643 | { |
11644 | - return self::$finder->findLike( $type, $like, $sql ); |
|
11644 | + return self::$finder->findLike($type, $like, $sql); |
|
11645 | 11645 | } |
11646 | 11646 | |
11647 | 11647 | /** |
@@ -11657,7 +11657,7 @@ discard block |
||
11657 | 11657 | */ |
11658 | 11658 | public static function startLogging() |
11659 | 11659 | { |
11660 | - self::debug( TRUE, RDefault::C_LOGGER_ARRAY ); |
|
11660 | + self::debug(TRUE, RDefault::C_LOGGER_ARRAY); |
|
11661 | 11661 | } |
11662 | 11662 | |
11663 | 11663 | /** |
@@ -11667,7 +11667,7 @@ discard block |
||
11667 | 11667 | */ |
11668 | 11668 | public static function stopLogging() |
11669 | 11669 | { |
11670 | - self::debug( FALSE ); |
|
11670 | + self::debug(FALSE); |
|
11671 | 11671 | } |
11672 | 11672 | |
11673 | 11673 | /** |
@@ -11722,9 +11722,9 @@ discard block |
||
11722 | 11722 | * |
11723 | 11723 | * @return void |
11724 | 11724 | */ |
11725 | - public static function setAutoResolve( $automatic = TRUE ) |
|
11725 | + public static function setAutoResolve($automatic = TRUE) |
|
11726 | 11726 | { |
11727 | - OODBBean::setAutoResolve( (boolean) $automatic ); |
|
11727 | + OODBBean::setAutoResolve((boolean) $automatic); |
|
11728 | 11728 | } |
11729 | 11729 | |
11730 | 11730 | /** |
@@ -11744,10 +11744,10 @@ discard block |
||
11744 | 11744 | * @param string $pluginName name of the method to call the plugin |
11745 | 11745 | * @param callable $callable a PHP callable |
11746 | 11746 | */ |
11747 | - public static function ext( $pluginName, $callable ) |
|
11747 | + public static function ext($pluginName, $callable) |
|
11748 | 11748 | { |
11749 | - if ( !ctype_alnum( $pluginName ) ) { |
|
11750 | - throw new RedException( 'Plugin name may only contain alphanumeric characters.' ); |
|
11749 | + if (!ctype_alnum($pluginName)) { |
|
11750 | + throw new RedException('Plugin name may only contain alphanumeric characters.'); |
|
11751 | 11751 | } |
11752 | 11752 | self::$plugins[$pluginName] = $callable; |
11753 | 11753 | } |
@@ -11761,15 +11761,15 @@ discard block |
||
11761 | 11761 | * |
11762 | 11762 | * @return mixed |
11763 | 11763 | */ |
11764 | - public static function __callStatic( $pluginName, $params ) |
|
11764 | + public static function __callStatic($pluginName, $params) |
|
11765 | 11765 | { |
11766 | - if ( !ctype_alnum( $pluginName) ) { |
|
11767 | - throw new RedException( 'Plugin name may only contain alphanumeric characters.' ); |
|
11766 | + if (!ctype_alnum($pluginName)) { |
|
11767 | + throw new RedException('Plugin name may only contain alphanumeric characters.'); |
|
11768 | 11768 | } |
11769 | - if ( !isset( self::$plugins[$pluginName] ) ) { |
|
11770 | - throw new RedException( 'Plugin \''.$pluginName.'\' does not exist, add this plugin using: R::ext(\''.$pluginName.'\')' ); |
|
11769 | + if (!isset(self::$plugins[$pluginName])) { |
|
11770 | + throw new RedException('Plugin \'' . $pluginName . '\' does not exist, add this plugin using: R::ext(\'' . $pluginName . '\')'); |
|
11771 | 11771 | } |
11772 | - return call_user_func_array( self::$plugins[$pluginName], $params ); |
|
11772 | + return call_user_func_array(self::$plugins[$pluginName], $params); |
|
11773 | 11773 | } |
11774 | 11774 | } |
11775 | 11775 | |
@@ -11842,12 +11842,12 @@ discard block |
||
11842 | 11842 | * |
11843 | 11843 | * @return void |
11844 | 11844 | */ |
11845 | - private function copySharedBeans( OODBBean $copy, $shared, $beans ) |
|
11845 | + private function copySharedBeans(OODBBean $copy, $shared, $beans) |
|
11846 | 11846 | { |
11847 | 11847 | $copy->$shared = array(); |
11848 | 11848 | |
11849 | - foreach ( $beans as $subBean ) { |
|
11850 | - array_push( $copy->$shared, $subBean ); |
|
11849 | + foreach ($beans as $subBean) { |
|
11850 | + array_push($copy->$shared, $subBean); |
|
11851 | 11851 | } |
11852 | 11852 | } |
11853 | 11853 | |
@@ -11864,11 +11864,11 @@ discard block |
||
11864 | 11864 | * |
11865 | 11865 | * @return void |
11866 | 11866 | */ |
11867 | - private function copyOwnBeans( OODBBean $copy, $owned, $beans, $trail, $preserveIDs ) |
|
11867 | + private function copyOwnBeans(OODBBean $copy, $owned, $beans, $trail, $preserveIDs) |
|
11868 | 11868 | { |
11869 | 11869 | $copy->$owned = array(); |
11870 | - foreach ( $beans as $subBean ) { |
|
11871 | - array_push( $copy->$owned, $this->duplicate( $subBean, $trail, $preserveIDs ) ); |
|
11870 | + foreach ($beans as $subBean) { |
|
11871 | + array_push($copy->$owned, $this->duplicate($subBean, $trail, $preserveIDs)); |
|
11872 | 11872 | } |
11873 | 11873 | } |
11874 | 11874 | |
@@ -11881,14 +11881,14 @@ discard block |
||
11881 | 11881 | * |
11882 | 11882 | * @return OODBBean |
11883 | 11883 | */ |
11884 | - private function createCopy( OODBBean $bean ) |
|
11884 | + private function createCopy(OODBBean $bean) |
|
11885 | 11885 | { |
11886 | - $type = $bean->getMeta( 'type' ); |
|
11886 | + $type = $bean->getMeta('type'); |
|
11887 | 11887 | |
11888 | - $copy = $this->redbean->dispense( $type ); |
|
11889 | - $copy->setMeta( 'sys.dup-from-id', $bean->id ); |
|
11890 | - $copy->setMeta( 'sys.old-id', $bean->id ); |
|
11891 | - $copy->importFrom( $bean ); |
|
11888 | + $copy = $this->redbean->dispense($type); |
|
11889 | + $copy->setMeta('sys.dup-from-id', $bean->id); |
|
11890 | + $copy->setMeta('sys.old-id', $bean->id); |
|
11891 | + $copy->importFrom($bean); |
|
11892 | 11892 | $copy->id = 0; |
11893 | 11893 | |
11894 | 11894 | return $copy; |
@@ -11904,12 +11904,12 @@ discard block |
||
11904 | 11904 | * |
11905 | 11905 | * @return boolean |
11906 | 11906 | */ |
11907 | - private function inTrailOrAdd( &$trail, OODBBean $bean ) |
|
11907 | + private function inTrailOrAdd(&$trail, OODBBean $bean) |
|
11908 | 11908 | { |
11909 | - $type = $bean->getMeta( 'type' ); |
|
11909 | + $type = $bean->getMeta('type'); |
|
11910 | 11910 | $key = $type . $bean->getID(); |
11911 | 11911 | |
11912 | - if ( isset( $trail[$key] ) ) { |
|
11912 | + if (isset($trail[$key])) { |
|
11913 | 11913 | return TRUE; |
11914 | 11914 | } |
11915 | 11915 | |
@@ -11928,12 +11928,12 @@ discard block |
||
11928 | 11928 | * |
11929 | 11929 | * @return array |
11930 | 11930 | */ |
11931 | - private function getListNames( $typeName ) |
|
11931 | + private function getListNames($typeName) |
|
11932 | 11932 | { |
11933 | - $owned = 'own' . ucfirst( $typeName ); |
|
11934 | - $shared = 'shared' . ucfirst( $typeName ); |
|
11933 | + $owned = 'own' . ucfirst($typeName); |
|
11934 | + $shared = 'shared' . ucfirst($typeName); |
|
11935 | 11935 | |
11936 | - return array( $owned, $shared ); |
|
11936 | + return array($owned, $shared); |
|
11937 | 11937 | } |
11938 | 11938 | |
11939 | 11939 | /** |
@@ -11945,9 +11945,9 @@ discard block |
||
11945 | 11945 | * |
11946 | 11946 | * @return boolean |
11947 | 11947 | */ |
11948 | - protected function hasOwnList( $type, $target ) |
|
11948 | + protected function hasOwnList($type, $target) |
|
11949 | 11949 | { |
11950 | - return isset( $this->columns[$target][$type . '_id'] ); |
|
11950 | + return isset($this->columns[$target][$type . '_id']); |
|
11951 | 11951 | } |
11952 | 11952 | |
11953 | 11953 | /** |
@@ -11959,9 +11959,9 @@ discard block |
||
11959 | 11959 | * |
11960 | 11960 | * @return boolean |
11961 | 11961 | */ |
11962 | - protected function hasSharedList( $type, $target ) |
|
11962 | + protected function hasSharedList($type, $target) |
|
11963 | 11963 | { |
11964 | - return in_array( AQueryWriter::getAssocTableFormat( array( $type, $target ) ), $this->tables ); |
|
11964 | + return in_array(AQueryWriter::getAssocTableFormat(array($type, $target)), $this->tables); |
|
11965 | 11965 | } |
11966 | 11966 | |
11967 | 11967 | /** |
@@ -11973,37 +11973,37 @@ discard block |
||
11973 | 11973 | * |
11974 | 11974 | * @return OODBBean |
11975 | 11975 | */ |
11976 | - protected function duplicate( OODBBean $bean, $trail = array(), $preserveIDs = FALSE ) |
|
11976 | + protected function duplicate(OODBBean $bean, $trail = array(), $preserveIDs = FALSE) |
|
11977 | 11977 | { |
11978 | - if ( $this->inTrailOrAdd( $trail, $bean ) ) return $bean; |
|
11978 | + if ($this->inTrailOrAdd($trail, $bean)) return $bean; |
|
11979 | 11979 | |
11980 | - $type = $bean->getMeta( 'type' ); |
|
11980 | + $type = $bean->getMeta('type'); |
|
11981 | 11981 | |
11982 | - $copy = $this->createCopy( $bean ); |
|
11983 | - foreach ( $this->tables as $table ) { |
|
11982 | + $copy = $this->createCopy($bean); |
|
11983 | + foreach ($this->tables as $table) { |
|
11984 | 11984 | |
11985 | - if ( !empty( $this->filters ) ) { |
|
11986 | - if ( !in_array( $table, $this->filters ) ) continue; |
|
11985 | + if (!empty($this->filters)) { |
|
11986 | + if (!in_array($table, $this->filters)) continue; |
|
11987 | 11987 | } |
11988 | 11988 | |
11989 | - list( $owned, $shared ) = $this->getListNames( $table ); |
|
11989 | + list($owned, $shared) = $this->getListNames($table); |
|
11990 | 11990 | |
11991 | - if ( $this->hasSharedList( $type, $table ) ) { |
|
11992 | - if ( $beans = $bean->$shared ) { |
|
11993 | - $this->copySharedBeans( $copy, $shared, $beans ); |
|
11991 | + if ($this->hasSharedList($type, $table)) { |
|
11992 | + if ($beans = $bean->$shared) { |
|
11993 | + $this->copySharedBeans($copy, $shared, $beans); |
|
11994 | 11994 | } |
11995 | - } elseif ( $this->hasOwnList( $type, $table ) ) { |
|
11996 | - if ( $beans = $bean->$owned ) { |
|
11997 | - $this->copyOwnBeans( $copy, $owned, $beans, $trail, $preserveIDs ); |
|
11995 | + } elseif ($this->hasOwnList($type, $table)) { |
|
11996 | + if ($beans = $bean->$owned) { |
|
11997 | + $this->copyOwnBeans($copy, $owned, $beans, $trail, $preserveIDs); |
|
11998 | 11998 | } |
11999 | 11999 | |
12000 | - $copy->setMeta( 'sys.shadow.' . $owned, NULL ); |
|
12000 | + $copy->setMeta('sys.shadow.' . $owned, NULL); |
|
12001 | 12001 | } |
12002 | 12002 | |
12003 | - $copy->setMeta( 'sys.shadow.' . $shared, NULL ); |
|
12003 | + $copy->setMeta('sys.shadow.' . $shared, NULL); |
|
12004 | 12004 | } |
12005 | 12005 | |
12006 | - $copy->id = ( $preserveIDs ) ? $bean->id : $copy->id; |
|
12006 | + $copy->id = ($preserveIDs) ? $bean->id : $copy->id; |
|
12007 | 12007 | |
12008 | 12008 | return $copy; |
12009 | 12009 | } |
@@ -12014,7 +12014,7 @@ discard block |
||
12014 | 12014 | * |
12015 | 12015 | * @param ToolBox $toolbox |
12016 | 12016 | */ |
12017 | - public function __construct( ToolBox $toolbox ) |
|
12017 | + public function __construct(ToolBox $toolbox) |
|
12018 | 12018 | { |
12019 | 12019 | $this->toolbox = $toolbox; |
12020 | 12020 | $this->redbean = $toolbox->getRedBean(); |
@@ -12030,18 +12030,18 @@ discard block |
||
12030 | 12030 | * |
12031 | 12031 | * @return array |
12032 | 12032 | */ |
12033 | - public function camelfy( $array, $dolphinMode = false ) { |
|
12033 | + public function camelfy($array, $dolphinMode = false) { |
|
12034 | 12034 | $newArray = array(); |
12035 | - foreach( $array as $key => $element ) { |
|
12036 | - $newKey = preg_replace_callback( '/_(\w)/', function( &$matches ){ |
|
12037 | - return strtoupper( $matches[1] ); |
|
12035 | + foreach ($array as $key => $element) { |
|
12036 | + $newKey = preg_replace_callback('/_(\w)/', function(&$matches) { |
|
12037 | + return strtoupper($matches[1]); |
|
12038 | 12038 | }, $key); |
12039 | 12039 | |
12040 | - if ( $dolphinMode ) { |
|
12041 | - $newKey = preg_replace( '/(\w)Id$/', '$1ID', $newKey ); |
|
12040 | + if ($dolphinMode) { |
|
12041 | + $newKey = preg_replace('/(\w)Id$/', '$1ID', $newKey); |
|
12042 | 12042 | } |
12043 | 12043 | |
12044 | - $newArray[$newKey] = ( is_array($element) ) ? $this->camelfy( $element, $dolphinMode ) : $element; |
|
12044 | + $newArray[$newKey] = (is_array($element)) ? $this->camelfy($element, $dolphinMode) : $element; |
|
12045 | 12045 | } |
12046 | 12046 | return $newArray; |
12047 | 12047 | } |
@@ -12063,10 +12063,10 @@ discard block |
||
12063 | 12063 | * |
12064 | 12064 | * @return void |
12065 | 12065 | */ |
12066 | - public function setTables( $tables ) |
|
12066 | + public function setTables($tables) |
|
12067 | 12067 | { |
12068 | - foreach ( $tables as $key => $value ) { |
|
12069 | - if ( is_numeric( $key ) ) { |
|
12068 | + foreach ($tables as $key => $value) { |
|
12069 | + if (is_numeric($key)) { |
|
12070 | 12070 | $this->tables[] = $value; |
12071 | 12071 | } else { |
12072 | 12072 | $this->tables[] = $key; |
@@ -12097,7 +12097,7 @@ discard block |
||
12097 | 12097 | * |
12098 | 12098 | * @param boolean $yesNo TRUE to use caching, FALSE otherwise |
12099 | 12099 | */ |
12100 | - public function setCacheTables( $yesNo ) |
|
12100 | + public function setCacheTables($yesNo) |
|
12101 | 12101 | { |
12102 | 12102 | $this->cacheTables = $yesNo; |
12103 | 12103 | } |
@@ -12111,10 +12111,10 @@ discard block |
||
12111 | 12111 | * |
12112 | 12112 | * @param array $filters list of tables to be filtered |
12113 | 12113 | */ |
12114 | - public function setFilters( $filters ) |
|
12114 | + public function setFilters($filters) |
|
12115 | 12115 | { |
12116 | - if ( !is_array( $filters ) ) { |
|
12117 | - $filters = array( $filters ); |
|
12116 | + if (!is_array($filters)) { |
|
12117 | + $filters = array($filters); |
|
12118 | 12118 | } |
12119 | 12119 | |
12120 | 12120 | $this->filters = $filters; |
@@ -12145,21 +12145,21 @@ discard block |
||
12145 | 12145 | * |
12146 | 12146 | * @return OODBBean |
12147 | 12147 | */ |
12148 | - public function dup( OODBBean $bean, $trail = array(), $preserveIDs = FALSE ) |
|
12148 | + public function dup(OODBBean $bean, $trail = array(), $preserveIDs = FALSE) |
|
12149 | 12149 | { |
12150 | - if ( !count( $this->tables ) ) { |
|
12150 | + if (!count($this->tables)) { |
|
12151 | 12151 | $this->tables = $this->toolbox->getWriter()->getTables(); |
12152 | 12152 | } |
12153 | 12153 | |
12154 | - if ( !count( $this->columns ) ) { |
|
12155 | - foreach ( $this->tables as $table ) { |
|
12156 | - $this->columns[$table] = $this->toolbox->getWriter()->getColumns( $table ); |
|
12154 | + if (!count($this->columns)) { |
|
12155 | + foreach ($this->tables as $table) { |
|
12156 | + $this->columns[$table] = $this->toolbox->getWriter()->getColumns($table); |
|
12157 | 12157 | } |
12158 | 12158 | } |
12159 | 12159 | |
12160 | - $rs = $this->duplicate( ( clone $bean ), $trail, $preserveIDs ); |
|
12160 | + $rs = $this->duplicate((clone $bean), $trail, $preserveIDs); |
|
12161 | 12161 | |
12162 | - if ( !$this->cacheTables ) { |
|
12162 | + if (!$this->cacheTables) { |
|
12163 | 12163 | $this->tables = array(); |
12164 | 12164 | $this->columns = array(); |
12165 | 12165 | } |
@@ -12200,24 +12200,24 @@ discard block |
||
12200 | 12200 | * |
12201 | 12201 | * @return array |
12202 | 12202 | */ |
12203 | - public function exportAll( $beans, $parents = FALSE, $filters = array(), $caseStyle = 'snake') |
|
12203 | + public function exportAll($beans, $parents = FALSE, $filters = array(), $caseStyle = 'snake') |
|
12204 | 12204 | { |
12205 | 12205 | $array = array(); |
12206 | 12206 | |
12207 | - if ( !is_array( $beans ) ) { |
|
12208 | - $beans = array( $beans ); |
|
12207 | + if (!is_array($beans)) { |
|
12208 | + $beans = array($beans); |
|
12209 | 12209 | } |
12210 | 12210 | |
12211 | - foreach ( $beans as $bean ) { |
|
12212 | - $this->setFilters( $filters ); |
|
12211 | + foreach ($beans as $bean) { |
|
12212 | + $this->setFilters($filters); |
|
12213 | 12213 | |
12214 | - $duplicate = $this->dup( $bean, array(), TRUE ); |
|
12214 | + $duplicate = $this->dup($bean, array(), TRUE); |
|
12215 | 12215 | |
12216 | - $array[] = $duplicate->export( FALSE, $parents, FALSE, $filters ); |
|
12216 | + $array[] = $duplicate->export(FALSE, $parents, FALSE, $filters); |
|
12217 | 12217 | } |
12218 | 12218 | |
12219 | - if ( $caseStyle === 'camel' ) $array = $this->camelfy( $array ); |
|
12220 | - if ( $caseStyle === 'dolphin' ) $array = $this->camelfy( $array, true ); |
|
12219 | + if ($caseStyle === 'camel') $array = $this->camelfy($array); |
|
12220 | + if ($caseStyle === 'dolphin') $array = $this->camelfy($array, true); |
|
12221 | 12221 | |
12222 | 12222 | return $array; |
12223 | 12223 | } |
@@ -12251,7 +12251,7 @@ discard block |
||
12251 | 12251 | class RedBean_SimpleModel extends \RedBeanPHP\SimpleModel {}; |
12252 | 12252 | |
12253 | 12253 | if (!class_exists('R')) { |
12254 | - class R extends \RedBeanPHP\Facade{}; |
|
12254 | + class R extends \RedBeanPHP\Facade {}; |
|
12255 | 12255 | } |
12256 | 12256 | |
12257 | 12257 | |
@@ -12288,7 +12288,7 @@ discard block |
||
12288 | 12288 | |
12289 | 12289 | function EID($enumName) |
12290 | 12290 | { |
12291 | - return \RedBeanPHP\Facade::enum( $enumName )->id; |
|
12291 | + return \RedBeanPHP\Facade::enum($enumName)->id; |
|
12292 | 12292 | } |
12293 | 12293 | |
12294 | 12294 | } |
@@ -12301,33 +12301,33 @@ discard block |
||
12301 | 12301 | * |
12302 | 12302 | * @return void |
12303 | 12303 | */ |
12304 | -if ( !function_exists( 'dump' ) ) { |
|
12304 | +if (!function_exists('dump')) { |
|
12305 | 12305 | |
12306 | - function dmp( $list ) |
|
12306 | + function dmp($list) |
|
12307 | 12307 | { |
12308 | - print_r( \RedBeanPHP\Facade::dump( $list ) ); |
|
12308 | + print_r(\RedBeanPHP\Facade::dump($list)); |
|
12309 | 12309 | } |
12310 | 12310 | } |
12311 | 12311 | |
12312 | 12312 | /** |
12313 | 12313 | * Function alias for R::genSlots(). |
12314 | 12314 | */ |
12315 | -if ( !function_exists( 'genslots' ) ) { |
|
12315 | +if (!function_exists('genslots')) { |
|
12316 | 12316 | |
12317 | - function genslots( $slots, $tpl = NULL ) |
|
12317 | + function genslots($slots, $tpl = NULL) |
|
12318 | 12318 | { |
12319 | - return \RedBeanPHP\Facade::genSlots( $slots, $tpl ); |
|
12319 | + return \RedBeanPHP\Facade::genSlots($slots, $tpl); |
|
12320 | 12320 | } |
12321 | 12321 | } |
12322 | 12322 | |
12323 | 12323 | /** |
12324 | 12324 | * Function alias for R::flat(). |
12325 | 12325 | */ |
12326 | -if ( !function_exists( 'array_flatten' ) ) { |
|
12326 | +if (!function_exists('array_flatten')) { |
|
12327 | 12327 | |
12328 | - function array_flatten( $array ) |
|
12328 | + function array_flatten($array) |
|
12329 | 12329 | { |
12330 | - return \RedBeanPHP\Facade::flat( $array ); |
|
12330 | + return \RedBeanPHP\Facade::flat($array); |
|
12331 | 12331 | } |
12332 | 12332 | } |
12333 | 12333 |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | public function __construct() { |
37 | 37 | //parent::__construct(); |
38 | 38 | |
39 | - $this->_sesion=new \Sistema\Nucleo\CFSesion(); |
|
39 | + $this->_sesion = new \Sistema\Nucleo\CFSesion(); |
|
40 | 40 | } |
41 | - public function enviarCorreo($para, $titulo= 'Asunto', $mensaje= 'cuerpo del correo'){ |
|
41 | + public function enviarCorreo($para, $titulo = 'Asunto', $mensaje = 'cuerpo del correo') { |
|
42 | 42 | return mail($para, $titulo, $mensaje); |
43 | 43 | } |
44 | 44 | |
45 | 45 | |
46 | 46 | // filtros Email |
47 | 47 | |
48 | - function filtroEmail($email){ |
|
49 | - if (!filter_input(INPUT_POST, $email, FILTER_VALIDATE_EMAIL)){ |
|
48 | + function filtroEmail($email) { |
|
49 | + if (!filter_input(INPUT_POST, $email, FILTER_VALIDATE_EMAIL)) { |
|
50 | 50 | echo "E-Mail no es valido"; |
51 | 51 | } |
52 | 52 | else |
@@ -58,44 +58,44 @@ discard block |
||
58 | 58 | |
59 | 59 | //cadenas |
60 | 60 | |
61 | - function rangoTexto($texto, $inicio, $cantidad){ |
|
61 | + function rangoTexto($texto, $inicio, $cantidad) { |
|
62 | 62 | |
63 | - return $limite= substr($texto, $inicio, $cantidad); |
|
63 | + return $limite = substr($texto, $inicio, $cantidad); |
|
64 | 64 | |
65 | 65 | } |
66 | 66 | |
67 | 67 | //Redirecionar |
68 | 68 | |
69 | - function Redireccion($url, $permanent = false){ |
|
69 | + function Redireccion($url, $permanent = false) { |
|
70 | 70 | header('Location: ' . $url, true, $permanent ? 301 : 302); |
71 | 71 | |
72 | 72 | exit(); |
73 | 73 | } |
74 | 74 | |
75 | - function redireccionUrl($url){ |
|
76 | - $url=Cf_BASE_URL.$url; |
|
75 | + function redireccionUrl($url) { |
|
76 | + $url = Cf_BASE_URL . $url; |
|
77 | 77 | header('Location: ' . $url); |
78 | 78 | exit(); |
79 | 79 | } |
80 | 80 | |
81 | - function redireccionUrlMsj($controlador){ |
|
81 | + function redireccionUrlMsj($controlador) { |
|
82 | 82 | $this->_sesion->iniciarSesion('_s', false); |
83 | - $_SESSION[error_ingreso]='Error en el intento de ingreso'; |
|
84 | - $controlador=Cf_BASE_URL.$controlador; |
|
83 | + $_SESSION[error_ingreso] = 'Error en el intento de ingreso'; |
|
84 | + $controlador = Cf_BASE_URL . $controlador; |
|
85 | 85 | header('Location: ' . $controlador); |
86 | 86 | exit(); |
87 | 87 | } |
88 | 88 | |
89 | - function redireccion_($url, $statusCode = 303){ |
|
89 | + function redireccion_($url, $statusCode = 303) { |
|
90 | 90 | header('Location: ' . $url, true, $statusCode); |
91 | 91 | die(); |
92 | 92 | } |
93 | 93 | |
94 | - function redirect($controller,$method = "index",$args = array()) |
|
94 | + function redirect($controller, $method = "index", $args = array()) |
|
95 | 95 | { |
96 | 96 | global $core; /* Guess Obviously */ |
97 | 97 | |
98 | - $location = $core->Cf_BASE_URL . "/" . $controller . "/" . $method . "/" . implode("/",$args); |
|
98 | + $location = $core->Cf_BASE_URL . "/" . $controller . "/" . $method . "/" . implode("/", $args); |
|
99 | 99 | |
100 | 100 | /* |
101 | 101 | * Use @header to redirect the page: |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | |
109 | 109 | //texto |
110 | - public function filtrarEntero($int){ |
|
110 | + public function filtrarEntero($int) { |
|
111 | 111 | |
112 | 112 | return filter_var($int, FILTER_VALIDATE_INT); |
113 | 113 |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | ); |
39 | 39 | |
40 | 40 | public static function configurar($clave, $valor = null) { |
41 | - if( is_array($clave) ) { |
|
41 | + if (is_array($clave)) { |
|
42 | 42 | foreach ($clave as $config_name => $config_value) { |
43 | 43 | self::$configuracion[$config_name] = $config_value; |
44 | 44 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param string $clave |
64 | 64 | */ |
65 | 65 | public static function obtener($clave, $raw = false, $tiempo_personalizado = null) { |
66 | - if( ! self::file_expired($archivo = self::obtenerRuta($clave), $tiempo_personalizado)) { |
|
66 | + if (!self::file_expired($archivo = self::obtenerRuta($clave), $tiempo_personalizado)) { |
|
67 | 67 | $contenido = file_get_contents($archivo); |
68 | 68 | return $raw ? $contenido : unserialize($contenido); |
69 | 69 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @return bool true if the data was removed successfully |
91 | 91 | */ |
92 | 92 | public static function eliminar($clave) { |
93 | - if( ! file_exists($archivo = self::obtenerRuta($clave)) ) { |
|
93 | + if (!file_exists($archivo = self::obtenerRuta($clave))) { |
|
94 | 94 | return true; |
95 | 95 | } |
96 | 96 | return @unlink($archivo); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @return bool if the file has expired or not |
118 | 118 | */ |
119 | 119 | public static function file_expired($archivo, $fecha = null) { |
120 | - if( ! file_exists($archivo) ) { |
|
120 | + if (!file_exists($archivo)) { |
|
121 | 121 | return true; |
122 | 122 | } |
123 | 123 | return (time() > (filemtime($archivo) + 60 * ($fecha ? $fecha : self::$configuracion['expires']))); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | break; |
162 | 162 | } |
163 | 163 | echo '</div>'; |
164 | - echo '</div>'.PHP_EOL; |
|
164 | + echo '</div>' . PHP_EOL; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Closing form |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | // Asignamos las claves conviritiendo el array |
193 | 193 | foreach ($data as $attr=>$value) { |
194 | - $r .= $attr.'="'.$value.'" '; |
|
194 | + $r .= $attr . '="' . $value . '" '; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | $r .= '/>'; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | |
210 | 210 | // Asignamos las claves conviritiendo el array |
211 | 211 | foreach ($data as $attr=>$value) { |
212 | - $base .= $attr.'="'.$value.'" '; |
|
212 | + $base .= $attr . '="' . $value . '" '; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | if (!is_array($values)) { |
222 | 222 | // Comprobamos el value, es posible que el usuario este intentando crear los Radio (option) de forma separada |
223 | 223 | if (!is_array($values) and $selected == $values) $base .= ' checked="checked" '; |
224 | - return $base . ' value="'.$values.'" />'; |
|
224 | + return $base . ' value="' . $values . '" />'; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | // Por el contrario, tenemos 1 o m�s value con lo que es un posible texto |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | foreach ($values as $id=>$text) { |
231 | 231 | $r .= $base; |
232 | 232 | if ($selected !== null and $id == $selected) $r .= ' checked="checked" '; |
233 | - $r .= ' value="'. $id .'" />'.$text.'</label>'; |
|
233 | + $r .= ' value="' . $id . '" />' . $text . '</label>'; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | return $r; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $r = '<select '; |
250 | 250 | // Convert array to input string |
251 | 251 | foreach ($data as $attr=>$value) { |
252 | - $r .= $attr.'="'.$value.'" '; |
|
252 | + $r .= $attr . '="' . $value . '" '; |
|
253 | 253 | } |
254 | 254 | // Return end input |
255 | 255 | $r .= '>'; |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | // Asignamos las claves conviritiendo el array |
289 | 289 | foreach ($data as $attr=>$value) { |
290 | - $r .= $attr.'="'.$value.'" '; |
|
290 | + $r .= $attr . '="' . $value . '" '; |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | $r .= '>'; |
@@ -304,14 +304,14 @@ discard block |
||
304 | 304 | */ |
305 | 305 | private function showStartForm() { |
306 | 306 | $r = '<form '; |
307 | - if ($this->action!= '') $r .= 'action="'.$this->action.'" '; |
|
308 | - if ($this->method != '') $r .= 'method="'.$this->method .'" '; |
|
309 | - if ($this->name != '') $r .= 'name="'.$this->name .'" '; |
|
310 | - if ($this->on_submit != '') $r .= 'onSubmit="'.$this->on_submit .'" '; |
|
311 | - if ($this->id != '') $r .= 'id="'.$this->id .'" '; |
|
312 | - if ($this->class != '') $r .= 'class="'.$this->class .'" '; |
|
313 | - |
|
314 | - return $r . '>'.PHP_EOL; |
|
307 | + if ($this->action != '') $r .= 'action="' . $this->action . '" '; |
|
308 | + if ($this->method != '') $r .= 'method="' . $this->method . '" '; |
|
309 | + if ($this->name != '') $r .= 'name="' . $this->name . '" '; |
|
310 | + if ($this->on_submit != '') $r .= 'onSubmit="' . $this->on_submit . '" '; |
|
311 | + if ($this->id != '') $r .= 'id="' . $this->id . '" '; |
|
312 | + if ($this->class != '') $r .= 'class="' . $this->class . '" '; |
|
313 | + |
|
314 | + return $r . '>' . PHP_EOL; |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -408,14 +408,14 @@ discard block |
||
408 | 408 | if (isset($data['maxlength']) and is_numeric($data['maxlength']) and $data['maxlength'] > -1 |
409 | 409 | and strlen($readValue) > $data['maxlength']) { |
410 | 410 | |
411 | - $this->log('is too long. Maximum' . ' ' . $data['maxlength'] . ' ' . 'characters', $data ); |
|
411 | + $this->log('is too long. Maximum' . ' ' . $data['maxlength'] . ' ' . 'characters', $data); |
|
412 | 412 | return false; |
413 | 413 | } |
414 | 414 | |
415 | 415 | if (isset($data['pattern']) and is_numeric($data['pattern']) and $data['maxlength'] != '' |
416 | 416 | and preg_match($data['pattern'], $readValue) === FALSE) { |
417 | 417 | |
418 | - $this->log('pattern error' . ' (' . $data['pattern'] . ')' , $data); |
|
418 | + $this->log('pattern error' . ' (' . $data['pattern'] . ')', $data); |
|
419 | 419 | return false; |
420 | 420 | } |
421 | 421 | break; |
@@ -429,20 +429,20 @@ discard block |
||
429 | 429 | |
430 | 430 | // MIN |
431 | 431 | if (isset($data['min']) and $readValue < $data['min']) { |
432 | - $this->log('The number have to be greather than' . ' ' . $data['min'].'.', $data); |
|
432 | + $this->log('The number have to be greather than' . ' ' . $data['min'] . '.', $data); |
|
433 | 433 | return false; |
434 | 434 | } |
435 | 435 | |
436 | 436 | // MAX |
437 | 437 | if (isset($data['max']) and $readValue > $data['max']) { |
438 | - $this->log('The number have to be less than' . ' ' . $data['max'].'.', $data); |
|
438 | + $this->log('The number have to be less than' . ' ' . $data['max'] . '.', $data); |
|
439 | 439 | return false; |
440 | 440 | } |
441 | 441 | |
442 | 442 | // STEP http://www.w3schools.com/tags/att_input_step.asp |
443 | 443 | // Value 0 ever is valid (and if you try Divide to Zero, it will take error because the result is inifinite |
444 | 444 | if (isset($data['step']) and $readValue != 0 and $readValue % $data['step'] !== 0) { |
445 | - $this->log('The number have to be multiple of' . ' ' . $data['step'].'.', $data); |
|
445 | + $this->log('The number have to be multiple of' . ' ' . $data['step'] . '.', $data); |
|
446 | 446 | return false; |
447 | 447 | } |
448 | 448 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | //min | max |
452 | 452 | echo $readValue; |
453 | 453 | if (!is_date($readValue)) { |
454 | - $this->log('The date' . ' ' .$readValue.' '. 'must have format' . ' mm/dd/yyyy '.'.', $data); |
|
454 | + $this->log('The date' . ' ' . $readValue . ' ' . 'must have format' . ' mm/dd/yyyy ' . '.', $data); |
|
455 | 455 | return false; |
456 | 456 | } |
457 | 457 | break; |
@@ -489,14 +489,14 @@ discard block |
||
489 | 489 | if (is_array($value)) { |
490 | 490 | $this->log('Values don\'t match.', $data); |
491 | 491 | } else { |
492 | - $this->log('ID ' .$value.' ' . 'don\'t match', $data); |
|
492 | + $this->log('ID ' . $value . ' ' . 'don\'t match', $data); |
|
493 | 493 | } |
494 | 494 | return false; |
495 | 495 | } |
496 | 496 | } else { |
497 | 497 | // Is string |
498 | 498 | if ($readValue == $values) { |
499 | - $this->log('The value' . ' ' . $value.' ' . 'is not available', $data); |
|
499 | + $this->log('The value' . ' ' . $value . ' ' . 'is not available', $data); |
|
500 | 500 | return false; |
501 | 501 | } |
502 | 502 | } |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | * |
606 | 606 | * @example $fr->addInput('text', 'Username', '', true, 'Type here your username', array('class'=>'text red', id => 'text1'), array()) |
607 | 607 | */ |
608 | - public function addInput($label = '', $type = 'text', $name = '', $value = '', $required = false, $placeholder = '', $attributes = array()) { |
|
608 | + public function addInput($label = '', $type = 'text', $name = '', $value = '', $required = false, $placeholder = '', $attributes = array()) { |
|
609 | 609 | // Creating main data |
610 | 610 | $data = array( |
611 | 611 | 'type' => $type, |
@@ -642,10 +642,10 @@ discard block |
||
642 | 642 | * @param string $placeholder Default text to show if box is empty |
643 | 643 | * @param unknown $attributes Additional attributes |
644 | 644 | */ |
645 | - public function addNumber($label = '', $name = '', $value = '', $range = false, $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) { |
|
645 | + public function addNumber($label = '', $name = '', $value = '', $range = false, $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) { |
|
646 | 646 | // Creating main data |
647 | 647 | $data = array( |
648 | - 'type' => (! $range) ? 'number' : 'range', |
|
648 | + 'type' => (!$range) ? 'number' : 'range', |
|
649 | 649 | 'name' => $name, |
650 | 650 | 'value' => $value, |
651 | 651 | ); |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | * @param string $placeholder Default text to show if box is empty |
681 | 681 | * @param unknown $attributes Additional attributes |
682 | 682 | */ |
683 | - public function addDate($label = '', $name = '', $value = '', $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) { |
|
683 | + public function addDate($label = '', $name = '', $value = '', $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) { |
|
684 | 684 | // Creating main data |
685 | 685 | $data = array( |
686 | 686 | 'type' => 'date', |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | $this->errors .= ' ' . $message . '.'; |
897 | 897 | |
898 | 898 | // Extra message (title attribute) |
899 | - if (isset($data['title']) and $data['title'] != '') $this->errors .= ' | '. 'MESSAGE' .': ' . $data['title']; |
|
899 | + if (isset($data['title']) and $data['title'] != '') $this->errors .= ' | ' . 'MESSAGE' . ': ' . $data['title']; |
|
900 | 900 | |
901 | 901 | $this->errors .= '<br />'; |
902 | 902 | } |
@@ -913,11 +913,11 @@ discard block |
||
913 | 913 | */ |
914 | 914 | // More examples: |
915 | 915 | // http://us2.php.net/manual/es/function.checkdate.php |
916 | -function is_date( $str ) { |
|
916 | +function is_date($str) { |
|
917 | 917 | // Try to execute date creator |
918 | 918 | try { |
919 | - $dt = new DateTime( trim($str) ); |
|
920 | - } catch( Exception $e ) { |
|
919 | + $dt = new DateTime(trim($str)); |
|
920 | + } catch (Exception $e) { |
|
921 | 921 | // If fails, it return false, date is incorrect |
922 | 922 | return false; |
923 | 923 | } |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | ) |
54 | 54 | ); |
55 | 55 | |
56 | - $menu = '<ul class="inline" >'. PHP_EOL; |
|
57 | - foreach($items as $item) |
|
56 | + $menu = '<ul class="inline" >' . PHP_EOL; |
|
57 | + foreach ($items as $item) |
|
58 | 58 | { |
59 | 59 | $current = (in_array($sel, $item)) ? ' class="current"' : ''; |
60 | - $id = (!empty($item['id'])) ? ' id="'.$item['id'].'"' : ''; |
|
61 | - $menu .= '<li'.$current.'><a href="'.$item['link'].'"'.$id.'>'.$item['title'].'</a></li>'."\n"; |
|
60 | + $id = (!empty($item['id'])) ? ' id="' . $item['id'] . '"' : ''; |
|
61 | + $menu .= '<li' . $current . '><a href="' . $item['link'] . '"' . $id . '>' . $item['title'] . '</a></li>' . "\n"; |
|
62 | 62 | } |
63 | - $menu .= '</ul>'. PHP_EOL . PHP_EOL; |
|
63 | + $menu .= '</ul>' . PHP_EOL . PHP_EOL; |
|
64 | 64 | return $menu; |
65 | 65 | } |
66 | 66 | |
@@ -91,19 +91,19 @@ discard block |
||
91 | 91 | |
92 | 92 | $count = count($items); |
93 | 93 | $i = 0; |
94 | - $menu = PHP_EOL .'<p class="bottom_nav">'; |
|
95 | - foreach($items as $item) |
|
94 | + $menu = PHP_EOL . '<p class="bottom_nav">'; |
|
95 | + foreach ($items as $item) |
|
96 | 96 | { |
97 | 97 | $current = (in_array($sel, $item)) ? ' class="current"' : ''; |
98 | - $id = (!empty($item['id'])) ? ' id="'.$item['id'].'"' : ''; |
|
99 | - $menu .= '<a'.$current.' href="'.$item['link'].'"'.$id.'>'.$item['title'].'</a>'; |
|
98 | + $id = (!empty($item['id'])) ? ' id="' . $item['id'] . '"' : ''; |
|
99 | + $menu .= '<a' . $current . ' href="' . $item['link'] . '"' . $id . '>' . $item['title'] . '</a>'; |
|
100 | 100 | $i++; |
101 | - if($count != $i) |
|
101 | + if ($count != $i) |
|
102 | 102 | { |
103 | - $menu .= ' '.$separador.' '; |
|
103 | + $menu .= ' ' . $separador . ' '; |
|
104 | 104 | } |
105 | 105 | } |
106 | - $menu .= '</p>'. PHP_EOL ; |
|
106 | + $menu .= '</p>' . PHP_EOL; |
|
107 | 107 | return $menu; |
108 | 108 | } |
109 | 109 |
@@ -193,27 +193,27 @@ discard block |
||
193 | 193 | if ($end > $this->total_pages) $end = $this->total_pages; |
194 | 194 | |
195 | 195 | // Showing all clickable pages (create div if class is defined) |
196 | - if ($this->style != '') $r = '<div class="'.$this->style.'">'; |
|
196 | + if ($this->style != '') $r = '<div class="' . $this->style . '">'; |
|
197 | 197 | else $r = ''; |
198 | 198 | |
199 | 199 | |
200 | 200 | // First / previous |
201 | 201 | if ($this->cur_page > 1) { |
202 | - if ($this->first != '') $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
203 | - if ($this->previous != '') $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
202 | + if ($this->first != '') $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">' . $this->first . '</a> '; |
|
203 | + if ($this->previous != '') $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">' . $this->previous . '</a> '; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // You can optimize this separating BEFORE and AFTER current page in two for (to avoid load "if" in each loop) |
207 | 207 | // but it would be difficult on changes |
208 | - for ($n=$start; $n<=$end; $n++) { |
|
209 | - if ($n != $cur_page) $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
210 | - else $r .= '<a class="current">'.$n.'</a> '; |
|
208 | + for ($n = $start; $n <= $end; $n++) { |
|
209 | + if ($n != $cur_page) $r .= '<a class="link" href="' . $url_start . $n . $url_end . '">' . $n . '</a> '; |
|
210 | + else $r .= '<a class="current">' . $n . '</a> '; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | // next / last |
214 | 214 | if ($this->cur_page < $this->total_pages) { |
215 | - if ($this->next != '') $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
216 | - if ($this->last != '') $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
215 | + if ($this->next != '') $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">' . $this->next . '</a> '; |
|
216 | + if ($this->last != '') $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end . '">' . $this->last . '</a> '; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | // End div (if exist) |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | $records = $this->records; |
254 | 254 | |
255 | 255 | // Force maxium records loaded (only if is specified by user) |
256 | - if ($max_records > 0 and $max_records > $total_records) |
|
256 | + if ($max_records > 0 and $max_records > $total_records) |
|
257 | 257 | $this->total_records = $max_records; |
258 | 258 | |
259 | 259 | // Calculate total pages that have |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | // Saving changes |
277 | 277 | $this->first_record = $start; |
278 | - $this->limit = ' LIMIT '.$start.','.$records.' '; |
|
278 | + $this->limit = ' LIMIT ' . $start . ',' . $records . ' '; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -296,17 +296,17 @@ discard block |
||
296 | 296 | // And is empty, we have to Recicle ALL GET |
297 | 297 | // To know that page needs to be replaced we will use the "original_page" (the real get) |
298 | 298 | // Cortamos "pag=2" para obtener lo que va antes y despues, as� poder modificar directamente ese pag=2 por la pagina actual |
299 | - $query_string = explode($this->get_name.'='.$this->original_page, $_SERVER['QUERY_STRING']); |
|
299 | + $query_string = explode($this->get_name . '=' . $this->original_page, $_SERVER['QUERY_STRING']); |
|
300 | 300 | |
301 | 301 | // How start the new URL? To know it, we need to see the last character from current string |
302 | 302 | if (!in_array(substr($query_string[0], -1), array('?', '&'))) { |
303 | 303 | // Current string haven't any at end and it isn't "&" or "?" ? |
304 | 304 | // If initial string have one character at least it means that not is the first index |
305 | - if (isset($query_string[0][0])) $this->url_start = '?'.$query_string[0].'&'; |
|
306 | - else $this->url_start = '?'.$query_string[0]; |
|
305 | + if (isset($query_string[0][0])) $this->url_start = '?' . $query_string[0] . '&'; |
|
306 | + else $this->url_start = '?' . $query_string[0]; |
|
307 | 307 | } else { |
308 | 308 | // Current string already have ? or &, |
309 | - $this->url_start = '?'.$query_string[0]; |
|
309 | + $this->url_start = '?' . $query_string[0]; |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | $this->url_end = isset($query_string[1]) ? $query_string[1] : ''; |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | foreach ($gets as $get) { |
319 | 319 | if ($get != $get_name) { |
320 | 320 | // Trying to get the GET |
321 | - if (isset($_GET[$get])) $tmp .= $get.'='.$_GET[$get].'&'; |
|
321 | + if (isset($_GET[$get])) $tmp .= $get . '=' . $_GET[$get] . '&'; |
|
322 | 322 | } else { |
323 | 323 | // Pour the $tmp content to $tmp_start |
324 | 324 | if ($tmp_start == '') $tmp_start .= '?'; |
@@ -333,16 +333,16 @@ discard block |
||
333 | 333 | $this->url_start = $tmp_start; |
334 | 334 | $this->url_end = $tmp; |
335 | 335 | } |
336 | - else $this->url_start = '?'.$tmp; |
|
336 | + else $this->url_start = '?' . $tmp; |
|
337 | 337 | } |
338 | - } else{ |
|
338 | + } else { |
|
339 | 339 | // Non recicle |
340 | 340 | $this->url_start = '?'; |
341 | 341 | $this->url_end = ''; |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Add the pagination |
345 | - $this->url_start .= $this->get_name.'='; |
|
345 | + $this->url_start .= $this->get_name . '='; |
|
346 | 346 | } |
347 | 347 | } |
348 | 348 | } |
@@ -30,20 +30,20 @@ discard block |
||
30 | 30 | //Seguridad |
31 | 31 | |
32 | 32 | //xss funciones de mitigacion |
33 | - function xsseguro($texto,$encoding='UTF-8'){ |
|
34 | - return htmlspecialchars($texto,ENT_QUOTES | ENT_HTML401,$encoding); |
|
33 | + function xsseguro($texto, $encoding = 'UTF-8') { |
|
34 | + return htmlspecialchars($texto, ENT_QUOTES | ENT_HTML401, $encoding); |
|
35 | 35 | } |
36 | - function xecho($texto){ |
|
36 | + function xecho($texto) { |
|
37 | 37 | echo xsseguro($texto); |
38 | 38 | } |
39 | 39 | |
40 | - public function filtrarTexto($texto){ |
|
40 | + public function filtrarTexto($texto) { |
|
41 | 41 | return strip_tags($texto); |
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - public function filtrarCaracteresEspeciales($texto){ |
|
46 | + public function filtrarCaracteresEspeciales($texto) { |
|
47 | 47 | return htmlspecialchars($texto, ENT_QUOTES); |
48 | 48 | } |
49 | 49 | |
@@ -59,67 +59,67 @@ discard block |
||
59 | 59 | return $cadenaAleatoria; |
60 | 60 | } |
61 | 61 | // encriptacion |
62 | - function cifrado($clave){ |
|
63 | - $cfi=sha1(md5($clave)); |
|
64 | - return $clave=Cf_KEY_MD5.$cfi; |
|
62 | + function cifrado($clave) { |
|
63 | + $cfi = sha1(md5($clave)); |
|
64 | + return $clave = Cf_KEY_MD5 . $cfi; |
|
65 | 65 | } |
66 | 66 | // Protecion CSRF |
67 | 67 | public function generoTokenDeFormulario($formulario) { |
68 | - $secreta = Cf_CSRF_SECRET.$this->generarCadenaAleatoria(); |
|
68 | + $secreta = Cf_CSRF_SECRET . $this->generarCadenaAleatoria(); |
|
69 | 69 | $sid = session_id(); |
70 | - $token = md5($secreta.$sid.$formulario); |
|
70 | + $token = md5($secreta . $sid . $formulario); |
|
71 | 71 | return $token; |
72 | 72 | } |
73 | 73 | |
74 | 74 | public function verificoTokenDeFormulario($formulario, $token) { |
75 | - $secreta = Cf_CSRF_SECRET.$this->generarCadenaAleatoria(); |
|
75 | + $secreta = Cf_CSRF_SECRET . $this->generarCadenaAleatoria(); |
|
76 | 76 | $sid = session_id(); |
77 | - $correcta = md5($secreta.$sid.$formulario); |
|
77 | + $correcta = md5($secreta . $sid . $formulario); |
|
78 | 78 | return ($token == $correcta); |
79 | 79 | } |
80 | 80 | |
81 | - function obtenerDireccionIP(){ |
|
82 | - if (!empty($_SERVER ['HTTP_CLIENT_IP'] )) |
|
83 | - $ip=$_SERVER ['HTTP_CLIENT_IP']; |
|
84 | - elseif (!empty($_SERVER ['HTTP_X_FORWARDED_FOR'] )) |
|
85 | - $ip=$_SERVER ['HTTP_X_FORWARDED_FOR']; |
|
81 | + function obtenerDireccionIP() { |
|
82 | + if (!empty($_SERVER ['HTTP_CLIENT_IP'])) |
|
83 | + $ip = $_SERVER ['HTTP_CLIENT_IP']; |
|
84 | + elseif (!empty($_SERVER ['HTTP_X_FORWARDED_FOR'])) |
|
85 | + $ip = $_SERVER ['HTTP_X_FORWARDED_FOR']; |
|
86 | 86 | else |
87 | - $ip=$_SERVER ['REMOTE_ADDR']; |
|
87 | + $ip = $_SERVER ['REMOTE_ADDR']; |
|
88 | 88 | |
89 | 89 | return $ip; |
90 | 90 | } |
91 | 91 | |
92 | - function restringirIp($ip){ |
|
92 | + function restringirIp($ip) { |
|
93 | 93 | $ipCliente = $this->obtenerDireccionIP(); |
94 | 94 | |
95 | - if($ipCliente == $ip){ |
|
95 | + if ($ipCliente == $ip) { |
|
96 | 96 | return true; |
97 | 97 | } |
98 | - else{ |
|
98 | + else { |
|
99 | 99 | header('location: http://www.tusitioweb/redireccion'); |
100 | 100 | exit; |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | - function restringirConjuntoIps($ips){ |
|
104 | + function restringirConjuntoIps($ips) { |
|
105 | 105 | $ipCliente = obtenerDireccionIP(); |
106 | 106 | |
107 | - if (in_array($ipCliente,$ips)){ |
|
107 | + if (in_array($ipCliente, $ips)) { |
|
108 | 108 | return true; |
109 | 109 | } |
110 | - else{ |
|
110 | + else { |
|
111 | 111 | header('location: http://direccion_envio_salida'); |
112 | 112 | exit; |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - function restringirRango(){ |
|
116 | + function restringirRango() { |
|
117 | 117 | $ipCliente = obtenerDireccionIP(); |
118 | 118 | |
119 | - if(substr($ipCliente, 0, 8 ) == "150.214."){ |
|
119 | + if (substr($ipCliente, 0, 8) == "150.214.") { |
|
120 | 120 | return true; |
121 | 121 | } |
122 | - else{ |
|
122 | + else { |
|
123 | 123 | header('location: http://direccion_envio_salida'); |
124 | 124 | exit; |
125 | 125 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * |
137 | 137 | */ |
138 | 138 | function emailSeguro($cadena) { |
139 | - return preg_replace( '((?:\n|\r|\t|%0A|%0D|%08|%09)+)i' , '', $cadena ); |
|
139 | + return preg_replace('((?:\n|\r|\t|%0A|%0D|%08|%09)+)i', '', $cadena); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /*** example usage |
@@ -27,7 +27,7 @@ |
||
27 | 27 | |
28 | 28 | class CFPHPVinculos { |
29 | 29 | |
30 | - function get_dominio(){ |
|
30 | + function get_dominio() { |
|
31 | 31 | |
32 | 32 | $dominio = "http://www.my-site-domain.com/"; |
33 | 33 | return $dominio; |
@@ -32,31 +32,31 @@ |
||
32 | 32 | { |
33 | 33 | $controlador = $peticion->getControlador() . 'Controlador'; |
34 | 34 | //definimos la ruta al controlador |
35 | - $rutaControlador = SITE_ROOT . 'mvc' . DS .'controladores' . DS . $controlador . '.php'; |
|
35 | + $rutaControlador = SITE_ROOT . 'mvc' . DS . 'controladores' . DS . $controlador . '.php'; |
|
36 | 36 | $metodo = $peticion->getMetodo(); |
37 | 37 | $args = $peticion->getArgumentos(); |
38 | 38 | |
39 | 39 | //verifcamos que el archivo existe con la funcion de PHP is_readable |
40 | - if(is_readable($rutaControlador)){ |
|
40 | + if (is_readable($rutaControlador)) { |
|
41 | 41 | require_once $rutaControlador; |
42 | 42 | $controlador = new $controlador; |
43 | 43 | |
44 | - if(is_callable(array($controlador, $metodo))){ |
|
44 | + if (is_callable(array($controlador, $metodo))) { |
|
45 | 45 | $metodo = $peticion->getMetodo(); |
46 | 46 | } |
47 | - else{ |
|
47 | + else { |
|
48 | 48 | $metodo = 'index'; |
49 | 49 | } |
50 | 50 | |
51 | - if(isset($args)){ |
|
51 | + if (isset($args)) { |
|
52 | 52 | call_user_func_array(array($controlador, $metodo), $args); |
53 | 53 | } |
54 | - else{ |
|
54 | + else { |
|
55 | 55 | call_user_func(array($controlador, $metodo)); |
56 | 56 | } |
57 | 57 | |
58 | 58 | } else { |
59 | - header('Location: '. Cf_BASE_URL.'error/'); |
|
59 | + header('Location: ' . Cf_BASE_URL . 'error/'); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | } |
63 | 63 | \ No newline at end of file |