/** * Renders template to output. * @return void */ public function render() { if ($this->file == NULL) { // intentionally == throw new Nette\InvalidStateException("Template file name was not specified."); } $cache = new Caching\Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate'); if ($storage instanceof Caching\Storages\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 (FilterException $e) { $e->setSourceFile($this->file); throw $e; } $cache->save($this->file, $compiled, array(Caching\Cache::FILES => $this->file, Caching\Cache::CONSTS => 'Nette\\Framework::REVISION')); $cache->release(); $cached = $cache->load($this->file); } if ($cached !== NULL && $storage instanceof Caching\Storages\PhpFileStorage) { Nette\Utils\LimitedScope::load($cached['file'], $this->getParams()); } else { Nette\Utils\LimitedScope::evaluate($compiled, $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."); } $this->__set('template', $this); $shortName = str_replace(dirname(dirname($this->file)), '', $this->file); $cache = new Cache($this->getCacheStorage(), 'Nette.FileTemplate'); $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::CONSTS => 'Nette\\Framework::REVISION')); $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()); } }
/** * 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); $cache = new Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate'); if ($storage instanceof TemplateCacheStorage) { $storage->hint = str_replace(dirname(dirname($this->file)), '', $this->file); } $cached = $content = $cache[$this->file]; if ($content === NULL) { try { $content = $this->compile(file_get_contents($this->file)); $content = "<?php\n\n// source file: {$this->file}\n\n?>{$content}"; } catch (TemplateException $e) { $e->setSourceFile($this->file); throw $e; } $cache->save($this->file, $content, array(Cache::FILES => $this->file, Cache::CONSTS => 'Nette\\Framework::REVISION')); $cache->release(); $cached = $cache[$this->file]; } if ($cached !== NULL && $storage instanceof TemplateCacheStorage) { LimitedScope::load($cached['file'], $this->getParams()); flock($cached['handle'], LOCK_UN); fclose($cached['handle']); } else { LimitedScope::evaluate($content, $this->getParams()); } }
/** * Renders template to output. * @return void */ public function render() { $cache = new Caching\Cache($storage = $this->getCacheStorage(), 'Nette.Template'); $cached = $compiled = $cache->load($this->source); if ($compiled === NULL) { $compiled = $this->compile(); $cache->save($this->source, $compiled, array(Caching\Cache::CONSTS => 'Nette\\Framework::REVISION')); $cache->release(); $cached = $cache->load($this->source); } if ($cached !== NULL && $storage instanceof Caching\Storages\PhpFileStorage) { Nette\Utils\LimitedScope::load($cached['file'], $this->getParams()); } else { Nette\Utils\LimitedScope::evaluate($compiled, $this->getParams()); } }