Skip to content

Commit

Permalink
refactor(ExceptionNotifyManager): add getChannels method
Browse files Browse the repository at this point in the history
- Add a new protected method 'getChannels' in the ExceptionNotifyManager class
- Accept an array or string as the 'channels' parameter
- If 'channels' is not provided, use the 'defaults' value from the config
- If 'channels' is a string, convert it to an array using explode
- Return the 'channels' as an array
  • Loading branch information
guanguans committed Aug 8, 2023
1 parent 2c5e46a commit 70f58ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions config/exception-notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
/**
* The default reported channels.
*/
'defaults' => [
'defaults' => env('EXCEPTION_NOTIFY_DEFAULTS', [
// 'bark',
// 'chanify',
// 'dingTalk',
Expand All @@ -104,7 +104,7 @@
// 'telegram',
// 'weWork',
// 'xiZhi',
],
]),

/**
* The list of channels.
Expand Down
20 changes: 16 additions & 4 deletions src/ExceptionNotifyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
*
Expand Down

0 comments on commit 70f58ce

Please sign in to comment.