Skip to content

Commit

Permalink
Add exception handling to Singleton trait
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer committed Jan 3, 2024
1 parent 6ba215e commit b20a8df
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Traits/Singleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace OCC\Basics\Traits;

use Exception;
use LogicException;

/**
Expand All @@ -45,11 +46,17 @@ trait Singleton
* @param mixed ...$args Constructor parameters
*
* @return static The singleton instance
*
* @throws Exception
*/
final public static function getInstance(mixed ...$args): static
{
if (!isset(static::$singleton[static::class])) {
static::$singleton[static::class] = new static(...$args);
try {
static::$singleton[static::class] = new static(...$args);
} catch (Exception $exception) {
throw $exception;
}
}
return static::$singleton[static::class];
}
Expand Down

0 comments on commit b20a8df

Please sign in to comment.