本文整理汇总了PHP中Latte\PhpWriter::using方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpWriter::using方法的具体用法?PHP PhpWriter::using怎么用?PHP PhpWriter::using使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Latte\PhpWriter
的用法示例。
在下文中一共展示了PhpWriter::using方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: nodeOpened
/**
* 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: nodeOpened
/**
* 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: nodeOpened
/**
* 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: nodeOpened
/**
* 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()
);
}
示例5: compile
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: macroLink
/**
* {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: compile
/**
* 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: nodeOpened
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: compile
/**
* 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: src
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: macroIfAllowed
/**
* @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));
}