/** * Create a new cache storage instance. * * @param string $storage * * @return CS\Apc|CS\Dba|CS\File|CS\Memcached|CS\Memory|CS\Pdo|CS\Redis|CS\WinCache * @throws \RuntimeException */ protected static function factory($storage) { $conf = Registry::get('conf'); switch ($storage) { case 'apc': return new CS\Apc($conf['cache']['key']); case 'file': return new CS\File($conf['cache']['storage_path']); case 'pdo': return new CS\Pdo(Pdo\Factory::get($conf['cache']['database']), $conf['cache']['key']); case 'memcached': return new CS\Memcached(Memcached::connection(), $conf['cache']['key']); case 'memory': return new CS\Memory(); case 'redis': return new CS\Redis(Redis::database()); case 'wincache': return new CS\WinCache($conf['cache']['key']); case 'dba': return new CS\Dba(String::ensureTrailing('/', $conf['cache']['storage_path']) . $conf['cache']['key']); default: throw new \RuntimeException("Cache storage {$storage} is not supported."); } }
/** * @param array $conf */ private static function loadPdoDriver(array $conf) { $dbConf = $conf[$conf['environment']]['db']; if (is_array($dbConf) && $conf['environment'] != 'testing') { Registry::set('em', new EntityManager(Pdo\Factory::get($dbConf), $conf['app']['name'])); } }
/** * @param string $type * @param string $for * * @return bool * @throws \DomainException */ protected function createTable($type, $for) { $type = trim($type); try { $pdo = $file = null; $conf = Registry::get('conf'); switch ($for) { case 'cache': $pdo = Factory::get($conf['cache']['database']); $file = 'create-cache-table-' . $type . '.sql'; break; case 'session': $pdo = Factory::get($conf['session']['database']); $file = 'create-session-table-' . $type . '.sql'; break; } $file = str_replace('/', DS, BASE_PATH . 'pimf-framework/core/Pimf/_database/' . $file); return $pdo->exec(file_get_contents(new File($file))) or print_r($pdo->errorInfo(), true); } catch (\PDOException $pdoe) { throw new Bomb($pdoe->getMessage()); } }
/** * @param string $environment * @param array $dbConf * @param string $appName */ private static function loadPdoDriver($environment, $dbConf, $appName) { if (is_array($dbConf) && $environment != 'testing') { self::$em = new EntityManager(Pdo\Factory::get($dbConf), $appName); } }
/** * Create a new session storage instance. * * @param string $storage * * @return Storage\Storage * @throws \RuntimeException */ public static function factory($storage) { switch ($storage) { case 'apc': return new Storage\Apc(Cache::storage('apc')); case 'cookie': return new Storage\Cookie(); case 'file': return new Storage\File(Config::get('session.storage_path')); case 'pdo': return new Storage\Pdo(Pdo\Factory::get(Config::get('session.database'))); case 'memcached': return new Storage\Memcached(Cache::storage('memcached')); case 'memory': return new Storage\Memory(); case 'redis': return new Storage\Redis(Cache::storage('redis')); case 'dba': return new Storage\Dba(Cache::storage('dba')); default: throw new \RuntimeException("Session storage [{$storage}] is not supported."); } }