diff options
Diffstat (limited to 'src/Support/SingletonTraitWithArguments.php')
| -rw-r--r-- | src/Support/SingletonTraitWithArguments.php | 25 | 
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Support/SingletonTraitWithArguments.php b/src/Support/SingletonTraitWithArguments.php new file mode 100644 index 0000000..2ac0653 --- /dev/null +++ b/src/Support/SingletonTraitWithArguments.php @@ -0,0 +1,25 @@ +<?php + +namespace PHPIAC\Support; + +use PetrKnap\Php\Singleton\SingletonTrait; + +trait SingletonTraitWithArguments +{ +    use SingletonTrait; + +    /** +     * @param mixed ...$arguments +     * +     * @return self +     */ +    public static function getInstance(mixed ...$arguments) +    { +        $self = get_called_class(); +        if (! isset(self::$instances[$self])) { +            self::$instances[$self] = new $self(...$arguments); +        } + +        return self::$instances[$self]; +    } +}  | 
