+ // @todo 2020.09 Remove this call after 2 releases
+ $name = $this->checkLegacyBackend($name);
+
+ // If there's no cached instance create a new instance
+ if (!isset($this->backendInstances[$name])) {
+ // If the current name isn't a valid backend (or the SystemResource instance) create it
+ if ($this->isValidBackend($name, $onlyUserBackend)) {
+ switch ($name) {
+ // Try the filesystem backend
+ case Storage\Filesystem::getName():
+ $this->backendInstances[$name] = new Storage\Filesystem($this->config, $this->logger, $this->l10n);
+ break;
+ // try the database backend
+ case Storage\Database::getName():
+ $this->backendInstances[$name] = new Storage\Database($this->dba, $this->logger, $this->l10n);
+ break;
+ // at least, try if there's an addon for the backend
+ case Storage\SystemResource::getName():
+ $this->backendInstances[$name] = new Storage\SystemResource();
+ break;
+ default:
+ $data = [
+ 'name' => $name,
+ 'storage' => null,
+ ];
+ Hook::callAll('storage_instance', $data);
+ if (($data['storage'] ?? null) instanceof Storage\IStorage) {
+ $this->backendInstances[$data['name'] ?? $name] = $data['storage'];
+ } else {
+ return null;
+ }
+ break;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ return $this->backendInstances[$name];