@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | private function initBaseConfig() |
| 90 | 90 | { |
| 91 | - $this->initConfigIfNotSet('app.route.active', defined('NEBULA_ROUTE_GROUPS')? \explode(',', \constant('NEBULA_ROUTE_GROUPS')) :['default']); |
|
| 91 | + $this->initConfigIfNotSet('app.route.active', defined('NEBULA_ROUTE_GROUPS') ? \explode(',', \constant('NEBULA_ROUTE_GROUPS')) : ['default']); |
|
| 92 | 92 | $this->initConfigIfNotSet('app.import', [\constant('NEBULA_APP').'/'.'share']); |
| 93 | 93 | $this->initConfigIfNotSet('app.resource', [\constant('NEBULA_APP').'/'.'resource']); |
| 94 | 94 | $this->initConfigIfNotSet('app.module.scan-path', [\constant('NEBULA_APP').'/'.'modules']); |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | private function initTimezone() |
| 117 | 117 | { |
| 118 | - $timezone = defined('DEFAULT_TIMEZONE')?constant('DEFAULT_TIMEZONE'):'PRC'; |
|
| 118 | + $timezone = defined('DEFAULT_TIMEZONE') ?constant('DEFAULT_TIMEZONE') : 'PRC'; |
|
| 119 | 119 | date_default_timezone_set($this->config->get('app.timezone', $timezone)); |
| 120 | 120 | } |
| 121 | 121 | |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public function run() |
| 201 | 201 | { |
| 202 | - $className = $this->config->get('app.application', Application::class); |
|
| 202 | + $className = $this->config->get('app.application', Application::class); |
|
| 203 | 203 | $this->application = Runnable::newClassInstance($className); |
| 204 | 204 | $this->application->setContext($this); |
| 205 | 205 | $this->application->setPath($this->path); |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | protected $matcher; |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - public function __construct(array $methods, string $uri, array $attribute=[]) |
|
| 42 | + public function __construct(array $methods, string $uri, array $attribute = []) |
|
| 43 | 43 | { |
| 44 | - array_walk($methods, function ($value) { |
|
| 44 | + array_walk($methods, function($value) { |
|
| 45 | 45 | return strtoupper($value); |
| 46 | 46 | }); |
| 47 | 47 | $this->methods = $methods; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param RequestInterface $request |
| 158 | 158 | * @return array|null |
| 159 | 159 | */ |
| 160 | - public function match(RequestInterface $request):?array { |
|
| 160 | + public function match(RequestInterface $request): ?array { |
|
| 161 | 161 | if (\in_array($request->getMethod(), $this->methods)) { |
| 162 | 162 | if (($parameter = $this->matcher->match($request->getUrl())) !== null) { |
| 163 | 163 | return $this->matcher->buildParamter($parameter); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @param mixed $default |
| 67 | 67 | * @return mixed |
| 68 | 68 | */ |
| 69 | - public function getHeader(string $name, $default =null) |
|
| 69 | + public function getHeader(string $name, $default = null) |
|
| 70 | 70 | { |
| 71 | 71 | if (array_key_exists(strtolower($name), $this->headers)) { |
| 72 | 72 | return $this->headers[$name]; |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function ip() |
| 94 | 94 | { |
| 95 | - static $ipFrom = ['HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP','HTTP_FORWARDED_FOR','HTTP_FORWARDED','REMOTE_ADDR']; |
|
| 95 | + static $ipFrom = ['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR']; |
|
| 96 | 96 | foreach ($ipFrom as $key) { |
| 97 | 97 | if (array_key_exists($key, $_SERVER)) { |
| 98 | 98 | foreach (explode(',', $_SERVER[$key]) as $ip) { |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | $method = strtoupper($server['REQUEST_METHOD'] ?? 'GET'); |
| 123 | 123 | $uri = $server['REQUEST_URI']??'/'; |
| 124 | - $headers = HeaderItem::buildFromServer($server ?: $_SERVER); |
|
| 125 | - $request = new static($method, $uri, $headers); |
|
| 124 | + $headers = HeaderItem::buildFromServer($server ?: $_SERVER); |
|
| 125 | + $request = new static($method, $uri, $headers); |
|
| 126 | 126 | $request->setDocumentRoot($server['DOCUMENT_ROOT']); |
| 127 | 127 | if ($simulate && $server !== null) { |
| 128 | 128 | $request->setServer($server); |
@@ -163,7 +163,7 @@ |
||
| 163 | 163 | $object = $class->getMethod('instance')->invoke(null); |
| 164 | 164 | $context->setResponse($object); |
| 165 | 165 | $class->getMethod('proccess')->invokeArgs($object, [ |
| 166 | - new Runnable([$object,'onRequest']), |
|
| 166 | + new Runnable([$object, 'onRequest']), |
|
| 167 | 167 | $context->getRequest(), |
| 168 | 168 | $this->matcher->getAttribute('buffer', true), |
| 169 | 169 | ]); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function add(?string $module = null, string $name, RouteMatcher $router) |
| 59 | 59 | { |
| 60 | - $module = $module ?: $this->default; |
|
| 60 | + $module = $module ?: $this->default; |
|
| 61 | 61 | if (\array_key_exists($module, $this->routes)) { |
| 62 | 62 | $this->routes[$module]->add($name, $router); |
| 63 | 63 | } else { |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @param Request $request |
| 90 | 90 | * @return MatchResult|null |
| 91 | 91 | */ |
| 92 | - public function match(Request $request):?MatchResult |
|
| 92 | + public function match(Request $request): ?MatchResult |
|
| 93 | 93 | { |
| 94 | 94 | foreach ($this->routes as $module => $collection) { |
| 95 | 95 | foreach ($collection as $name => $matcher) { |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | * @param string $name |
| 109 | 109 | * @return RouteMatcher|null |
| 110 | 110 | */ |
| 111 | - public function find(?string $module = null, string $name):?RouteMatcher |
|
| 111 | + public function find(?string $module = null, string $name): ?RouteMatcher |
|
| 112 | 112 | { |
| 113 | - $module = $module ?: $this->default; |
|
| 113 | + $module = $module ?: $this->default; |
|
| 114 | 114 | if (\array_key_exists($module, $this->routes)) { |
| 115 | 115 | return $this->routes[$module]->get($name); |
| 116 | 116 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function loadFromModule(Manager $manager) |
| 52 | 52 | { |
| 53 | - $groups = $this->applicaton->getConfig()->get('app.active', ['default']); |
|
| 53 | + $groups = $this->applicaton->getConfig()->get('app.active', ['default']); |
|
| 54 | 54 | foreach ($groups as $group) { |
| 55 | 55 | $manager->loadRoute($group, $this); |
| 56 | 56 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @param Request $request |
| 79 | 79 | * @return MatchResult|null |
| 80 | 80 | */ |
| 81 | - public function match(Request $request):?MatchResult |
|
| 81 | + public function match(Request $request): ?MatchResult |
|
| 82 | 82 | { |
| 83 | 83 | foreach ($this->routes as $group => $routes) { |
| 84 | 84 | if (($result = $routes->match($request)) !== null) { |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | class Content |
| 15 | 15 | { |
| 16 | 16 | protected $types = [ |
| 17 | - JsonContent::class => ['boolean', 'integer','double', 'string','array','NULL', JsonSerializable::class ], |
|
| 17 | + JsonContent::class => ['boolean', 'integer', 'double', 'string', 'array', 'NULL', JsonSerializable::class], |
|
| 18 | 18 | FileContent::class => [SplFileInfo::class], |
| 19 | 19 | ]; |
| 20 | 20 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | - if (\method_exists($content,'__toString')) { |
|
| 35 | + if (\method_exists($content, '__toString')) { |
|
| 36 | 36 | return Response::instance()->send($content->__toString()); |
| 37 | 37 | } |
| 38 | 38 | throw new \Exception(sprintf('can not encode %s class to response', get_class($content))); |
@@ -4,15 +4,15 @@ |
||
| 4 | 4 | use nebula\application\Loader; |
| 5 | 5 | use nebula\application\Request; |
| 6 | 6 | |
| 7 | -require_once __DIR__ .'/loader.php'; |
|
| 7 | +require_once __DIR__.'/loader.php'; |
|
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | |
| 11 | 11 | // 初始化系统加载器 |
| 12 | 12 | $loader = new Loader; |
| 13 | 13 | $loader->register(); |
| 14 | -$loader->addIncludePath(NEBULA_SYSTEM .'/src', 'nebula'); |
|
| 15 | -$loader->import(NEBULA_SYSTEM .'/src/functions.php'); |
|
| 14 | +$loader->addIncludePath(NEBULA_SYSTEM.'/src', 'nebula'); |
|
| 15 | +$loader->import(NEBULA_SYSTEM.'/src/functions.php'); |
|
| 16 | 16 | // 初始化请求 |
| 17 | 17 | $request = Request::buildFromServer(); |
| 18 | 18 | $request->apply(true); |