$this]; } /** * Fetches and returns the currently selected ObjectStorageProvider * * @throws ObjectStorageException * @return iObjectStorageProvider */ public function getStorage(): iObjectStorageProvider { // If the provider is already loaded, return that one if (isset($this->provider)) return $this->provider; // Load the config, if it isn't loaded yet if (!isset($this->cfg)) { try { /** @var Config $configs */ $configs = Factory::getInstance('config'); $this->cfg = $configs->getConfig('objectstorage')->toArray(); } catch (ConfigException | FactoryException $e) { throw new ObjectStorageException("Could not get ObjectStorageProvider. No config file named 'config.objectstorage.php' could be found."); } } // Get the currently selected ObjectStorageProvider $selected = $this->cfg['ObjectStorageProvider']; if (is_null($selected)) throw new ObjectStorageException("Could not get ObjectStorageProvider. Selected provider is null!"); // Try and load the ObjectStorageProvider $class = '\FuzeWorks\ObjectStorage\Provider\\' . $selected; if (!class_exists($class, true)) throw new ObjectStorageException("Could not get ObjectStorageProvider. Selected provider '".$selected."' is not recognized."); /** @var iObjectStorageProvider $provider */ $provider = new $class(); if (!$provider instanceof iObjectStorageProvider) throw new ObjectStorageException("Could not get ObjectStorageProvider. Selected provider '".$selected."' is not an instance of iObjectStorageProvider'."); // Fetch the parameters $params = isset($this->cfg[$selected]) && is_array($this->cfg[$selected]) ? $this->cfg[$selected] : []; if (!$provider->init($params)) throw new ObjectStorageException("Could not get ObjectStorageProvider. Selected provider '".$selected."' failed to load."); $this->provider = $provider; return $this->provider; } /** * Returns a PSR compatible Cache object * * @return CacheInterface * @throws ObjectStorageException */ public function getCache(): CacheInterface { if (isset($this->cache)) return $this->cache; $storageProvider = $this->getStorage(); $this->cache = new ObjectStorageCache($storageProvider); return $this->cache; } public function onAddComponent(Configurator $configurator) { } public function onCreateContainer(Factory $container) { } }