6 protected static $repo = [];
12 public static function getById($id)
14 if (!array_key_exists(__CLASS__, self::$repo))
16 self::$repo[__CLASS__] = [];
19 if (!array_key_exists($id, self::$repo[__CLASS__]))
23 self::$repo[__CLASS__][$id] =
new static($id);
30 return self::$repo[__CLASS__][$id];
35 if (array_key_exists(__CLASS__, self::$repo))
37 foreach (self::$repo[__CLASS__] as $key => $object)
39 if ($object === $this)
41 unset(self::$repo[__CLASS__][$key]);
52 public static function getInstance($object)
54 if ($object instanceof
static)
58 return static::getById($object);