Skip to content

Commit

Permalink
refactor(ExceptionNotifyManager): Improve createDriver method
Browse files Browse the repository at this point in the history
- Added a check for custom creators
- Improved handling of driver creation logic
- Added support for custom driver classes
- Throw exception if driver is not supported
  • Loading branch information
guanguans committed Apr 18, 2024
1 parent afbd0ff commit f8a0242
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/ExceptionNotifyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ protected function attempt(string $key, int $maxAttempts, int $decaySeconds = 60
});
}

protected function createDriver($driver)
{
if (isset($this->customCreators[$driver])) {
return $this->callCustomCreator($driver);
}

$config = $this->config->get("exception-notify.channels.$driver");

$studlyName = Str::studly($config['driver'] ?? $driver);

if (method_exists($this, $method = "create{$studlyName}Driver")) {
return $this->{$method}($config);
}

if (class_exists($class = "Guanguans\\LaravelExceptionNotify\\Channels\\{$studlyName}Channel")) {
return new $class($config);
}

throw new \InvalidArgumentException("Driver [$driver] not supported.");
}

protected function createBarkDriver(): BarkChannel
{
return new BarkChannel(
Expand Down

0 comments on commit f8a0242

Please sign in to comment.