diff --git a/config/exception-notify.php b/config/exception-notify.php index 950d6b6..ffab8f2 100644 --- a/config/exception-notify.php +++ b/config/exception-notify.php @@ -87,7 +87,7 @@ /** * The default reported channels. */ - 'defaults' => [ + 'defaults' => env('EXCEPTION_NOTIFY_DEFAULTS', [ // 'bark', // 'chanify', // 'dingTalk', @@ -104,7 +104,7 @@ // 'telegram', // 'weWork', // 'xiZhi', - ], + ]), /** * The list of channels. diff --git a/src/ExceptionNotifyManager.php b/src/ExceptionNotifyManager.php index a45965c..65c30ff 100644 --- a/src/ExceptionNotifyManager.php +++ b/src/ExceptionNotifyManager.php @@ -83,10 +83,9 @@ public function report(\Throwable $throwable, $channels = null): void return; } - $dispatch = dispatch(new ReportExceptionJob(app(CollectorManager::class)->mapToReports( - (array) ($channels ?? config('exception-notify.defaults')), - $throwable - ))); + $dispatch = dispatch(new ReportExceptionJob( + app(CollectorManager::class)->mapToReports($this->getChannels($channels), $throwable) + )); if ( ! $this->container->runningInConsole() @@ -107,6 +106,19 @@ public function getDefaultDriver() return Arr::first(config('exception-notify.defaults')); } + /** + * @param array|string $channels + */ + protected function getChannels($channels): array + { + $channels ??= config('exception-notify.defaults'); + if (\is_string($channels)) { + $channels = explode(',', $channels); + } + + return (array) $channels; + } + /** * @throws BindingResolutionException *