作者 竞泽

feat:inject

... ... @@ -18,9 +18,12 @@ class Ding implements AgentInterface
public function report(array $content)
{
$talk = new DingTalkService([
]);
$talk = new DingTalkService(['token' => $this->token, 'enabled' => true, 'secret' => $this->secret]);
$talk->setTextMessage(join("\n", $content))->send();
}
public function dsiabled(): bool
{
return !$this->enable;
}
}
... ...
... ... @@ -34,4 +34,9 @@ class Wx implements AgentInterface
]
]);
}
public function dsiabled(): bool
{
return !$this->enable;
}
}
... ...
... ... @@ -5,4 +5,6 @@ namespace Lackoxygen\ExceptionPush\Contracts;
interface AgentInterface
{
public function report(array $content);
public function dsiabled(): bool;
}
... ...
... ... @@ -28,14 +28,18 @@ class Dispatcher implements CallbackInterface
{
return function ($agents, $body) {
foreach ($agents as $agent) {
if ($agent instanceof AgentInterface) {
if (!$agent instanceof AgentInterface) {
continue;
}
if ($agent->dsiabled()) {
continue;
}
try {
$agent->report($body);
} catch (\Exception $exception) {
app('log')->error($exception->getMessage());
}
}
}
};
}
... ...
... ... @@ -10,9 +10,30 @@ class ExceptionPushProvider extends ServiceProvider
{
protected array $commands = [];
/**
* @return void
*/
public function boot()
{
$configPath = __DIR__.'/../publish/exception.push.php';
$this->publishes([
$configPath => config_path('exception.push.php')
], 'lackoxygen-exception-push');
}
public function register()
{
$this->app->singleton(ExceptionHandler::class, Handler::class);
$this->app->singleton('exception.push', ExceptionPush::class);
}
/**
* @return string[]
*/
public function provides(): array
{
return ['exception.push'];
}
}
... ...