コード例 #1
0
ファイル: Cache.php プロジェクト: browserfs/website
    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');