/** * Constructor creates cache driver by name. Parameters for * the specific driver may be deployed by the second argument. * * @param string|false The name of the driver * @return void * * TODO normalize case-sensitive names */ private function __construct($name = null, array $params = null) { // load configuration if (self::$conf === null) { // default configuration self::$conf = array('Cache_Lite' => array('cacheDir' => VIVVO_FS_INSTALL_ROOT . 'cache/', 'lifeTime' => null, 'automaticSerialization' => true, 'errorHandlingAPIBreak' => true, 'group' => 'vivvo_cache'), 'SQLite' => array('file' => VIVVO_FS_INSTALL_ROOT . 'cache/sqlite.db', 'schema' => 'CREATE TABLE cache( id VARCHAR(100) PRIMARY KEY, tags VARCHAR(255), lifetime INTEGER, data TEXT);'), 'MySQL' => array('host' => VIVVO_DB_HOST, 'username' => VIVVO_DB_USER, 'password' => VIVVO_DB_PASSWORD, 'database' => VIVVO_DB_DATABASE, 'data_table' => VIVVO_DB_PREFIX . 'cache', 'tags_table' => VIVVO_DB_PREFIX . 'cache_tags')); if (defined('VIVVO_SYSTEM_CACHE_DRIVER_PARAMS')) { self::$conf = array_merge(self::$conf, json_decode(VIVVO_SYSTEM_CACHE_DRIVER_PARAMS, true)); } } $name = $name === null ? VIVVO_SYSTEM_CACHE_DRIVER : trim($name); $driver = 'vivvo_cache_' . $name; $file = VIVVO_FS_CACHE_DRIVER . $name . '.php'; if (!file_exists($file)) { throw new CacheDriverException($driver, 'Driver file could not be found.'); } require_once $file; // Passed params overwrites those in conf.cache.php since they are on-demand $params = $params !== null ? array_merge(self::$conf[$name], $params) : self::$conf[$name]; is_array($params) or $params = array(); // Create our cache driver self::$drivers[$name] = new $driver($params); if (!self::$drivers[$name] instanceof vivvo_cache_driver) { throw new CacheDriverException($driver, 'Driver class does not implement vivvo_cache_driver interface.'); } }