/** * Renders template to output. * @return void */ public function render() { $cache = new Cache($storage = $this->getCacheStorage(), 'Nette.Template'); $cached = $compiled = $cache->load($this->source); if ($compiled === NULL) { $compiled = $this->compile(); $cache->save($this->source, $compiled, array(Cache::CONSTS => 'Framework::REVISION')); $cached = $cache->load($this->source); } if ($cached !== NULL && $storage instanceof PhpFileStorage) { LimitedScope::load($cached['file'], $this->getParameters()); } else { LimitedScope::evaluate($compiled, $this->getParameters()); } }
/** * Renders template to output. * @return void */ public function render() { $cache = Environment::getCache('StringTemplate'); $key = md5($this->content); $content = $cache[$key]; if ($content === NULL) { // not cached if (!$this->getFilters()) { $this->onPrepareFilters($this); } $cache[$key] = $content = $this->compile($this->content); } $this->__set('template', $this); /*Nette\Loaders\*/ LimitedScope::evaluate($content, $this->getParams()); }
/** * Renders template to output. * @return void */ public function render() { if ($this->file == NULL) { // intentionally == throw new InvalidStateException("Template file name was not specified."); } elseif (!is_file($this->file) || !is_readable($this->file)) { throw new FileNotFoundException("Missing template file '{$this->file}'."); } $this->__set('template', $this); $cache = new Cache($this->getCacheStorage(), 'Nette.Template'); $key = md5($this->file) . '.' . basename($this->file); $cached = $content = $cache[$key]; if ($content === NULL) { if (!$this->getFilters()) { $this->onPrepareFilters($this); } if (!$this->getFilters()) { /*Nette\Loaders\*/ LimitedScope::load($this->file, $this->getParams()); return; } try { $shortName = $this->file; $shortName = str_replace(Environment::getVariable('templatesDir'), "…", $shortName); } catch (Exception $foo) { } $content = $this->compile(file_get_contents($this->file), "file {$shortName}"); $cache->save($key, $content, array(Cache::FILES => $this->file, Cache::EXPIRE => self::$cacheExpire)); $cached = $cache[$key]; } if ($cached !== NULL && self::$cacheStorage instanceof TemplateCacheStorage) { /*Nette\Loaders\*/ LimitedScope::load($cached['file'], $this->getParams()); fclose($cached['handle']); } else { /*Nette\Loaders\*/ LimitedScope::evaluate($content, $this->getParams()); } }
/** * 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()); } }
/** * Renders template to output. * @return void */ public function render() { if ($this->file == NULL) { // intentionally == throw new InvalidStateException("Template file name was not specified."); } $this->__set('template', $this); $shortName = str_replace(Environment::getVariable('appDir'), '', $this->file); $cache = new Cache($this->getCacheStorage(), 'Nette.Template'); $key = trim(strtr($shortName, '\\/@', '.._'), '.') . '-' . md5($this->file); $cached = $content = $cache[$key]; if ($content === NULL) { if (!$this->getFilters()) { $this->onPrepareFilters($this); } if (!$this->getFilters()) { LimitedScope::load($this->file, $this->getParams()); return; } $content = $this->compile(file_get_contents($this->file), "file …{$shortName}"); $cache->save($key, $content, array(Cache::FILES => $this->file, Cache::EXPIRE => self::$cacheExpire)); $cache->release(); $cached = $cache[$key]; } if ($cached !== NULL && self::$cacheStorage instanceof TemplateCacheStorage) { LimitedScope::load($cached['file'], $this->getParams()); fclose($cached['handle']); } else { LimitedScope::evaluate($content, $this->getParams()); } }
/** * Returns system DI container. * @return SystemContainer */ public function createContainer() { if ($cacheDir = $this->getCacheDirectory()) { $cache = new Cache(new PhpFileStorage($cacheDir), 'Nette.Configurator'); $cacheKey = array($this->parameters, $this->files); $cached = $cache->load($cacheKey); if (!$cached) { $code = $this->buildContainer($dependencies); $cache->save($cacheKey, $code, array(Cache::FILES => $dependencies)); $cached = $cache->load($cacheKey); } LimitedScope::load($cached['file'], TRUE); } elseif ($this->files) { throw new InvalidStateException("Set path to temporary directory using setTempDirectory()."); } else { LimitedScope::evaluate($this->buildContainer()); // back compatibility with Environment } $container = new $this->parameters['container']['class'](); $container->initialize(); Environment::setContext($container); // back compatibility return $container; }
/** * Renders template to output. * @return void */ public function render() { if ($this->file == NULL) { // intentionally == throw new InvalidStateException("Template file name was not specified."); } elseif (!is_file($this->file) || !is_readable($this->file)) { throw new FileNotFoundException("Missing template file '{$this->file}'."); } $this->params['template'] = $this; if (!count($this->filters)) { LimitedScope::load($this->file, $this->params); return; } $cache = new Cache($this->getCacheStorage(), 'Nette.Template'); $key = md5($this->file) . count($this->filters) . '.' . basename($this->file); $cached = $content = $cache[$key]; if ($content === NULL) { $content = file_get_contents($this->file); foreach ($this->filters as $filter) { if (!is_callable($filter)) { $able = is_callable($filter, TRUE, $textual); throw new InvalidStateException("Filter '{$textual}' is not " . ($able ? 'callable.' : 'valid PHP callback.')); } // remove PHP code $res = ''; $blocks = array(); unset($php); foreach (token_get_all($content) as $token) { if (is_array($token)) { if ($token[0] === T_INLINE_HTML) { $res .= $token[1]; unset($php); } else { if (!isset($php)) { $res .= $php = "@php:p" . count($blocks) . "@"; $php =& $blocks[$php]; } $php .= $token[1]; } } else { $php .= $token; } } try { $content = call_user_func($filter, $res); } catch (Exception $e) { is_callable($filter, TRUE, $textual); throw new InvalidStateException("Filter {$textual}: " . $e->getMessage() . " (in file {$this->file})", 0, $e); } $content = strtr($content, $blocks); // put PHP code back } $content = "<?php\n// template {$this->file}\n?>{$content}"; $cache->save($key, $content, array(Cache::FILES => $this->file, Cache::EXPIRE => self::$cacheExpire)); $cached = $cache[$key]; } if ($cached !== NULL && self::$cacheStorage instanceof TemplateCacheStorage) { LimitedScope::load($cached['file'], $this->params); fclose($cached['handle']); } else { LimitedScope::evaluate($content, $this->params); } }