summaryrefslogtreecommitdiff
path: root/src/Support/SingletonTraitWithArguments.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Support/SingletonTraitWithArguments.php')
-rw-r--r--src/Support/SingletonTraitWithArguments.php25
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];
+ }
+}