public static function create(\browserfs\website\Cache &$cache, $namespaceName) { if (!is_string($namespaceName)) { throw new \browserfs\Exception('Invalid argument: $namespaceName: string expected!'); } $result = new self(null, $cache->getName() . '_' . $namespaceName); $result->cache = $cache; $result->namespace = $namespaceName; return $result; }
protected function addCacheSource($cacheName, $cacheURI) { $info = @parse_url($cacheURI); if ($info === false || !is_array($info) || !isset($info['scheme'])) { throw new \browserfs\Exception('URL "' . $cacheURI . '" is not a valid cache URI ( source = "' . $cacheName . '" )'); } $cacheType = $info['scheme']; $cache = \browserfs\website\Cache::factory($cacheType, $info, $cacheName); $this->caches[$cacheName] = $cache; }
public static function factory($cacheTypeSchemaName, $cacheDriverConnectionConfig, $cacheSourceName) { if (!is_string($cacheTypeSchemaName) || $cacheTypeSchemaName === '') { throw new \browserfs\Exception('Invalid argument $cacheTypeSchemaName: non-empty string expected!'); } if (!is_array($cacheDriverConnectionConfig)) { throw new \browserfs\Exception('Invalid argument $cacheDriverConnectionConfig: array expected!'); } if (!is_string($cacheSourceName) || $cacheSourceName === '') { throw new \browserfs\Exception('Invalid argument $cacheSourceName: Expected non-empty string!'); } if (!isset(self::$factories[$cacheTypeSchemaName])) { throw new \browserfs\Exception('Failed to instantiate cache of type "' . $cacheTypeSchemaName . '": No driver provider registered!'); } try { $className = self::$factories[$cacheTypeSchemaName]; if (!class_exists($className)) { throw new \browserfs\Exception('Class "' . $className . '" implementing cache of type "' . $cacheTypeSchemaName . '" was not found!'); } $result = new $className($cacheDriverConnectionConfig, $cacheSourceName); if (!$result instanceof \browserfs\website\Cache) { throw new \browserfs\Exception('Although a declared cache driver for scheme "' . $cacheTypeSchemaName . '" was found in class "' . $className . '", it could not be used because it does not extend \\browserfs\\website\\Cache'); } return $result; } catch (\Exception $e) { throw new \browserfs\Exception('Failed to initialize cache source "' . $cacheSourceName . '": ' . $e->getMessage(), 1, $e); } } } \browserfs\website\Cache::registerDriver('memory', '\\' . __NAMESPACE__ . '\\Cache\\Driver\\Memory');