diff --git a/app/Infra/Exceptions/BusinessException.php b/app/Infra/Exceptions/BusinessException.php index f409c381..ce7952af 100644 --- a/app/Infra/Exceptions/BusinessException.php +++ b/app/Infra/Exceptions/BusinessException.php @@ -23,7 +23,7 @@ public function __construct( int|object $code = 0, string|array $message = '', bool $overrideMessage = false, - \Throwable $previous = null, + ?\Throwable $previous = null, float $duration = 5, ) { [$code, $message] = $this->prepareCodeAndMessage($code, $message, $overrideMessage); @@ -53,7 +53,7 @@ protected function reportToLog(): void { try { /** @var \Leevel\Log\ILog $log */ - $log = \App::make('log'); + $log = \App::proxy()->make('log'); $log->error($this->getMessage(), ['exception' => (string) $this]); } catch (Throwable) { } diff --git a/app/Infra/Exceptions/LockException.php b/app/Infra/Exceptions/LockException.php index 74d79428..0e64d04f 100644 --- a/app/Infra/Exceptions/LockException.php +++ b/app/Infra/Exceptions/LockException.php @@ -23,7 +23,7 @@ public function __construct( int|object $code = 0, string|array $message = '', bool $overrideMessage = false, - \Throwable $previous = null + ?\Throwable $previous = null ) { [$code, $message] = $this->prepareCodeAndMessage($code, $message, $overrideMessage); parent::__construct(Response::HTTP_FAILED_DEPENDENCY, $message, $code, $previous); diff --git a/app/Infra/Exceptions/UnauthorizedHttpException.php b/app/Infra/Exceptions/UnauthorizedHttpException.php index 7c4f4256..6f131ced 100644 --- a/app/Infra/Exceptions/UnauthorizedHttpException.php +++ b/app/Infra/Exceptions/UnauthorizedHttpException.php @@ -19,7 +19,7 @@ public function __construct( int|object $code = 0, string|array $message = '', bool $overrideMessage = false, - \Throwable $previous = null + ?\Throwable $previous = null ) { [$code, $message] = $this->prepareCodeAndMessage($code, $message, $overrideMessage); parent::__construct($message, $code, $previous); diff --git a/app/Infra/Helper/ForceCloseDebug.php b/app/Infra/Helper/ForceCloseDebug.php index 65424ace..0cf21ff2 100644 --- a/app/Infra/Helper/ForceCloseDebug.php +++ b/app/Infra/Helper/ForceCloseDebug.php @@ -28,7 +28,7 @@ public static function handle(): void public static function restore(): void { - Config::set('debug', static::$debug); + Config::proxy()->set('debug', static::$debug); $debugBar = static::getDebugBar(); if (static::$debugBar) { diff --git a/app/Infra/Helper/functions.php b/app/Infra/Helper/functions.php index 2058f27a..baace76b 100644 --- a/app/Infra/Helper/functions.php +++ b/app/Infra/Helper/functions.php @@ -3,7 +3,6 @@ declare(strict_types=1); use App\Infra\Module\RoadRunner\RoadRunnerDump; -use App\Infra\Proxy\Permission; use Leevel\Cache\Manager; use Leevel\Cache\Redis; use Leevel\Database\IDatabase; @@ -22,16 +21,6 @@ function enabledCoroutine(): bool } } -if (!function_exists('permission')) { - /** - * 校验权限. - */ - function permission(string $resource, ?string $method = null): bool - { - return Permission::handle($resource, $method); - } -} - if (!function_exists('sql_listener')) { /** * SQL 监听器. @@ -241,7 +230,7 @@ function response_add_cors_headers(Response $response): Response function redis_cache(): \Redis { /** @var Manager $manager */ - $manager = \App::make('caches'); + $manager = \App::proxy()->make('caches'); /** @var Redis $phpRedis */ $phpRedis = $manager->connect('redis'); diff --git a/app/Infra/Proxy/Demo.php b/app/Infra/Proxy/Demo.php new file mode 100644 index 00000000..6ab658f2 --- /dev/null +++ b/app/Infra/Proxy/Demo.php @@ -0,0 +1,31 @@ +{$method}(...$args); + } + + /** + * 代理服务. + */ + public static function proxy(): DemoService + { + return new DemoService(); + } +} diff --git a/app/Infra/Proxy/Permission.php b/app/Infra/Proxy/Permission.php deleted file mode 100644 index 8a682177..00000000 --- a/app/Infra/Proxy/Permission.php +++ /dev/null @@ -1,35 +0,0 @@ -{$method}(...$args); - } - - /** - * 代理服务. - */ - public static function proxy(): AdminPermission - { - // @phpstan-ignore-next-line - return Container::singletons()->make('permission'); - } -} diff --git a/app/Infra/Service/Demo.php b/app/Infra/Service/Demo.php index 8878f0e3..93dedd16 100644 --- a/app/Infra/Service/Demo.php +++ b/app/Infra/Service/Demo.php @@ -4,12 +4,12 @@ namespace App\Infra\Service; -class Page +class Demo { public function handle(DemoParams $params): array { $params->validate(); - + return [ 'hello' => 'world', ];