summaryrefslogtreecommitdiff
path: root/src/Support/SingletonTraitWithArguments.php
blob: 2ac065348b2b845d3fb4a050c6ac95845e258f91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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];
    }
}