@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function __construct($resource = []) |
| 27 | 27 | { |
| 28 | - $this->resource = \is_array($resource)?$resource:[$resource]; |
|
| 28 | + $this->resource = \is_array($resource) ? $resource : [$resource]; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param string $limitPath 父级溢出 |
| 66 | 66 | * @return string|null |
| 67 | 67 | */ |
| 68 | - public function getResourcePath(string $path, string $limitPath = null):?string |
|
| 68 | + public function getResourcePath(string $path, string $limitPath = null): ?string |
|
| 69 | 69 | { |
| 70 | 70 | foreach ($this->resource as $root) { |
| 71 | 71 | $target = $root.'/'.$path; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param string $path |
| 84 | 84 | * @return string|null |
| 85 | 85 | */ |
| 86 | - public function getConfigResourcePath(string $path):?string |
|
| 86 | + public function getConfigResourcePath(string $path): ?string |
|
| 87 | 87 | { |
| 88 | 88 | foreach ($this->resource as $root) { |
| 89 | 89 | if ($target = PathResolver::resolve($root.'/'.$path)) { |
@@ -36,16 +36,16 @@ discard block |
||
| 36 | 36 | $this->debug->info('==============================='); |
| 37 | 37 | $this->debug->time('loading application'); |
| 38 | 38 | $appLoader->load(); |
| 39 | - $this->event->exec('application:load-config', [ $this->config ,$this]); |
|
| 39 | + $this->event->exec('application:load-config', [$this->config, $this]); |
|
| 40 | 40 | $this->debug->timeEnd('loading application'); |
| 41 | 41 | $this->debug->time('loading datasource'); |
| 42 | 42 | $appLoader->loadDataSource(); |
| 43 | 43 | Table::load($this); |
| 44 | - $this->event->exec('application:load-environment', [ $this->config ,$this]); |
|
| 44 | + $this->event->exec('application:load-environment', [$this->config, $this]); |
|
| 45 | 45 | $this->debug->timeEnd('loading datasource'); |
| 46 | 46 | $this->debug->time('loading route'); |
| 47 | 47 | $appLoader->loadRoute(); |
| 48 | - $this->event->exec('application:load-route', [$this->route , $this]); |
|
| 48 | + $this->event->exec('application:load-route', [$this->route, $this]); |
|
| 49 | 49 | $this->debug->timeEnd('loading route'); |
| 50 | 50 | $this->debug->info('-------------------------------'); |
| 51 | 51 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | if (!$response->isSended()) { |
| 98 | 98 | $response->end(); |
| 99 | 99 | } |
| 100 | - $this->debug->info('resposned with code '. $response->getStatus()); |
|
| 100 | + $this->debug->info('resposned with code '.$response->getStatus()); |
|
| 101 | 101 | $this->debug->timeEnd('sending response'); |
| 102 | 102 | } catch (\Throwable $e) { |
| 103 | 103 | $this->debug->uncaughtException($e); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | protected function createResponse(?MatchResult $result, Request $request, Response $response) |
| 156 | 156 | { |
| 157 | 157 | if (SUDA_DEBUG) { |
| 158 | - $response->setHeader('x-route', $result === null?'default':$result->getName()); |
|
| 158 | + $response->setHeader('x-route', $result === null ? 'default' : $result->getName()); |
|
| 159 | 159 | } |
| 160 | 160 | if ($result === null) { |
| 161 | 161 | $content = $this->defaultResponse($this, $request, $response); |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | class ContentWrapper |
| 18 | 18 | { |
| 19 | 19 | protected $types = [ |
| 20 | - [ JsonContentWrapper::class , ['array', JsonSerializable::class],], |
|
| 21 | - [ HtmlContentWrapper::class , ['boolean', 'integer','double', 'string'],], |
|
| 22 | - [ NullContentWrapper::class , ['NULL'],], |
|
| 23 | - [ FileContentWrapper::class , [SplFileObject::class],], |
|
| 20 | + [JsonContentWrapper::class, ['array', JsonSerializable::class], ], |
|
| 21 | + [HtmlContentWrapper::class, ['boolean', 'integer', 'double', 'string'], ], |
|
| 22 | + [NullContentWrapper::class, ['NULL'], ], |
|
| 23 | + [FileContentWrapper::class, [SplFileObject::class], ], |
|
| 24 | 24 | ]; |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public static function isTypeOf($data, string $type) : bool |
| 46 | 46 | { |
| 47 | - if (is_object($data) && !\in_array($type, ['boolean', 'bool', 'integer', 'double', 'string','array','NULL'])) { |
|
| 47 | + if (is_object($data) && !\in_array($type, ['boolean', 'bool', 'integer', 'double', 'string', 'array', 'NULL'])) { |
|
| 48 | 48 | $class = new ReflectionClass($data); |
| 49 | 49 | $typeRef = new ReflectionClass($type); |
| 50 | 50 | if ($typeRef->isInterface()) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | class Debug implements LoggerInterface, LoggerAwareInterface, DumpInterface, AttachInterface, ConfigInterface |
| 19 | 19 | { |
| 20 | - use LoggerTrait,LoggerAwareTrait,DumpTrait,AttachTrait,ConfigTrait; |
|
| 20 | + use LoggerTrait, LoggerAwareTrait, DumpTrait, AttachTrait, ConfigTrait; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * 忽略堆栈 |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $replace = []; |
| 70 | 70 | foreach ($context as $key => $val) { |
| 71 | - $replace['{' . $key . '}'] = $val; |
|
| 71 | + $replace['{'.$key.'}'] = $val; |
|
| 72 | 72 | } |
| 73 | 73 | return strtr($message, $replace); |
| 74 | 74 | } |
@@ -84,26 +84,26 @@ discard block |
||
| 84 | 84 | return $attribute; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public static function formatBytes(int $bytes, int $precision=0) |
|
| 87 | + public static function formatBytes(int $bytes, int $precision = 0) |
|
| 88 | 88 | { |
| 89 | - $human= ['B', 'KB', 'MB', 'GB', 'TB']; |
|
| 89 | + $human = ['B', 'KB', 'MB', 'GB', 'TB']; |
|
| 90 | 90 | $bytes = max($bytes, 0); |
| 91 | - $pow = floor(($bytes?log($bytes):0)/log(1024)); |
|
| 92 | - $pos = min($pow, count($human)-1); |
|
| 93 | - $bytes /= (1 << (10* $pos)); |
|
| 91 | + $pow = floor(($bytes ?log($bytes) : 0) / log(1024)); |
|
| 92 | + $pos = min($pow, count($human) - 1); |
|
| 93 | + $bytes /= (1 << (10 * $pos)); |
|
| 94 | 94 | return round($bytes, $precision).' '.$human[$pos]; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public function time(string $name, string $type= LogLevel::INFO) |
|
| 97 | + public function time(string $name, string $type = LogLevel::INFO) |
|
| 98 | 98 | { |
| 99 | - $this->timeRecord[$name]=['time'=>microtime(true),'level'=>$type]; |
|
| 99 | + $this->timeRecord[$name] = ['time'=>microtime(true), 'level'=>$type]; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function timeEnd(string $name) |
| 103 | 103 | { |
| 104 | 104 | if (\array_key_exists($name, $this->timeRecord)) { |
| 105 | - $pass=microtime(true)-$this->timeRecord[$name]['time']; |
|
| 106 | - $this->log($this->timeRecord[$name]['level'], 'process '. $name.' cost '. number_format($pass, 5).'s'); |
|
| 105 | + $pass = microtime(true) - $this->timeRecord[$name]['time']; |
|
| 106 | + $this->log($this->timeRecord[$name]['level'], 'process '.$name.' cost '.number_format($pass, 5).'s'); |
|
| 107 | 107 | return $pass; |
| 108 | 108 | } |
| 109 | 109 | return 0; |
@@ -230,7 +230,7 @@ |
||
| 230 | 230 | protected function closeOutputBuffer(bool $flush) |
| 231 | 231 | { |
| 232 | 232 | while (ob_get_level() > 0) { |
| 233 | - $flush?ob_end_flush():ob_end_clean(); |
|
| 233 | + $flush ?ob_end_flush() : ob_end_clean(); |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | |
@@ -42,4 +42,4 @@ |
||
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | // 加载器 |
| 45 | -require_once SUDA_SYSTEM .'/src/framework/loader/Loader.php'; |
|
| 45 | +require_once SUDA_SYSTEM.'/src/framework/loader/Loader.php'; |
|
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | function suda_panic($error_type, $error_message, $error_code = 500) |
| 3 | 3 | { |
| 4 | - date_default_timezone_set(defined('DEFAULT_TIMEZONE')?constant('DEFAULT_TIMEZONE'):'PRC'); |
|
| 4 | + date_default_timezone_set(defined('DEFAULT_TIMEZONE') ?constant('DEFAULT_TIMEZONE') : 'PRC'); |
|
| 5 | 5 | header('HTTP/1.1 500 Internal Server Error'); |
| 6 | 6 | header('Status:500 Internal Server Error'); |
| 7 | 7 | ob_start(); |
| 8 | 8 | $error_sort_type = strpos($error_type, '\\') === false ? $error_type : \substr($error_type, \strrpos($error_type, '\\') + 1); |
| 9 | - include __DIR__ .'/error.php'; |
|
| 9 | + include __DIR__.'/error.php'; |
|
| 10 | 10 | header('Content-Type:text/html; charset=UTF-8'); |
| 11 | 11 | header('Content-Length:'.ob_get_length()); |
| 12 | 12 | die(ob_get_clean()); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | protected function whereStringArray(string $where, array $whereBinder) |
| 109 | 109 | { |
| 110 | 110 | list($where, $whereBinder) = $this->parepareWhereString($where, $whereBinder); |
| 111 | - $this->where = 'WHERE '. $where; |
|
| 111 | + $this->where = 'WHERE '.$where; |
|
| 112 | 112 | $this->binder = $this->mergeBinder($this->binder, $whereBinder); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function groupBy(string $what) |
| 122 | 122 | { |
| 123 | - $this->groupBy = 'GROUP BY '. $what; |
|
| 123 | + $this->groupBy = 'GROUP BY '.$what; |
|
| 124 | 124 | return $this; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | { |
| 155 | 155 | |
| 156 | 156 | list($having, $havingBinder) = $this->parepareWhereString($having, $havingBinder); |
| 157 | - $this->having = 'HAVING '. $having; |
|
| 157 | + $this->having = 'HAVING '.$having; |
|
| 158 | 158 | $this->binder = $this->mergeBinder($this->binder, $havingBinder); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | public function orderBy(string $what, string $order = 'ASC') |
| 169 | 169 | { |
| 170 | - $this->orderBy = 'ORDER BY '. $what.' '. $order; |
|
| 170 | + $this->orderBy = 'ORDER BY '.$what.' '.$order; |
|
| 171 | 171 | return $this; |
| 172 | 172 | } |
| 173 | 173 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public function limit(int $start, int $length = null) |
| 182 | 182 | { |
| 183 | - $this->limit = 'LIMIT '. $start . ($length !== null ? ',' .$length :''); |
|
| 183 | + $this->limit = 'LIMIT '.$start.($length !== null ? ','.$length : ''); |
|
| 184 | 184 | return $this; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | protected function prepareQuery():Query |
| 209 | 209 | { |
| 210 | - $where = [$this->where,$this->groupBy,$this->having,$this->orderBy,$this->limit]; |
|
| 210 | + $where = [$this->where, $this->groupBy, $this->having, $this->orderBy, $this->limit]; |
|
| 211 | 211 | $condition = implode(' ', array_filter(array_map('trim', $where), 'strlen')); |
| 212 | - $select = [$this->distinct,$this->select]; |
|
| 212 | + $select = [$this->distinct, $this->select]; |
|
| 213 | 213 | $selection = implode(' ', array_filter(array_map('trim', $select), 'strlen')); |
| 214 | 214 | $string = "SELECT {$selection} FROM {$this->table} {$condition}"; |
| 215 | 215 | return new Query($string, $this->binder); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $fields = $reads; |
| 20 | 20 | } else { |
| 21 | 21 | $field = []; |
| 22 | - $prefix = strlen($table) ?"`{$table}`." :''; |
|
| 22 | + $prefix = strlen($table) ? "`{$table}`." : ''; |
|
| 23 | 23 | foreach ($reads as $want) { |
| 24 | 24 | $field[] = $prefix."`$want`"; |
| 25 | 25 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | list($inSQL, $binders) = $this->prepareInParameter($values, $name); |
| 85 | 85 | $sql = $name.' IN ('.$inSQL.')'; |
| 86 | - return [$sql,$binders]; |
|
| 86 | + return [$sql, $binders]; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | protected function prepareInParameter($values, string $name) |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | protected function prepareQueryMark(string $sql, array $parameter) |
| 130 | 130 | { |
| 131 | 131 | $binders = []; |
| 132 | - $query = \preg_replace_callback('/\?/', function ($match) use (&$binders, $parameter) { |
|
| 132 | + $query = \preg_replace_callback('/\?/', function($match) use (&$binders, $parameter) { |
|
| 133 | 133 | $index = count($binders); |
| 134 | 134 | if (\array_key_exists($index, $parameter)) { |
| 135 | 135 | $name = Binder::index($index); |