作者 竞泽

feat:inject

@@ -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 }
@@ -34,4 +34,9 @@ class Wx implements AgentInterface @@ -34,4 +34,9 @@ class Wx implements AgentInterface
34 ] 34 ]
35 ]); 35 ]);
36 } 36 }
  37 +
  38 + public function dsiabled(): bool
  39 + {
  40 + return !$this->enable;
  41 + }
37 } 42 }
@@ -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,14 +28,18 @@ class Dispatcher implements CallbackInterface @@ -28,14 +28,18 @@ 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) { 31 + if (!$agent instanceof AgentInterface) {
  32 + continue;
  33 + }
  34 + if ($agent->dsiabled()) {
  35 + continue;
  36 + }
32 try { 37 try {
33 $agent->report($body); 38 $agent->report($body);
34 } catch (\Exception $exception) { 39 } catch (\Exception $exception) {
35 app('log')->error($exception->getMessage()); 40 app('log')->error($exception->getMessage());
36 } 41 }
37 } 42 }
38 - }  
39 }; 43 };
40 } 44 }
41 45
@@ -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 }