@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | if (static::peekPath() == 'json') { |
36 | 36 | // check access for API response modes |
37 | 37 | static::$responseMode = static::shiftPath(); |
38 | - if (in_array(static::$responseMode, ['json','jsonp'])) { |
|
38 | + if (in_array(static::$responseMode, ['json', 'jsonp'])) { |
|
39 | 39 | if (!static::checkAPIAccess()) { |
40 | 40 | return static::throwAPIUnAuthorizedError(); |
41 | 41 | } |
@@ -49,8 +49,7 @@ discard block |
||
49 | 49 | public static function handleRecordsRequest($action = false) |
50 | 50 | { |
51 | 51 | switch ($action ? $action : $action = static::shiftPath()) { |
52 | - case 'save': |
|
53 | - { |
|
52 | + case 'save' : { |
|
54 | 53 | return static::handleMultiSaveRequest(); |
55 | 54 | } |
56 | 55 | |
@@ -175,9 +174,7 @@ discard block |
||
175 | 174 | public static function handleRecordRequest(ActiveRecord $Record, $action = false) |
176 | 175 | { |
177 | 176 | switch ($action ? $action : $action = static::shiftPath()) { |
178 | - case '': |
|
179 | - case false: |
|
180 | - { |
|
177 | + case '' : case false : { |
|
181 | 178 | $className = static::$recordClass; |
182 | 179 | |
183 | 180 | return static::respond(static::getTemplateName($className::$singularNoun), [ |
@@ -211,7 +208,7 @@ discard block |
||
211 | 208 | |
212 | 209 | $PrimaryKey = $className::getPrimaryKey(); |
213 | 210 | |
214 | - if (static::$responseMode == 'json' && in_array($_SERVER['REQUEST_METHOD'], ['POST','PUT'])) { |
|
211 | + if (static::$responseMode == 'json' && in_array($_SERVER['REQUEST_METHOD'], ['POST', 'PUT'])) { |
|
215 | 212 | $JSONData = JSON::getRequestData(); |
216 | 213 | if (is_array($JSONData)) { |
217 | 214 | $_REQUEST = $JSONData; |
@@ -299,7 +296,7 @@ discard block |
||
299 | 296 | |
300 | 297 | $PrimaryKey = $className::getPrimaryKey(); |
301 | 298 | |
302 | - if (static::$responseMode == 'json' && in_array($_SERVER['REQUEST_METHOD'], ['POST','PUT','DELETE'])) { |
|
299 | + if (static::$responseMode == 'json' && in_array($_SERVER['REQUEST_METHOD'], ['POST', 'PUT', 'DELETE'])) { |
|
303 | 300 | $JSONData = JSON::getRequestData(); |
304 | 301 | if (is_array($JSONData)) { |
305 | 302 | $_REQUEST = $JSONData; |
@@ -394,7 +391,7 @@ discard block |
||
394 | 391 | return static::throwUnauthorizedError(); |
395 | 392 | } |
396 | 393 | |
397 | - if (in_array($_SERVER['REQUEST_METHOD'], ['POST','PUT'])) { |
|
394 | + if (in_array($_SERVER['REQUEST_METHOD'], ['POST', 'PUT'])) { |
|
398 | 395 | if (static::$responseMode == 'json') { |
399 | 396 | $_REQUEST = JSON::getRequestData(); |
400 | 397 | if (is_array($_REQUEST['data'])) { |
@@ -554,7 +551,7 @@ discard block |
||
554 | 551 | |
555 | 552 | public static function getTemplateName($noun) |
556 | 553 | { |
557 | - return preg_replace_callback('/\s+([a-zA-Z])/', function ($matches) { |
|
554 | + return preg_replace_callback('/\s+([a-zA-Z])/', function($matches) { |
|
558 | 555 | return strtoupper($matches[1]); |
559 | 556 | }, $noun); |
560 | 557 | } |
@@ -31,8 +31,7 @@ |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | switch ($responseMode ? $responseMode : static::$responseMode) { |
34 | - case 'json': |
|
35 | - JSON::translateAndRespond($responseData); |
|
34 | + case 'json' : JSON::translateAndRespond($responseData); |
|
36 | 35 | break; |
37 | 36 | case 'jsonp': |
38 | 37 | JSONP::translateAndRespond($responseData); |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | { |
12 | 12 | // configurables |
13 | 13 | /** |
14 | - * Set this to true if you want the table(s) to automatically be created when not found. |
|
15 | - * @var bool |
|
16 | - */ |
|
14 | + * Set this to true if you want the table(s) to automatically be created when not found. |
|
15 | + * @var bool |
|
16 | + */ |
|
17 | 17 | public static $autoCreateTables = true; |
18 | 18 | |
19 | 19 | /** |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | |
64 | 64 | |
65 | 65 | /** |
66 | - * Validation checks |
|
67 | - * @var array |
|
68 | - */ |
|
66 | + * Validation checks |
|
67 | + * @var array |
|
68 | + */ |
|
69 | 69 | public static $validators = []; |
70 | 70 | |
71 | 71 | /** |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | static::$tableName |
415 | 415 | , join(',', $set), |
416 | 416 | ], |
417 | - [static::class,'handleError'] |
|
417 | + [static::class, 'handleError'] |
|
418 | 418 | ); |
419 | 419 | |
420 | 420 | $this->_record[static::$primaryKey ? static::$primaryKey : 'ID'] = DB::insertID(); |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | , static::_cn(static::$primaryKey ? static::$primaryKey : 'ID') |
430 | 430 | , $this->getPrimaryKeyValue(), |
431 | 431 | ], |
432 | - [static::class,'handleError'] |
|
432 | + [static::class, 'handleError'] |
|
433 | 433 | ); |
434 | 434 | |
435 | 435 | $this->_isUpdated = true; |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | static::$tableName |
498 | 498 | ,static::_cn(static::$primaryKey ? static::$primaryKey : 'ID') |
499 | 499 | ,$id, |
500 | - ], [static::class,'handleError']); |
|
500 | + ], [static::class, 'handleError']); |
|
501 | 501 | |
502 | 502 | return DB::affectedRows() > 0; |
503 | 503 | } |
@@ -563,9 +563,9 @@ discard block |
||
563 | 563 | |
564 | 564 | if ($cacheIndex) { |
565 | 565 | $key = sprintf('%s/%s:%s', static::$tableName, $field, $value); |
566 | - return DB::oneRecordCached($key, $query, $params, [static::class,'handleError']); |
|
566 | + return DB::oneRecordCached($key, $query, $params, [static::class, 'handleError']); |
|
567 | 567 | } else { |
568 | - return DB::oneRecord($query, $params, [static::class,'handleError']); |
|
568 | + return DB::oneRecord($query, $params, [static::class, 'handleError']); |
|
569 | 569 | } |
570 | 570 | } |
571 | 571 | |
@@ -599,13 +599,13 @@ discard block |
||
599 | 599 | , $order ? 'ORDER BY '.join(',', $order) : '', |
600 | 600 | ], |
601 | 601 | |
602 | - [static::class,'handleError'] |
|
602 | + [static::class, 'handleError'] |
|
603 | 603 | ); |
604 | 604 | } |
605 | 605 | |
606 | 606 | public static function getByQuery($query, $params = []) |
607 | 607 | { |
608 | - return static::instantiateRecord(DB::oneRecord($query, $params, [static::class,'handleError'])); |
|
608 | + return static::instantiateRecord(DB::oneRecord($query, $params, [static::class, 'handleError'])); |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | public static function getAllByClass($className = false, $options = []) |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | } |
701 | 701 | |
702 | 702 | // build query |
703 | - $query = 'SELECT %1$s `%3$s`.*'; |
|
703 | + $query = 'SELECT %1$s `%3$s`.*'; |
|
704 | 704 | |
705 | 705 | if (!empty($options['extraColumns'])) { |
706 | 706 | if (is_array($options['extraColumns'])) { |
@@ -708,14 +708,14 @@ discard block |
||
708 | 708 | $query .= ', '.$value.' AS '.$key; |
709 | 709 | } |
710 | 710 | } else { |
711 | - $query .= ', ' . $options['extraColumns']; |
|
711 | + $query .= ', '.$options['extraColumns']; |
|
712 | 712 | } |
713 | 713 | } |
714 | 714 | $query .= ' FROM `%2$s` AS `%3$s` %4$s'; |
715 | 715 | $query .= ' WHERE (%5$s)'; |
716 | 716 | |
717 | 717 | if (!empty($options['having'])) { |
718 | - $query .= ' HAVING (' . (is_array($options['having']) ? join(') AND (', static::_mapConditions($options['having'])) : $options['having']) . ')'; |
|
718 | + $query .= ' HAVING ('.(is_array($options['having']) ? join(') AND (', static::_mapConditions($options['having'])) : $options['having']).')'; |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | $params = [ |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | |
730 | 730 | |
731 | 731 | if ($options['order']) { |
732 | - $query .= ' ORDER BY ' . join(',', static::_mapFieldOrder($options['order'])); |
|
732 | + $query .= ' ORDER BY '.join(',', static::_mapFieldOrder($options['order'])); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | if ($options['limit']) { |
@@ -737,9 +737,9 @@ discard block |
||
737 | 737 | } |
738 | 738 | |
739 | 739 | if ($options['indexField']) { |
740 | - return DB::table(static::_cn($options['indexField']), $query, $params, [static::class,'handleError']); |
|
740 | + return DB::table(static::_cn($options['indexField']), $query, $params, [static::class, 'handleError']); |
|
741 | 741 | } else { |
742 | - return DB::allRecords($query, $params, [static::class,'handleError']); |
|
742 | + return DB::allRecords($query, $params, [static::class, 'handleError']); |
|
743 | 743 | } |
744 | 744 | } |
745 | 745 | |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | ]; |
765 | 765 | |
766 | 766 | if ($options['order']) { |
767 | - $query .= ' ORDER BY ' . join(',', static::_mapFieldOrder($options['order'])); |
|
767 | + $query .= ' ORDER BY '.join(',', static::_mapFieldOrder($options['order'])); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | if ($options['limit']) { |
@@ -772,20 +772,20 @@ discard block |
||
772 | 772 | } |
773 | 773 | |
774 | 774 | if ($options['indexField']) { |
775 | - return DB::table(static::_cn($options['indexField']), $query, $params, [static::class,'handleError']); |
|
775 | + return DB::table(static::_cn($options['indexField']), $query, $params, [static::class, 'handleError']); |
|
776 | 776 | } else { |
777 | - return DB::allRecords($query, $params, [static::class,'handleError']); |
|
777 | + return DB::allRecords($query, $params, [static::class, 'handleError']); |
|
778 | 778 | } |
779 | 779 | } |
780 | 780 | |
781 | 781 | public static function getAllByQuery($query, $params = []) |
782 | 782 | { |
783 | - return static::instantiateRecords(DB::allRecords($query, $params, [static::class,'handleError'])); |
|
783 | + return static::instantiateRecords(DB::allRecords($query, $params, [static::class, 'handleError'])); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | public static function getTableByQuery($keyField, $query, $params = []) |
787 | 787 | { |
788 | - return static::instantiateRecords(DB::table($keyField, $query, $params, [static::class,'handleError'])); |
|
788 | + return static::instantiateRecords(DB::table($keyField, $query, $params, [static::class, 'handleError'])); |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | |
@@ -888,7 +888,7 @@ discard block |
||
888 | 888 | { |
889 | 889 | static::init(); |
890 | 890 | if (!static::fieldExists($field)) { |
891 | - throw new Exception('getColumnName called on nonexisting column: ' . get_called_class().'->'.$field); |
|
891 | + throw new Exception('getColumnName called on nonexisting column: '.get_called_class().'->'.$field); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | return static::$_classFields[get_called_class()][$field]['columnName']; |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | case 'boolean': |
1220 | 1220 | { |
1221 | 1221 | if (!isset($this->_convertedValues[$field])) { |
1222 | - $this->_convertedValues[$field] = (boolean)$value; |
|
1222 | + $this->_convertedValues[$field] = (boolean) $value; |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | 1225 | return $this->_convertedValues[$field]; |
@@ -1300,7 +1300,7 @@ discard block |
||
1300 | 1300 | |
1301 | 1301 | case 'boolean': |
1302 | 1302 | { |
1303 | - $value = (boolean)$value; |
|
1303 | + $value = (boolean) $value; |
|
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | case 'decimal': |
@@ -1495,7 +1495,7 @@ discard block |
||
1495 | 1495 | foreach ($order as $key => $value) { |
1496 | 1496 | if (is_string($key)) { |
1497 | 1497 | $columnName = static::_cn($key); |
1498 | - $direction = strtoupper($value)=='DESC' ? 'DESC' : 'ASC'; |
|
1498 | + $direction = strtoupper($value) == 'DESC' ? 'DESC' : 'ASC'; |
|
1499 | 1499 | } else { |
1500 | 1500 | $columnName = static::_cn($value); |
1501 | 1501 | $direction = 'ASC'; |
@@ -66,7 +66,7 @@ |
||
66 | 66 | ]; |
67 | 67 | |
68 | 68 | if ($options['order']) { |
69 | - $query .= ' ORDER BY ' . join(',', static::_mapFieldOrder($options['order'])); |
|
69 | + $query .= ' ORDER BY '.join(',', static::_mapFieldOrder($options['order'])); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | if ($options['limit']) { |
@@ -98,7 +98,7 @@ |
||
98 | 98 | |
99 | 99 | // check validator |
100 | 100 | if (!is_callable($validator)) { |
101 | - throw new Exception('Validator for field ' . $options['id'] . ' is not callable'); |
|
101 | + throw new Exception('Validator for field '.$options['id'].' is not callable'); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | if ($options['type'] == 'one-one') { |
70 | 70 | if (empty($options['local'])) { |
71 | - $options['local'] = $relationship . 'ID'; |
|
71 | + $options['local'] = $relationship.'ID'; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | if (empty($options['foreign'])) { |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | if (empty($options['foreign'])) { |
83 | - $options['foreign'] = $classShortName. 'ID'; |
|
83 | + $options['foreign'] = $classShortName.'ID'; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | if (!isset($options['indexField'])) { |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | if (empty($options['linkLocal'])) { |
145 | - $options['linkLocal'] = $classShortName . 'ID'; |
|
145 | + $options['linkLocal'] = $classShortName.'ID'; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | if (empty($options['linkForeign'])) { |
149 | 149 | $foreignShortname = basename(str_replace('\\', '/', $options['class']::$rootClass)); |
150 | - $options['linkForeign'] = $foreignShortname . 'ID'; |
|
150 | + $options['linkForeign'] = $foreignShortname.'ID'; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | if (empty($options['local'])) { |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | protected static $LastStatement; |
23 | 23 | protected static $Config; |
24 | 24 | |
25 | - public static function getConnection($label=null) |
|
25 | + public static function getConnection($label = null) |
|
26 | 26 | { |
27 | 27 | if (!$label) { |
28 | 28 | $label = static::getDefaultLabel(); |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | |
39 | 39 | if ($config['socket']) { |
40 | 40 | // socket connection |
41 | - $DSN = 'mysql:unix_socket=' . $config['socket'] . ';dbname=' . $config['database']; |
|
41 | + $DSN = 'mysql:unix_socket='.$config['socket'].';dbname='.$config['database']; |
|
42 | 42 | } else { |
43 | 43 | // tcp connection |
44 | - $DSN = 'mysql:host=' . $config['host'] . ';port=' . $config['port'] .';dbname=' . $config['database']; |
|
44 | + $DSN = 'mysql:host='.$config['host'].';port='.$config['port'].';dbname='.$config['database']; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | try { |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | { |
65 | 65 | if (is_string($data)) { |
66 | 66 | $data = static::getConnection()->quote($data); |
67 | - $data = substr($data, 1, strlen($data)-2); |
|
67 | + $data = substr($data, 1, strlen($data) - 2); |
|
68 | 68 | return $data; |
69 | 69 | } elseif (is_array($data)) { |
70 | 70 | foreach ($data as $key=>$string) { |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | $error = static::getConnection()->errorInfo(); |
284 | 284 | $message = $error[2]; |
285 | 285 | |
286 | - if (App::$Config['environment']=='dev') { |
|
286 | + if (App::$Config['environment'] == 'dev') { |
|
287 | 287 | $Handler = \Divergence\App::$whoops->popHandler(); |
288 | 288 | |
289 | 289 | $Handler->addDataTable("Query Information", [ |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | |
318 | 318 | protected static function startQueryLog($query) |
319 | 319 | { |
320 | - if (App::$Config['environment']!='dev') { |
|
320 | + if (App::$Config['environment'] != 'dev') { |
|
321 | 321 | return false; |
322 | 322 | } |
323 | 323 |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | * Keep it. We don't need a database connection to escape strings. |
14 | 14 | */ |
15 | 15 | return str_replace( |
16 | - ["\\", "\x00", "\n", "\r", "'", '"', "\x1a"], |
|
17 | - ["\\\\","\\0","\\n", "\\r", "\'", '\"', "\\Z"], |
|
16 | + ["\\", "\x00", "\n", "\r", "'", '"', "\x1a"], |
|
17 | + ["\\\\", "\\0", "\\n", "\\r", "\'", '\"', "\\Z"], |
|
18 | 18 | $str |
19 | 19 | ); |
20 | 20 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | case 'integer': |
131 | 131 | return 'int'.($field['unsigned'] ? ' unsigned' : '').(!empty($field['zerofill']) ? ' zerofill' : ''); |
132 | 132 | case 'decimal': |
133 | - return sprintf('decimal(%s)', $field['length']).(!empty($field['unsigned']) ? ' unsigned' : '').(!empty($field['zerofill']) ? ' zerofill' : '');; |
|
133 | + return sprintf('decimal(%s)', $field['length']).(!empty($field['unsigned']) ? ' unsigned' : '').(!empty($field['zerofill']) ? ' zerofill' : ''); ; |
|
134 | 134 | case 'float': |
135 | 135 | return 'float'; |
136 | 136 | case 'double': |
@@ -160,10 +160,10 @@ discard block |
||
160 | 160 | return 'year'; |
161 | 161 | |
162 | 162 | case 'enum': |
163 | - return sprintf('enum("%s")', join('","', array_map([static::class,'escape'], $field['values']))); |
|
163 | + return sprintf('enum("%s")', join('","', array_map([static::class, 'escape'], $field['values']))); |
|
164 | 164 | |
165 | 165 | case 'set': |
166 | - return sprintf('set("%s")', join('","', array_map([static::class,'escape'], $field['values']))); |
|
166 | + return sprintf('set("%s")', join('","', array_map([static::class, 'escape'], $field['values']))); |
|
167 | 167 | |
168 | 168 | default: |
169 | 169 | die("getSQLType: unhandled type $field[type]"); |
@@ -20,9 +20,9 @@ |
||
20 | 20 | |
21 | 21 | public static function config($Label) |
22 | 22 | { |
23 | - $Config = static::$ApplicationPath . '/config/' . $Label . '.php'; |
|
23 | + $Config = static::$ApplicationPath.'/config/'.$Label.'.php'; |
|
24 | 24 | if (!file_exists($Config)) { |
25 | - throw new \Exception($Config . ' not found in '.static::class.'::config()'); |
|
25 | + throw new \Exception($Config.' not found in '.static::class.'::config()'); |
|
26 | 26 | } |
27 | 27 | return require $Config; |
28 | 28 | } |