using() public static method

public static using ( MacroNode $node )
$node MacroNode
示例#1
0
 /**
  * New node is found. Returns FALSE to reject.
  *
  * @param MacroNode $node
  * @return bool
  * @throws Latte\CompileException
  */
 public function nodeOpened(MacroNode $node)
 {
     if ($node->prefix) {
         return false;
     }
     if ($node->modifiers) {
         throw new Latte\CompileException("Modifiers are not allowed in {{$node->name}}.");
     }
     $file = $node->tokenizer->fetchWord();
     if ($file === false) {
         throw new Latte\CompileException("Missing file name in {{$node->name}}.");
     } elseif ($node->tokenizer->fetchWord()) {
         throw new Latte\CompileException("Multiple arguments are not supported in {{$node->name}}.");
     }
     $node->isEmpty = true;
     $node->modifiers = '|safeurl|escape';
     // auto-escape
     $writer = Latte\PhpWriter::using($node, $this->compiler);
     if ($this->debugMode) {
         $node->openingCode = $writer->write('<?php echo %modify(%1.word . \'?\' . Nepada\\BustCache\\Helpers::timestamp(%0.var . %1.word)) ?>', $this->wwwDir, $file);
     } elseif (preg_match('#^(["\']?)[^$\'"]*\\1$#', $file)) {
         // Static path
         $file = trim($file, '"\'');
         $url = $file . '?' . Helpers::hash($this->wwwDir . $file);
         $url = Latte\Runtime\Filters::safeUrl($url);
         $node->openingCode = $writer->write('<?php echo %escape(%var) ?>', $url);
     } else {
         $node->openingCode = $writer->write('<?php echo %modify(%1.word . \'?\' . Nepada\\BustCache\\Helpers::hash(%0.var . %1.word)) ?>', $this->wwwDir, $file);
     }
 }
示例#2
0
 /**
  * New node is found.
  * @return bool
  */
 public function nodeOpened(Latte\MacroNode $node)
 {
     if ($node->modifiers) {
         trigger_error("Modifiers are not allowed in {{$node->name}}", E_USER_WARNING);
     }
     $this->used = TRUE;
     $node->isEmpty = FALSE;
     $node->openingCode = Latte\PhpWriter::using($node)->write('<?php if (Nette\\Bridges\\CacheLatte\\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>', Nette\Utils\Random::generate());
 }
示例#3
0
 /**
  * New node is found.
  * @return bool
  */
 public function nodeOpened(Latte\MacroNode $node)
 {
     if ($node->modifiers) {
         throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation());
     }
     $this->used = TRUE;
     $node->empty = FALSE;
     $node->openingCode = Latte\PhpWriter::using($node)->write('<?php if (Nette\\Bridges\\CacheLatte\\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>', Nette\Utils\Random::generate());
 }
示例#4
0
	/**
	 * New node is found.
	 * @return bool
	 */
	public function nodeOpened(Latte\MacroNode $node)
	{
		$this->used = TRUE;
		$node->isEmpty = FALSE;
		$node->openingCode = Latte\PhpWriter::using($node)
			->write('<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>',
				Nette\Utils\Random::generate()
			);
	}
 private function compile(MacroNode $node, $def)
 {
     $node->tokenizer->reset();
     $writer = PhpWriter::using($node, $this->compiler);
     if (is_string($def)) {
         return $writer->write($def);
     } else {
         return callback($def)->invoke($node, $writer);
     }
 }
示例#6
0
 /**
  * {link destination [,] [params]}
  * {plink destination [,] [params]}
  * n:href="destination [,] [params]"
  */
 public function macroLink(MacroNode $node, PhpWriter $writer)
 {
     $node->modifiers = preg_replace('#\\|safeurl\\s*(?=\\||\\z)#i', '', $node->modifiers);
     return $writer->using($node, $this->getCompiler())->write('echo %escape(%modify(' . ($node->name === 'plink' ? '$_presenter' : '$_control') . '->link(%node.word, %node.array?)))');
 }
示例#7
0
 /**
  * Generates code.
  * @return string
  */
 private function compile(MacroNode $node, $def)
 {
     $node->tokenizer->reset();
     $writer = Latte\PhpWriter::using($node, $this->compiler);
     if (is_string($def)) {
         return $writer->write($def);
     } else {
         return call_user_func($def, $node, $writer);
     }
 }
示例#8
0
 public function nodeOpened(MacroNode $node)
 {
     $this->used = true;
     $node->isEmpty = false;
     $node->openingCode = PhpWriter::using($node)->write('<?php if (Venne\\Latte\\Macros\\GlobalCacheMacro::createCache($netteCacheStorage, %var, $presenter->template->_g->caches, ' . var_export(self::$template, true) . ', %node.array?)) { ?>', Random::generate());
 }
示例#9
0
文件: MacroSet.php 项目: nette/latte
 /**
  * Generates code.
  * @return string
  */
 private function compile(MacroNode $node, $def)
 {
     $node->tokenizer->reset();
     $writer = Latte\PhpWriter::using($node);
     return is_string($def) ? $writer->write($def) : call_user_func($def, $node, $writer);
 }
示例#10
0
文件: MacroSet.php 项目: vsek/cms
 public function src(\Latte\MacroNode $node, \Latte\PhpWriter $writer)
 {
     return $writer->using($node, $this->getCompiler())->write('echo %escape(\\App\\MacroSet::getSrc($_presenter, %node.word, %node.array?))');
 }
示例#11
0
 /**
  * @param \Latte\MacroNode $node
  * @param \Latte\PhpWriter $writer
  * @return string
  */
 public function macroIfAllowed(MacroNode $node, PhpWriter $writer)
 {
     $name = Random::generate();
     return $writer->using($node, $this->getCompiler())->write(sprintf('$_allow_%s=FALSE;try{$_presenter->getContext()->getByType("Ark8\\Security\\Validator")->onMacro(%%node.word,%%node.array);$_allow_%s=TRUE;}catch(\\Nette\\Application\\ForbiddenRequestException $e){}if($_allow_%s){', $name, $name, $name));
 }