@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | // +---------------------------------------------------------------------- |
| 9 | 9 | // | Author: liu21st <[email protected]> |
| 10 | 10 | // +---------------------------------------------------------------------- |
| 11 | -declare (strict_types = 1); |
|
| 11 | +declare(strict_types=1); |
|
| 12 | 12 | |
| 13 | 13 | namespace think; |
| 14 | 14 | |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public function __construct(string $rootPath = '') |
| 182 | 182 | { |
| 183 | - $this->thinkPath = dirname(__DIR__) . DIRECTORY_SEPARATOR; |
|
| 184 | - $this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath(); |
|
| 185 | - $this->appPath = $this->rootPath . 'app' . DIRECTORY_SEPARATOR; |
|
| 186 | - $this->runtimePath = $this->rootPath . 'runtime' . DIRECTORY_SEPARATOR; |
|
| 187 | - $this->routePath = $this->rootPath . 'route' . DIRECTORY_SEPARATOR; |
|
| 183 | + $this->thinkPath = dirname(__DIR__).DIRECTORY_SEPARATOR; |
|
| 184 | + $this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR : $this->getDefaultRootPath(); |
|
| 185 | + $this->appPath = $this->rootPath.'app'.DIRECTORY_SEPARATOR; |
|
| 186 | + $this->runtimePath = $this->rootPath.'runtime'.DIRECTORY_SEPARATOR; |
|
| 187 | + $this->routePath = $this->rootPath.'route'.DIRECTORY_SEPARATOR; |
|
| 188 | 188 | |
| 189 | - if (is_file($this->appPath . 'provider.php')) { |
|
| 190 | - $this->bind(include $this->appPath . 'provider.php'); |
|
| 189 | + if (is_file($this->appPath.'provider.php')) { |
|
| 190 | + $this->bind(include $this->appPath.'provider.php'); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | static::setInstance($this); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | public function getService($service) |
| 248 | 248 | { |
| 249 | 249 | $name = is_string($service) ? $service : get_class($service); |
| 250 | - return array_values(array_filter($this->services, function ($value) use ($name) { |
|
| 250 | + return array_values(array_filter($this->services, function($value) use ($name) { |
|
| 251 | 251 | return $value instanceof $name; |
| 252 | 252 | }, ARRAY_FILTER_USE_BOTH))[0] ?? null; |
| 253 | 253 | } |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | */ |
| 405 | 405 | public function getBasePath(): string |
| 406 | 406 | { |
| 407 | - return $this->rootPath . 'app' . DIRECTORY_SEPARATOR; |
|
| 407 | + return $this->rootPath.'app'.DIRECTORY_SEPARATOR; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | public function getConfigPath(): string |
| 464 | 464 | { |
| 465 | - return $this->rootPath . 'config' . DIRECTORY_SEPARATOR; |
|
| 465 | + return $this->rootPath.'config'.DIRECTORY_SEPARATOR; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -508,8 +508,8 @@ discard block |
||
| 508 | 508 | $this->beginMem = memory_get_usage(); |
| 509 | 509 | |
| 510 | 510 | // 加载环境变量 |
| 511 | - if (is_file($this->rootPath . '.env')) { |
|
| 512 | - $this->env->load($this->rootPath . '.env'); |
|
| 511 | + if (is_file($this->rootPath.'.env')) { |
|
| 512 | + $this->env->load($this->rootPath.'.env'); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | $this->configExt = $this->env->get('config_ext', '.php'); |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | // 加载框架默认语言包 |
| 523 | 523 | $langSet = $this->lang->defaultLangSet(); |
| 524 | 524 | |
| 525 | - $this->lang->load($this->thinkPath . 'lang' . DIRECTORY_SEPARATOR . $langSet . '.php'); |
|
| 525 | + $this->lang->load($this->thinkPath.'lang'.DIRECTORY_SEPARATOR.$langSet.'.php'); |
|
| 526 | 526 | |
| 527 | 527 | // 加载应用默认语言包 |
| 528 | 528 | $this->loadLangPack($langSet); |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | // 加载系统语言包 |
| 564 | - $files = glob($this->appPath . 'lang' . DIRECTORY_SEPARATOR . $langset . '.*'); |
|
| 564 | + $files = glob($this->appPath.'lang'.DIRECTORY_SEPARATOR.$langset.'.*'); |
|
| 565 | 565 | $this->lang->load($files); |
| 566 | 566 | |
| 567 | 567 | // 加载扩展(自定义)语言包 |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | */ |
| 580 | 580 | public function boot(): void |
| 581 | 581 | { |
| 582 | - array_walk($this->services, function ($service) { |
|
| 582 | + array_walk($this->services, function($service) { |
|
| 583 | 583 | $this->bootService($service); |
| 584 | 584 | }); |
| 585 | 585 | } |
@@ -593,30 +593,30 @@ discard block |
||
| 593 | 593 | { |
| 594 | 594 | $appPath = $this->getAppPath(); |
| 595 | 595 | |
| 596 | - if (is_file($appPath . 'common.php')) { |
|
| 597 | - include_once $appPath . 'common.php'; |
|
| 596 | + if (is_file($appPath.'common.php')) { |
|
| 597 | + include_once $appPath.'common.php'; |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | - include_once $this->thinkPath . 'helper.php'; |
|
| 600 | + include_once $this->thinkPath.'helper.php'; |
|
| 601 | 601 | |
| 602 | 602 | $configPath = $this->getConfigPath(); |
| 603 | 603 | |
| 604 | 604 | $files = []; |
| 605 | 605 | |
| 606 | 606 | if (is_dir($configPath)) { |
| 607 | - $files = glob($configPath . '*' . $this->configExt); |
|
| 607 | + $files = glob($configPath.'*'.$this->configExt); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | foreach ($files as $file) { |
| 611 | 611 | $this->config->load($file, pathinfo($file, PATHINFO_FILENAME)); |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - if (is_file($appPath . 'event.php')) { |
|
| 615 | - $this->loadEvent(include $appPath . 'event.php'); |
|
| 614 | + if (is_file($appPath.'event.php')) { |
|
| 615 | + $this->loadEvent(include $appPath.'event.php'); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - if (is_file($appPath . 'service.php')) { |
|
| 619 | - $services = include $appPath . 'service.php'; |
|
| 618 | + if (is_file($appPath.'service.php')) { |
|
| 619 | + $services = include $appPath.'service.php'; |
|
| 620 | 620 | foreach ($services as $service) { |
| 621 | 621 | $this->register($service); |
| 622 | 622 | } |
@@ -681,9 +681,9 @@ discard block |
||
| 681 | 681 | $name = str_replace(['/', '.'], '\\', $name); |
| 682 | 682 | $array = explode('\\', $name); |
| 683 | 683 | $class = Str::studly(array_pop($array)); |
| 684 | - $path = $array ? implode('\\', $array) . '\\' : ''; |
|
| 684 | + $path = $array ? implode('\\', $array).'\\' : ''; |
|
| 685 | 685 | |
| 686 | - return $this->namespace . '\\' . $layer . '\\' . $path . $class; |
|
| 686 | + return $this->namespace.'\\'.$layer.'\\'.$path.$class; |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | /** |
@@ -704,7 +704,7 @@ discard block |
||
| 704 | 704 | { |
| 705 | 705 | $path = dirname(dirname(dirname(dirname($this->thinkPath)))); |
| 706 | 706 | |
| 707 | - return $path . DIRECTORY_SEPARATOR; |
|
| 707 | + return $path.DIRECTORY_SEPARATOR; |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | // +---------------------------------------------------------------------- |
| 9 | 9 | // | Author: liu21st <[email protected]> |
| 10 | 10 | // +---------------------------------------------------------------------- |
| 11 | -declare (strict_types = 1); |
|
| 11 | +declare(strict_types=1); |
|
| 12 | 12 | |
| 13 | 13 | namespace think; |
| 14 | 14 | |
@@ -122,14 +122,14 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | return $this->app->middleware->pipeline() |
| 124 | 124 | ->send($request) |
| 125 | - ->then(function ($request) { |
|
| 125 | + ->then(function($request) { |
|
| 126 | 126 | return $this->dispatchToRoute($request); |
| 127 | 127 | }); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | protected function dispatchToRoute($request) |
| 131 | 131 | { |
| 132 | - $withRoute = $this->app->config->get('app.with_route', true) ? function () { |
|
| 132 | + $withRoute = $this->app->config->get('app.with_route', true) ? function() { |
|
| 133 | 133 | $this->loadRoutes(); |
| 134 | 134 | } : null; |
| 135 | 135 | |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | protected function loadMiddleware(): void |
| 143 | 143 | { |
| 144 | - if (is_file($this->app->getBasePath() . 'middleware.php')) { |
|
| 145 | - $this->app->middleware->import(include $this->app->getBasePath() . 'middleware.php'); |
|
| 144 | + if (is_file($this->app->getBasePath().'middleware.php')) { |
|
| 145 | + $this->app->middleware->import(include $this->app->getBasePath().'middleware.php'); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | $routePath = $this->app->getRoutePath(); |
| 158 | 158 | |
| 159 | 159 | if (is_dir($routePath)) { |
| 160 | - $files = glob($routePath . '*.php'); |
|
| 160 | + $files = glob($routePath.'*.php'); |
|
| 161 | 161 | foreach ($files as $file) { |
| 162 | 162 | include $file; |
| 163 | 163 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | $route = m::mock(Route::class); |
| 49 | 49 | |
| 50 | - $route->shouldReceive('dispatch')->withArgs(function ($req, $withRoute) use ($request) { |
|
| 50 | + $route->shouldReceive('dispatch')->withArgs(function($req, $withRoute) use ($request) { |
|
| 51 | 51 | if ($withRoute) { |
| 52 | 52 | $withRoute(); |
| 53 | 53 | } |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | $this->http->multi(false); |
| 81 | 81 | |
| 82 | - $this->app->shouldReceive('getBasePath')->andReturn($root->getChild('app')->url() . DIRECTORY_SEPARATOR); |
|
| 83 | - $this->app->shouldReceive('getRootPath')->andReturn($root->url() . DIRECTORY_SEPARATOR); |
|
| 82 | + $this->app->shouldReceive('getBasePath')->andReturn($root->getChild('app')->url().DIRECTORY_SEPARATOR); |
|
| 83 | + $this->app->shouldReceive('getRootPath')->andReturn($root->url().DIRECTORY_SEPARATOR); |
|
| 84 | 84 | |
| 85 | 85 | $request = m::mock(Request::class)->makePartial(); |
| 86 | 86 | $response = m::mock(Response::class)->makePartial(); |