Beispiel #1
0
 function render()
 {
     if ($this->getFile() == NULL) {
         throw new InvalidStateException("Template file name was not specified.");
     }
     $cache = new NCache($storage = $this->getCacheStorage(), 'wplatte');
     if ($storage instanceof NPhpFileStorage) {
         $storage->hint = str_replace(dirname(dirname($this->getFile())), '', $this->getFile());
     }
     $cached = $compiled = $cache->load($this->getFile());
     if ($compiled === NULL) {
         try {
             $compiled = "<?php\n\n// source file: {$this->getFile()}\n\n?>" . $this->compile();
         } catch (NTemplateException $e) {
             $e->setSourceFile($this->getFile());
             throw $e;
         }
         $cache->save($this->getFile(), $compiled, array(NCache::FILES => $this->getFile(), NCache::CONSTS => array('NFramework::REVISION', 'WPLATTE_CACHE_VERSION')));
         $cache->release();
         $cached = $cache->load($this->getFile());
     }
     if ($cached !== NULL && $storage instanceof NPhpFileStorage) {
         NLimitedScope::load($cached['file'], $this->getParams());
     } else {
         NLimitedScope::evaluate($compiled, $this->getParams());
     }
 }
Beispiel #2
0
 function render()
 {
     if ($this->file == NULL) {
         throw new InvalidStateException("Template file name was not specified.");
     }
     $this->__set('template', $this);
     $cache = new NCache($storage = $this->getCacheStorage(), 'Nette.FileTemplate');
     if ($storage instanceof NTemplateCacheStorage) {
         $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 (NTemplateException $e) {
             $e->setSourceFile($this->file);
             throw $e;
         }
         $cache->save($this->file, $content, array(NCache::FILES => $this->file, NCache::EXPIRATION => self::$cacheExpire, NCache::CONSTS => 'NFramework::REVISION'));
         $cache->release();
         $cached = $cache[$this->file];
     }
     if ($cached !== NULL && $storage instanceof NTemplateCacheStorage) {
         NLimitedScope::load($cached['file'], $this->getParams());
         fclose($cached['handle']);
     } else {
         NLimitedScope::evaluate($content, $this->getParams());
     }
 }
Beispiel #3
0
	/**
	 * Renders template to output.
	 * @return void
	 */
	public function render()
	{
		$cache = new NCache($storage = $this->getCacheStorage(), 'Nette.Template');
		$cached = $compiled = $cache->load($this->source);

		if ($compiled === NULL) {
			$compiled = $this->compile();
			$cache->save($this->source, $compiled, array(NCache::CONSTS => 'NFramework::REVISION'));
			$cached = $cache->load($this->source);
		}

		if ($cached !== NULL && $storage instanceof NPhpFileStorage) {
			NLimitedScope::load($cached['file'], $this->getParameters());
		} else {
			NLimitedScope::evaluate($compiled, $this->getParameters());
		}
	}
	/**
	 * Returns system DI container.
	 * @return SystemContainer
	 */
	public function createContainer()
	{
		if ($cacheDir = $this->getCacheDirectory()) {
			$cache = new NCache(new NPhpFileStorage($cacheDir), 'Nette.Configurator');
			$cacheKey = array($this->params, $this->files);
			$cached = $cache->load($cacheKey);
			if (!$cached) {
				$code = $this->buildContainer($dependencies);
				$cache->save($cacheKey, $code, array(
					NCache::FILES => $this->params['productionMode'] ? NULL : $dependencies,
				));
				$cached = $cache->load($cacheKey);
			}
			NLimitedScope::load($cached['file'], TRUE);

		} elseif ($this->files) {
			throw new InvalidStateException("Set path to temporary directory using setTempDirectory().");

		} else {
			NLimitedScope::evaluate($this->buildContainer()); // back compatibility with Environment
		}

		$container = new $this->params['container']['class'];
		$container->initialize();
		NEnvironment::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.");
		}

		$cache = new NCache($storage = $this->getCacheStorage(), 'Nette.FileTemplate');
		if ($storage instanceof NPhpFileStorage) {
			$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 (NTemplateException $e) {
				$e->setSourceFile($this->file);
				throw $e;
			}

			$cache->save($this->file, $compiled, array(
				NCache::FILES => $this->file,
				NCache::CONSTS => 'NFramework::REVISION',
			));
			$cached = $cache->load($this->file);
		}

		if ($cached !== NULL && $storage instanceof NPhpFileStorage) {
			NLimitedScope::load($cached['file'], $this->getParameters());
		} else {
			NLimitedScope::evaluate($compiled, $this->getParameters());
		}
	}
Beispiel #6
0
 function render()
 {
     if ($this->file == NULL) {
         throw new InvalidStateException("Template file name was not specified.");
     }
     $this->__set('template', $this);
     $shortName = str_replace(NEnvironment::getVariable('appDir'), '', $this->file);
     $cache = new NCache($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()) {
             NLimitedScope::load($this->file, $this->getParams());
             return;
         }
         $content = $this->compile(file_get_contents($this->file), "file …{$shortName}");
         $cache->save($key, $content, array(NCache::FILES => $this->file, NCache::EXPIRE => self::$cacheExpire));
         $cache->release();
         $cached = $cache[$key];
     }
     if ($cached !== NULL && self::$cacheStorage instanceof NTemplateCacheStorage) {
         NLimitedScope::load($cached['file'], $this->getParams());
         fclose($cached['handle']);
     } else {
         NLimitedScope::evaluate($content, $this->getParams());
     }
 }