正在显示
5 个修改的文件
包含
44 行增加
和
9 行删除
| @@ -18,9 +18,12 @@ class Ding implements AgentInterface | @@ -18,9 +18,12 @@ class Ding implements AgentInterface | ||
| 18 | 18 | ||
| 19 | public function report(array $content) | 19 | public function report(array $content) |
| 20 | { | 20 | { |
| 21 | - $talk = new DingTalkService([ | ||
| 22 | - | ||
| 23 | - ]); | 21 | + $talk = new DingTalkService(['token' => $this->token, 'enabled' => true, 'secret' => $this->secret]); |
| 24 | $talk->setTextMessage(join("\n", $content))->send(); | 22 | $talk->setTextMessage(join("\n", $content))->send(); |
| 25 | } | 23 | } |
| 24 | + | ||
| 25 | + public function dsiabled(): bool | ||
| 26 | + { | ||
| 27 | + return !$this->enable; | ||
| 28 | + } | ||
| 26 | } | 29 | } |
| @@ -5,4 +5,6 @@ namespace Lackoxygen\ExceptionPush\Contracts; | @@ -5,4 +5,6 @@ namespace Lackoxygen\ExceptionPush\Contracts; | ||
| 5 | interface AgentInterface | 5 | interface AgentInterface |
| 6 | { | 6 | { |
| 7 | public function report(array $content); | 7 | public function report(array $content); |
| 8 | + | ||
| 9 | + public function dsiabled(): bool; | ||
| 8 | } | 10 | } |
| @@ -28,12 +28,16 @@ class Dispatcher implements CallbackInterface | @@ -28,12 +28,16 @@ class Dispatcher implements CallbackInterface | ||
| 28 | { | 28 | { |
| 29 | return function ($agents, $body) { | 29 | return function ($agents, $body) { |
| 30 | foreach ($agents as $agent) { | 30 | foreach ($agents as $agent) { |
| 31 | - if ($agent instanceof AgentInterface) { | ||
| 32 | - try { | ||
| 33 | - $agent->report($body); | ||
| 34 | - } catch (\Exception $exception) { | ||
| 35 | - app('log')->error($exception->getMessage()); | ||
| 36 | - } | 31 | + if (!$agent instanceof AgentInterface) { |
| 32 | + continue; | ||
| 33 | + } | ||
| 34 | + if ($agent->dsiabled()) { | ||
| 35 | + continue; | ||
| 36 | + } | ||
| 37 | + try { | ||
| 38 | + $agent->report($body); | ||
| 39 | + } catch (\Exception $exception) { | ||
| 40 | + app('log')->error($exception->getMessage()); | ||
| 37 | } | 41 | } |
| 38 | } | 42 | } |
| 39 | }; | 43 | }; |
| @@ -10,9 +10,30 @@ class ExceptionPushProvider extends ServiceProvider | @@ -10,9 +10,30 @@ class ExceptionPushProvider extends ServiceProvider | ||
| 10 | { | 10 | { |
| 11 | protected array $commands = []; | 11 | protected array $commands = []; |
| 12 | 12 | ||
| 13 | + /** | ||
| 14 | + * @return void | ||
| 15 | + */ | ||
| 16 | + public function boot() | ||
| 17 | + { | ||
| 18 | + $configPath = __DIR__.'/../publish/exception.push.php'; | ||
| 19 | + $this->publishes([ | ||
| 20 | + $configPath => config_path('exception.push.php') | ||
| 21 | + ], 'lackoxygen-exception-push'); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + | ||
| 13 | public function register() | 25 | public function register() |
| 14 | { | 26 | { |
| 15 | $this->app->singleton(ExceptionHandler::class, Handler::class); | 27 | $this->app->singleton(ExceptionHandler::class, Handler::class); |
| 16 | $this->app->singleton('exception.push', ExceptionPush::class); | 28 | $this->app->singleton('exception.push', ExceptionPush::class); |
| 17 | } | 29 | } |
| 30 | + | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * @return string[] | ||
| 34 | + */ | ||
| 35 | + public function provides(): array | ||
| 36 | + { | ||
| 37 | + return ['exception.push']; | ||
| 38 | + } | ||
| 18 | } | 39 | } |
-
请 注册 或 登录 后发表评论