@@ -10,6 +10,6 @@ |
||
| 10 | 10 | use Divergence\App as App; |
| 11 | 11 | |
| 12 | 12 | return [ |
| 13 | - 'debug' => file_exists(App::$App->ApplicationPath . '/.debug'), |
|
| 14 | - 'environment' => (file_exists(App::$App->ApplicationPath . '/.dev') ? 'dev' : 'production'), |
|
| 13 | + 'debug' => file_exists(App::$App->ApplicationPath.'/.debug'), |
|
| 14 | + 'environment' => (file_exists(App::$App->ApplicationPath.'/.dev') ? 'dev' : 'production'), |
|
| 15 | 15 | ]; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | // check access for API response modes |
| 70 | 70 | $this->responseBuilder = JsonBuilder::class; |
| 71 | 71 | |
| 72 | - if (in_array($this->responseBuilder, [JsonBuilder::class,JsonpBuilder::class])) { |
|
| 72 | + if (in_array($this->responseBuilder, [JsonBuilder::class, JsonpBuilder::class])) { |
|
| 73 | 73 | if (!$this->checkAPIAccess()) { |
| 74 | 74 | return $this->throwAPIUnAuthorizedError(); |
| 75 | 75 | } |
@@ -82,8 +82,7 @@ discard block |
||
| 82 | 82 | public function handleRecordsRequest($action = false): ResponseInterface |
| 83 | 83 | { |
| 84 | 84 | switch ($action ? $action : $action = $this->shiftPath()) { |
| 85 | - case 'save': |
|
| 86 | - { |
|
| 85 | + case 'save' : { |
|
| 87 | 86 | return $this->handleMultiSaveRequest(); |
| 88 | 87 | } |
| 89 | 88 | |
@@ -224,9 +223,7 @@ discard block |
||
| 224 | 223 | } |
| 225 | 224 | |
| 226 | 225 | switch ($action ? $action : $action = $this->shiftPath()) { |
| 227 | - case '': |
|
| 228 | - case false: |
|
| 229 | - { |
|
| 226 | + case '' : case false : { |
|
| 230 | 227 | $className = static::$recordClass; |
| 231 | 228 | |
| 232 | 229 | return $this->respond($this->getTemplateName($className::$singularNoun), [ |
@@ -314,7 +311,7 @@ discard block |
||
| 314 | 311 | { |
| 315 | 312 | $className = static::$recordClass; |
| 316 | 313 | |
| 317 | - $this->prepareResponseModeJSON(['POST','PUT']); |
|
| 314 | + $this->prepareResponseModeJSON(['POST', 'PUT']); |
|
| 318 | 315 | |
| 319 | 316 | if (!empty($_REQUEST['data'])) { |
| 320 | 317 | if ($className::fieldExists(key($_REQUEST['data']))) { |
@@ -389,7 +386,7 @@ discard block |
||
| 389 | 386 | { |
| 390 | 387 | $className = static::$recordClass; |
| 391 | 388 | |
| 392 | - $this->prepareResponseModeJSON(['POST','PUT','DELETE']); |
|
| 389 | + $this->prepareResponseModeJSON(['POST', 'PUT', 'DELETE']); |
|
| 393 | 390 | |
| 394 | 391 | if (!empty($_REQUEST['data'])) { |
| 395 | 392 | if ($className::fieldExists(key($_REQUEST['data']))) { |
@@ -453,7 +450,7 @@ discard block |
||
| 453 | 450 | return $this->throwUnauthorizedError(); |
| 454 | 451 | } |
| 455 | 452 | |
| 456 | - if (in_array($_SERVER['REQUEST_METHOD'], ['POST','PUT'])) { |
|
| 453 | + if (in_array($_SERVER['REQUEST_METHOD'], ['POST', 'PUT'])) { |
|
| 457 | 454 | if ($this->responseBuilder === JsonBuilder::class) { |
| 458 | 455 | $_REQUEST = JSON::getRequestData(); |
| 459 | 456 | if (is_array($_REQUEST['data'])) { |
@@ -603,7 +600,7 @@ discard block |
||
| 603 | 600 | |
| 604 | 601 | public function getTemplateName($noun) |
| 605 | 602 | { |
| 606 | - return preg_replace_callback('/\s+([a-zA-Z])/', function ($matches) { |
|
| 603 | + return preg_replace_callback('/\s+([a-zA-Z])/', function($matches) { |
|
| 607 | 604 | return strtoupper($matches[1]); |
| 608 | 605 | }, $noun); |
| 609 | 606 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | $this->ApplicationPath = $Path; |
| 37 | 37 | |
| 38 | - if (php_sapi_name()!=='cli') { |
|
| 38 | + if (php_sapi_name() !== 'cli') { |
|
| 39 | 39 | $this->Path = new Path($_SERVER['REQUEST_URI']); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | public function config($Label) |
| 48 | 48 | { |
| 49 | - $Config = $this->ApplicationPath . '/config/' . $Label . '.php'; |
|
| 49 | + $Config = $this->ApplicationPath.'/config/'.$Label.'.php'; |
|
| 50 | 50 | if (!file_exists($Config)) { |
| 51 | - throw new \Exception($Config . ' not found in '.static::class.'::config()'); |
|
| 51 | + throw new \Exception($Config.' not found in '.static::class.'::config()'); |
|
| 52 | 52 | } |
| 53 | 53 | return require $Config; |
| 54 | 54 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @param string $label |
| 101 | 101 | * @return void |
| 102 | 102 | */ |
| 103 | - public static function setConnection(string $label=null) |
|
| 103 | + public static function setConnection(string $label = null) |
|
| 104 | 104 | { |
| 105 | 105 | if ($label === null && static::$currentConnection === null) { |
| 106 | 106 | static::$currentConnection = static::getDefaultLabel(); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @uses static::$Timezone |
| 134 | 134 | * @uses PDO |
| 135 | 135 | */ |
| 136 | - public static function getConnection($label=null) |
|
| 136 | + public static function getConnection($label = null) |
|
| 137 | 137 | { |
| 138 | 138 | if ($label === null) { |
| 139 | 139 | if (static::$currentConnection === null) { |
@@ -152,10 +152,10 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | if (isset($config['socket'])) { |
| 154 | 154 | // socket connection |
| 155 | - $DSN = 'mysql:unix_socket=' . $config['socket'] . ';dbname=' . $config['database']; |
|
| 155 | + $DSN = 'mysql:unix_socket='.$config['socket'].';dbname='.$config['database']; |
|
| 156 | 156 | } else { |
| 157 | 157 | // tcp connection |
| 158 | - $DSN = 'mysql:host=' . $config['host'] . ';port=' . $config['port'] .';dbname=' . $config['database']; |
|
| 158 | + $DSN = 'mysql:host='.$config['host'].';port='.$config['port'].';dbname='.$config['database']; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | try { |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | { |
| 187 | 187 | if (is_string($data)) { |
| 188 | 188 | $data = static::getConnection()->quote($data); |
| 189 | - $data = substr($data, 1, strlen($data)-2); |
|
| 189 | + $data = substr($data, 1, strlen($data) - 2); |
|
| 190 | 190 | return $data; |
| 191 | 191 | } elseif (is_array($data)) { |
| 192 | 192 | foreach ($data as $key=>$string) { |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | $error = static::getConnection()->errorInfo(); |
| 512 | 512 | $message = $error[2]; |
| 513 | 513 | |
| 514 | - if (App::$App->Config['environment']=='dev') { |
|
| 514 | + if (App::$App->Config['environment'] == 'dev') { |
|
| 515 | 515 | /** @var \Whoops\Handler\PrettyPageHandler */ |
| 516 | 516 | $Handler = \Divergence\App::$App->whoops->popHandler(); |
| 517 | 517 | |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | */ |
| 556 | 556 | protected static function startQueryLog($query) |
| 557 | 557 | { |
| 558 | - if (App::$App->Config['environment']!='dev') { |
|
| 558 | + if (App::$App->Config['environment'] != 'dev') { |
|
| 559 | 559 | return false; |
| 560 | 560 | } |
| 561 | 561 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | protected static function _prepareOneOne(string $relationship, array $options): array |
| 78 | 78 | { |
| 79 | - $options['local'] = $options['local'] ?? $relationship . 'ID'; |
|
| 79 | + $options['local'] = $options['local'] ?? $relationship.'ID'; |
|
| 80 | 80 | $options['foreign'] = $options['foreign'] ?? 'ID'; |
| 81 | 81 | return $options; |
| 82 | 82 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | protected static function _prepareOneMany(string $classShortName, array $options): array |
| 85 | 85 | { |
| 86 | 86 | $options['local'] = $options['local'] ?? 'ID'; |
| 87 | - $options['foreign'] = $options['foreign'] ?? $classShortName. 'ID'; |
|
| 87 | + $options['foreign'] = $options['foreign'] ?? $classShortName.'ID'; |
|
| 88 | 88 | $options['indexField'] = $options['indexField'] ?? false; |
| 89 | 89 | $options['conditions'] = $options['conditions'] ?? []; |
| 90 | 90 | $options['conditions'] = is_string($options['conditions']) ? [$options['conditions']] : $options['conditions']; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $options['local'] = $options['local'] ?? 'ContextID'; |
| 106 | 106 | $options['foreign'] = $options['foreign'] ?? 'ID'; |
| 107 | 107 | $options['classField'] = $options['classField'] ?? 'ContextClass'; |
| 108 | - $options['allowedClasses'] = $options['allowedClasses'] ?? (!empty(static::$contextClasses)?static::$contextClasses:null); |
|
| 108 | + $options['allowedClasses'] = $options['allowedClasses'] ?? (!empty(static::$contextClasses) ? static::$contextClasses : null); |
|
| 109 | 109 | return $options; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | throw new Exception('Relationship type many-many option requires a linkClass setting.'); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $options['linkLocal'] = $options['linkLocal'] ?? $classShortName . 'ID'; |
|
| 121 | + $options['linkLocal'] = $options['linkLocal'] ?? $classShortName.'ID'; |
|
| 122 | 122 | $options['linkForeign'] = $options['linkForeign'] ?? basename(str_replace('\\', '/', $options['class']::$rootClass)).'ID'; |
| 123 | 123 | $options['local'] = $options['local'] ?? 'ID'; |
| 124 | 124 | $options['foreign'] = $options['foreign'] ?? 'ID'; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $options['type'] = 'one-one'; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - switch($options['type']) { |
|
| 141 | + switch ($options['type']) { |
|
| 142 | 142 | case 'one-one': |
| 143 | 143 | $options = static::_prepareOneOne($relationship, $options); |
| 144 | 144 | break; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $options = static::_prepareContextParent($options); |
| 153 | 153 | break; |
| 154 | 154 | case 'many-many': |
| 155 | - $options = static::_prepareManyMany($classShortName,$options); |
|
| 155 | + $options = static::_prepareManyMany($classShortName, $options); |
|
| 156 | 156 | break; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | public static $searchConditions = [ |
| 73 | 73 | 'Caption' => [ |
| 74 | - 'qualifiers' => ['any','caption'], |
|
| 74 | + 'qualifiers' => ['any', 'caption'], |
|
| 75 | 75 | 'points' => 2, |
| 76 | 76 | 'sql' => 'Caption LIKE "%%%s%%"', |
| 77 | 77 | ], |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | public static $defaultFilenameFormat = 'default.%s.jpg'; |
| 101 | 101 | public static $newDirectoryPermissions = 0775; |
| 102 | 102 | public static $newFilePermissions = 0664; |
| 103 | - public static $magicPath = null;//'/usr/share/misc/magic.mgc'; |
|
| 103 | + public static $magicPath = null; //'/usr/share/misc/magic.mgc'; |
|
| 104 | 104 | public static $useFaceDetection = true; |
| 105 | 105 | public static $faceDetectionTimeLimit = 10; |
| 106 | 106 | |
@@ -469,10 +469,10 @@ discard block |
||
| 469 | 469 | |
| 470 | 470 | public function initializeFromAnalysis($mediaInfo) |
| 471 | 471 | { |
| 472 | - $this->setValue('MIMEType',$mediaInfo['mimeType']); |
|
| 473 | - $this->setValue('Width',$mediaInfo['width']); |
|
| 474 | - $this->setValue('Height',$mediaInfo['height']); |
|
| 475 | - $this->setValue('Duration',$mediaInfo['duration']); |
|
| 472 | + $this->setValue('MIMEType', $mediaInfo['mimeType']); |
|
| 473 | + $this->setValue('Width', $mediaInfo['width']); |
|
| 474 | + $this->setValue('Height', $mediaInfo['height']); |
|
| 475 | + $this->setValue('Duration', $mediaInfo['duration']); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | // determine handler |
| 521 | 521 | $staticClass = get_called_class(); |
| 522 | 522 | if (!isset(static::$mimeHandlers[$mediaInfo['mimeType']]) || $staticClass != __CLASS__) { |
| 523 | - throw new Exception('No class registered for mime type "' . $mediaInfo['mimeType'] . '"'); |
|
| 523 | + throw new Exception('No class registered for mime type "'.$mediaInfo['mimeType'].'"'); |
|
| 524 | 524 | } else { |
| 525 | 525 | $className = $mediaInfo['className'] = static::$mimeHandlers[$mediaInfo['mimeType']]; |
| 526 | 526 | |
@@ -87,7 +87,7 @@ |
||
| 87 | 87 | $PreviewMedia = Media::createFromFile($previewPath, [ |
| 88 | 88 | 'ContextClass' => 'Media' |
| 89 | 89 | ,'ContextID' => $this->getValue('ID') |
| 90 | - ,'Caption' => sprintf('%u sec preview (%us-%us)', static::$previewDuration, $startTime, $startTime+static::$previewDuration), |
|
| 90 | + ,'Caption' => sprintf('%u sec preview (%us-%us)', static::$previewDuration, $startTime, $startTime + static::$previewDuration), |
|
| 91 | 91 | ]); |
| 92 | 92 | |
| 93 | 93 | return $PreviewMedia; |
@@ -51,24 +51,24 @@ |
||
| 51 | 51 | return $records; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Uses ContextClass and ContextID to get an object. |
|
| 56 | - * Quick way to attach things to other objects in a one-to-one relationship |
|
| 57 | - * |
|
| 58 | - * @param array $record An array of database rows. |
|
| 59 | - * @return ActiveRecord|null An array of instantiated ActiveRecord models from the provided data. |
|
| 60 | - */ |
|
| 54 | + /** |
|
| 55 | + * Uses ContextClass and ContextID to get an object. |
|
| 56 | + * Quick way to attach things to other objects in a one-to-one relationship |
|
| 57 | + * |
|
| 58 | + * @param array $record An array of database rows. |
|
| 59 | + * @return ActiveRecord|null An array of instantiated ActiveRecord models from the provided data. |
|
| 60 | + */ |
|
| 61 | 61 | public static function getByContextObject(ActiveRecord $Record, $options = []) |
| 62 | 62 | { |
| 63 | 63 | return static::getByContext($Record::$rootClass, $Record->getPrimaryKeyValue(), $options); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | - * Same as getByContextObject but this method lets you specify the ContextClass manually. |
|
| 68 | - * |
|
| 69 | - * @param array $record An array of database rows. |
|
| 70 | - * @return ActiveRecord|null An array of instantiated ActiveRecord models from the provided data. |
|
| 71 | - */ |
|
| 67 | + * Same as getByContextObject but this method lets you specify the ContextClass manually. |
|
| 68 | + * |
|
| 69 | + * @param array $record An array of database rows. |
|
| 70 | + * @return ActiveRecord|null An array of instantiated ActiveRecord models from the provided data. |
|
| 71 | + */ |
|
| 72 | 72 | public static function getByContext($contextClass, $contextID, $options = []) |
| 73 | 73 | { |
| 74 | 74 | if (!static::fieldExists('ContextClass')) { |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | return DB::oneRecord( |
| 186 | 186 | (new Select())->setTable(static::$tableName)->where(join(') AND (', $conditions))->order($order ? join(',', $order) : '')->limit('1'), |
| 187 | 187 | null, |
| 188 | - [static::class,'handleException'] |
|
| 188 | + [static::class, 'handleException'] |
|
| 189 | 189 | ); |
| 190 | 190 | } |
| 191 | 191 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | public static function getByQuery($query, $params = []) |
| 200 | 200 | { |
| 201 | - return static::instantiateRecord(DB::oneRecord($query, $params, [static::class,'handleException'])); |
|
| 201 | + return static::instantiateRecord(DB::oneRecord($query, $params, [static::class, 'handleException'])); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -309,9 +309,9 @@ discard block |
||
| 309 | 309 | $select->limit(sprintf('%u,%u', $options['offset'], $options['limit'])); |
| 310 | 310 | } |
| 311 | 311 | if ($options['indexField']) { |
| 312 | - return DB::table(static::_cn($options['indexField']), $select, null, null, [static::class,'handleException']); |
|
| 312 | + return DB::table(static::_cn($options['indexField']), $select, null, null, [static::class, 'handleException']); |
|
| 313 | 313 | } else { |
| 314 | - return DB::allRecords($select, null, [static::class,'handleException']); |
|
| 314 | + return DB::allRecords($select, null, [static::class, 'handleException']); |
|
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | */ |
| 325 | 325 | public static function getAllByQuery($query, $params = []) |
| 326 | 326 | { |
| 327 | - return static::instantiateRecords(DB::allRecords($query, $params, [static::class,'handleException'])); |
|
| 327 | + return static::instantiateRecords(DB::allRecords($query, $params, [static::class, 'handleException'])); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | public static function getTableByQuery($keyField, $query, $params = []) |
| 339 | 339 | { |
| 340 | - return static::instantiateRecords(DB::table($keyField, $query, $params, [static::class,'handleException'])); |
|
| 340 | + return static::instantiateRecords(DB::table($keyField, $query, $params, [static::class, 'handleException'])); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -395,9 +395,9 @@ discard block |
||
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | if ($options['indexField']) { |
| 398 | - return DB::table(static::_cn($options['indexField']), $select, null, null, [static::class,'handleException']); |
|
| 398 | + return DB::table(static::_cn($options['indexField']), $select, null, null, [static::class, 'handleException']); |
|
| 399 | 399 | } else { |
| 400 | - return DB::allRecords($select, null, [static::class,'handleException']); |
|
| 400 | + return DB::allRecords($select, null, [static::class, 'handleException']); |
|
| 401 | 401 | } |
| 402 | 402 | } |
| 403 | 403 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | return ', '.$value.' AS '.$key; |
| 468 | 468 | } |
| 469 | 469 | } else { |
| 470 | - return ', ' . $columns; |
|
| 470 | + return ', '.$columns; |
|
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | 473 | } |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | public static function buildHaving($having) |
| 482 | 482 | { |
| 483 | 483 | if (!empty($having)) { |
| 484 | - return ' (' . (is_array($having) ? join(') AND (', static::_mapConditions($having)) : $having) . ')'; |
|
| 484 | + return ' ('.(is_array($having) ? join(') AND (', static::_mapConditions($having)) : $having).')'; |
|
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | } |