ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SingletonTrait.php
Go to the documentation of this file.
1 <?php namespace ILIAS\GlobalScreen;
2 
8 trait SingletonTrait
9 {
10 
14  private static $services = [];
15 
16 
22  private function get(string $class_name)
23  {
24  if (!isset(self::$services[$class_name])) {
25  self::$services[$class_name] = new $class_name();
26  }
27 
28  return self::$services[$class_name];
29  }
30 
31 
37  private function getWithArgument(string $class_name, $argument)
38  {
39  if (!isset(self::$services[$class_name])) {
40  self::$services[$class_name] = new $class_name($argument);
41  }
42 
43  return self::$services[$class_name];
44  }
45 }
getWithArgument(string $class_name, $argument)