function load($dsn)
{
$fw = Base::instance();
if ($dsn = trim($dsn)) {
if (preg_match('/^redis=(.+)/', $dsn, $parts) && extension_loaded('redis')) {
list($host, $port, $db) = explode(':', $parts[1]) + [1 => 6379, 2 => NULL];
$this->ref = new Redis();
if (!$this->ref->connect($host, $port, 2)) {
$this->ref = NULL;
}
if (isset($db)) {
$this->ref->select($db);
}
} elseif (preg_match('/^memcache=(.+)/', $dsn, $parts) && extension_loaded('memcache')) {
foreach ($fw->split($parts[1]) as $server) {
list($host, $port) = explode(':', $server) + [1 => 11211];
if (empty($this->ref)) {
$this->ref = @memcache_connect($host, $port) ?: NULL;
} else {
memcache_add_server($this->ref, $host, $port);
}
}
}
if (empty($this->ref) && !preg_match('/^folder\\h*=/', $dsn)) {
$dsn = ($grep = preg_grep('/^(apc|wincache|xcache)/', array_map('strtolower', get_loaded_extensions()))) ? current($grep) : 'folder=' . $fw->get('TEMP') . 'cache/';
}
if (preg_match('/^folder\\h*=\\h*(.+)/', $dsn, $parts) && !is_dir($parts[1])) {
mkdir($parts[1], Base::MODE, TRUE);
}
}
$this->prefix = $fw->get('SEED');
return $this->dsn = $dsn;
}
/** * Renders template to output. * @return void */ public function render() { if ($this->file == NULL) { // intentionally == throw new InvalidStateException("Template file name was not specified."); } $cache = new Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate'); if ($storage instanceof PhpFileStorage) { $storage->hint = str_replace(dirname(dirname($this->file)), '', $this->file); } $cached = $compiled = $cache->load($this->file); if ($compiled === NULL) { try { $compiled = "<?php\n\n// source file: {$this->file}\n\n?>" . $this->compile(); } catch (TemplateException $e) { $e->setSourceFile($this->file); throw $e; } $cache->save($this->file, $compiled, array(Cache::FILES => $this->file, Cache::CONSTS => 'Framework::REVISION')); $cached = $cache->load($this->file); } if ($cached !== NULL && $storage instanceof PhpFileStorage) { LimitedScope::load($cached['file'], $this->getParameters()); } else { LimitedScope::evaluate($compiled, $this->getParameters()); } }