instances[$key] = $factory; } /** * Ruft eine registrierte Instanz ab und erstellt sie falls nötig. * * @param string $key Der Schlüssel der angeforderten Instanz. * @return mixed Die abgerufene Instanz. * @throws Exception Wenn keine Instanz mit dem gegebenen Schlüssel existiert. */ public function get(string $key): mixed { if(!isset($this->instances[$key])) { throw new Exception("No instance found for {$key}"); } return $this->instances[$key]($this); } }