@@ -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 | |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function __construct(string $rootPath = '') |
110 | 110 | { |
111 | - $this->thinkPath = dirname(__DIR__) . DIRECTORY_SEPARATOR; |
|
112 | - $this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath(); |
|
113 | - $this->appPath = $this->rootPath . 'app' . DIRECTORY_SEPARATOR; |
|
114 | - $this->runtimePath = $this->rootPath . 'runtime' . DIRECTORY_SEPARATOR; |
|
111 | + $this->thinkPath = dirname(__DIR__).DIRECTORY_SEPARATOR; |
|
112 | + $this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR : $this->getDefaultRootPath(); |
|
113 | + $this->appPath = $this->rootPath.'app'.DIRECTORY_SEPARATOR; |
|
114 | + $this->runtimePath = $this->rootPath.'runtime'.DIRECTORY_SEPARATOR; |
|
115 | 115 | |
116 | - if (is_file($this->appPath . 'provider.php')) { |
|
117 | - $this->bind(include $this->appPath . 'provider.php'); |
|
116 | + if (is_file($this->appPath.'provider.php')) { |
|
117 | + $this->bind(include $this->appPath.'provider.php'); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | static::setInstance($this); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | public function getService($service) |
175 | 175 | { |
176 | 176 | $name = is_string($service) ? $service : get_class($service); |
177 | - return array_values(array_filter($this->services, function ($value) use ($name) { |
|
177 | + return array_values(array_filter($this->services, function($value) use ($name) { |
|
178 | 178 | return $value instanceof $name; |
179 | 179 | }, ARRAY_FILTER_USE_BOTH))[0] ?? null; |
180 | 180 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public function getBasePath(): string |
252 | 252 | { |
253 | - return $this->rootPath . 'app' . DIRECTORY_SEPARATOR; |
|
253 | + return $this->rootPath.'app'.DIRECTORY_SEPARATOR; |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function getConfigPath(): string |
310 | 310 | { |
311 | - return $this->rootPath . 'config' . DIRECTORY_SEPARATOR; |
|
311 | + return $this->rootPath.'config'.DIRECTORY_SEPARATOR; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -354,8 +354,8 @@ discard block |
||
354 | 354 | $this->beginMem = memory_get_usage(); |
355 | 355 | |
356 | 356 | // 加载环境变量 |
357 | - if (is_file($this->rootPath . '.env')) { |
|
358 | - $this->env->load($this->rootPath . '.env'); |
|
357 | + if (is_file($this->rootPath.'.env')) { |
|
358 | + $this->env->load($this->rootPath.'.env'); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | $this->configExt = $this->env->get('config_ext', '.php'); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | // 加载框架默认语言包 |
369 | 369 | $langSet = $this->lang->defaultLangSet(); |
370 | 370 | |
371 | - $this->lang->load($this->thinkPath . 'lang' . DIRECTORY_SEPARATOR . $langSet . '.php'); |
|
371 | + $this->lang->load($this->thinkPath.'lang'.DIRECTORY_SEPARATOR.$langSet.'.php'); |
|
372 | 372 | |
373 | 373 | // 加载应用默认语言包 |
374 | 374 | $this->loadLangPack($langSet); |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | } |
408 | 408 | |
409 | 409 | // 加载系统语言包 |
410 | - $files = glob($this->appPath . 'lang' . DIRECTORY_SEPARATOR . $langset . '.*'); |
|
410 | + $files = glob($this->appPath.'lang'.DIRECTORY_SEPARATOR.$langset.'.*'); |
|
411 | 411 | $this->lang->load($files); |
412 | 412 | |
413 | 413 | // 加载扩展(自定义)语言包 |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | */ |
426 | 426 | public function boot(): void |
427 | 427 | { |
428 | - array_walk($this->services, function ($service) { |
|
428 | + array_walk($this->services, function($service) { |
|
429 | 429 | $this->bootService($service); |
430 | 430 | }); |
431 | 431 | } |
@@ -439,30 +439,30 @@ discard block |
||
439 | 439 | { |
440 | 440 | $appPath = $this->getAppPath(); |
441 | 441 | |
442 | - if (is_file($appPath . 'common.php')) { |
|
443 | - include_once $appPath . 'common.php'; |
|
442 | + if (is_file($appPath.'common.php')) { |
|
443 | + include_once $appPath.'common.php'; |
|
444 | 444 | } |
445 | 445 | |
446 | - include_once $this->thinkPath . 'helper.php'; |
|
446 | + include_once $this->thinkPath.'helper.php'; |
|
447 | 447 | |
448 | 448 | $configPath = $this->getConfigPath(); |
449 | 449 | |
450 | 450 | $files = []; |
451 | 451 | |
452 | 452 | if (is_dir($configPath)) { |
453 | - $files = glob($configPath . '*' . $this->configExt); |
|
453 | + $files = glob($configPath.'*'.$this->configExt); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | foreach ($files as $file) { |
457 | 457 | $this->config->load($file, pathinfo($file, PATHINFO_FILENAME)); |
458 | 458 | } |
459 | 459 | |
460 | - if (is_file($appPath . 'event.php')) { |
|
461 | - $this->loadEvent(include $appPath . 'event.php'); |
|
460 | + if (is_file($appPath.'event.php')) { |
|
461 | + $this->loadEvent(include $appPath.'event.php'); |
|
462 | 462 | } |
463 | 463 | |
464 | - if (is_file($appPath . 'service.php')) { |
|
465 | - $services = include $appPath . 'service.php'; |
|
464 | + if (is_file($appPath.'service.php')) { |
|
465 | + $services = include $appPath.'service.php'; |
|
466 | 466 | foreach ($services as $service) { |
467 | 467 | $this->register($service); |
468 | 468 | } |
@@ -527,9 +527,9 @@ discard block |
||
527 | 527 | $name = str_replace(['/', '.'], '\\', $name); |
528 | 528 | $array = explode('\\', $name); |
529 | 529 | $class = self::parseName(array_pop($array), 1); |
530 | - $path = $array ? implode('\\', $array) . '\\' : ''; |
|
530 | + $path = $array ? implode('\\', $array).'\\' : ''; |
|
531 | 531 | |
532 | - return $this->namespace . '\\' . $layer . '\\' . $path . $class; |
|
532 | + return $this->namespace.'\\'.$layer.'\\'.$path.$class; |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | { |
551 | 551 | $path = dirname(dirname(dirname(dirname($this->thinkPath)))); |
552 | 552 | |
553 | - return $path . DIRECTORY_SEPARATOR; |
|
553 | + return $path.DIRECTORY_SEPARATOR; |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | public static function parseName(string $name = null, int $type = 0, bool $ucfirst = true): string |
566 | 566 | { |
567 | 567 | if ($type) { |
568 | - $name = preg_replace_callback('/_([a-zA-Z])/', function ($match) { |
|
568 | + $name = preg_replace_callback('/_([a-zA-Z])/', function($match) { |
|
569 | 569 | return strtoupper($match[1]); |
570 | 570 | }, $name); |
571 | 571 | return $ucfirst ? ucfirst($name) : lcfirst($name); |
@@ -596,13 +596,13 @@ discard block |
||
596 | 596 | */ |
597 | 597 | public static function factory(string $name, string $namespace = '', ...$args) |
598 | 598 | { |
599 | - $class = false !== strpos($name, '\\') ? $name : $namespace . ucwords($name); |
|
599 | + $class = false !== strpos($name, '\\') ? $name : $namespace.ucwords($name); |
|
600 | 600 | |
601 | 601 | if (class_exists($class)) { |
602 | 602 | return Container::getInstance()->invokeClass($class, $args); |
603 | 603 | } |
604 | 604 | |
605 | - throw new ClassNotFoundException('class not exists:' . $class, $class); |
|
605 | + throw new ClassNotFoundException('class not exists:'.$class, $class); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | /** |