本文整理汇总了PHP中Latte\PhpWriter::formatArgs方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpWriter::formatArgs方法的具体用法?PHP PhpWriter::formatArgs怎么用?PHP PhpWriter::formatArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Latte\PhpWriter
的用法示例。
在下文中一共展示了PhpWriter::formatArgs方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: macroEachEnd
public function macroEachEnd(MacroNode $node, PhpWriter $writer)
{
if ($node->modifiers && $node->modifiers !== '|noiterator') {
trigger_error('Only modifier |noiterator is allowed here.', E_USER_WARNING);
}
$args = $writer->formatArgs();
if (substr($args, 0, 3) === 'as ') {
$parts = [self::$defaultEachArrayName, substr($args, 3)];
} elseif (empty($args)) {
$parts = [self::$defaultEachArrayName];
} else {
$parts = Strings::split($args, '#\\s+as\\s+#i');
}
if (count($parts) === 1) {
$parts[] = '$' . self::$defaultEachVarName;
}
$array = $parts[0];
$parts[0] = '(($_l_q instanceof WP_Query)?$_l_q->get_posts():(array)$_l_q)';
$args = implode(' as ', $parts);
if ($node->modifiers !== '|noiterator' && preg_match('#\\W(\\$iterator|include|require|get_defined_vars)\\W#', $this->getCompiler()->expandTokens($node->content))) {
$node->openingCode = '<?php $iterations = 0; $_l_q=' . $array . '; foreach ($iterator = $_l->its[] = new Latte\\Runtime\\CachingIterator(' . preg_replace('#(.*)\\s+as\\s+#i', '$1) as ', $args, 1) . ') { ?>';
$node->closingCode = '<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>';
} else {
$node->openingCode = '<?php $iterations = 0; $_l_q=' . $array . '; foreach (' . $args . ') { ?>';
$node->closingCode = '<?php $iterations++; } ?>';
}
}
示例2: macroImgLink
/**
* {imgLink $img [type]}
* @param Latte\MacroNode $node
* @param Latte\PhpWriter $writer
* @return string
*/
public function macroImgLink(Latte\MacroNode $node, Latte\PhpWriter $writer)
{
list($img, $type) = $this->getImageFromNode($node);
return '
$args = [' . ($type ? "'type' => '{$type}', " : NULL) . "'storage' => " . '$imageStorage' . ($node->args ? ', ' . $writer->formatArgs() : NULL) . '];
echo ' . get_class($this) . '::imgLink(' . $img . ', $args);
';
}
示例3: macroControl
/**
* {control name[:method] [params]}
*/
public function macroControl(MacroNode $node, PhpWriter $writer)
{
$words = $node->tokenizer->fetchWords();
if (!$words) {
throw new CompileException('Missing control name in {control}');
}
$name = $writer->formatWord($words[0]);
$method = isset($words[1]) ? ucfirst($words[1]) : '';
$method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}";
$param = $writer->formatArgs();
if (Strings::contains($node->args, '=>')) {
$param = "[{$param}]";
}
return ($name[0] === '$' ? "if (is_object({$name})) \$_l->tmp = {$name}; else " : '') . '$_l->tmp = $_control->getComponent(' . $name . '); ' . 'if ($_l->tmp instanceof Nette\\Application\\UI\\IRenderable) $_l->tmp->redrawControl(NULL, FALSE); ' . ($node->modifiers === '' ? "\$_l->tmp->{$method}({$param})" : $writer->write("ob_start(); \$_l->tmp->{$method}({$param}); echo %modify(ob_get_clean())"));
}
示例4: macroDump
/**
* {dump ...}
*/
public function macroDump(MacroNode $node, PhpWriter $writer)
{
if ($node->modifiers) {
trigger_error("Modifiers are not allowed in {{$node->name}}", E_USER_WARNING);
}
$args = $writer->formatArgs();
return $writer->write('Tracy\\Debugger::barDump(' . ($args ? "({$args})" : 'get_defined_vars()') . ', %var)', $args ?: 'variables');
}
示例5: macroDump
/**
* {dump ...}
*/
public function macroDump(MacroNode $node, PhpWriter $writer)
{
if ($node->modifiers) {
throw new CompileException("Modifiers are not allowed in {{$node->name}}");
}
$args = $writer->formatArgs();
return $writer->write('Tracy\\Debugger::barDump(' . ($args ? "({$args})" : 'get_defined_vars()') . ', %var)', $args ?: 'variables');
}
示例6: macroIfset
/**
* {ifset #block}
* {elseifset #block}
*/
public function macroIfset(MacroNode $node, PhpWriter $writer)
{
if ($node->modifiers) {
trigger_error("Modifiers are not allowed in {{$node->name}}", E_USER_WARNING);
}
if (!preg_match('~#|[\\w-]+\\z~A', $node->args)) {
return FALSE;
}
$list = array();
while (($name = $node->tokenizer->fetchWord()) !== FALSE) {
$list[] = preg_match('~#|[\\w-]+\\z~A', $name) ? '$_b->blocks["' . ltrim($name, '#') . '"]' : $writer->formatArgs(new Latte\MacroTokens($name));
}
return ($node->name === 'elseifset' ? '} else' : '') . 'if (isset(' . implode(', ', $list) . ')) {';
}
示例7: macroDump
/**
* {dump ...}
*/
public function macroDump(MacroNode $node, PhpWriter $writer)
{
$args = $writer->formatArgs();
return 'Tracy\\Debugger::barDump(' . ($node->args ? $writer->write("array(%var => {$args})", $args) : 'get_defined_vars()') . ', "Template " . str_replace(dirname(dirname($template->getName())), "\\xE2\\x80\\xA6", $template->getName()))';
}
示例8: createIterator
/**
* @from https://github.com/nette/latte/blob/master/src/Latte/Macros/CoreMacros.php#L253-L263
*
* @param \Latte\MacroNode $node
* @param \Latte\PhpWriter $writer
* @param string $iterate
*/
private function createIterator(MacroNode $node, PhpWriter $writer, $iterate)
{
if ($node->modifiers !== '|noiterator' && preg_match('#\\W(\\$iterator|include|require|get_defined_vars)\\W#', $this->getCompiler()->expandTokens($node->content))) {
$node->openingCode = '<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Latte\\Runtime\\CachingIterator(' . $iterate . ') as ' . $writer->formatArgs() . ') { ?>';
$node->closingCode = '<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>';
} else {
$node->openingCode = '<?php $iterations = 0; foreach (' . $iterate . ' as ' . $writer->formatArgs() . ') { ?>';
$node->closingCode = '<?php $iterations++; } ?>';
}
}
示例9: macroIfset
/**
* {ifset #block}
* {elseifset #block}
*/
public function macroIfset(MacroNode $node, PhpWriter $writer)
{
if ($node->modifiers) {
throw new CompileException('Modifiers are not allowed here.');
}
if (!preg_match('~#|[\\w-]+\\z~A', $node->args)) {
return FALSE;
}
$list = [];
while (($name = $node->tokenizer->fetchWord()) !== FALSE) {
$list[] = preg_match('~#|[\\w-]+\\z~A', $name) ? '$_b->blocks["' . ltrim($name, '#') . '"]' : $writer->formatArgs(new Latte\MacroTokens($name));
}
return ($node->name === 'elseifset' ? '} else' : '') . 'if (isset(' . implode(', ', $list) . ')) {';
}
示例10: macroDump
/**
* {dump ...}
*/
public function macroDump(MacroNode $node, PhpWriter $writer)
{
$args = $writer->formatArgs();
return $writer->write('Tracy\\Debugger::barDump(' . ($args ? "({$args})" : 'get_defined_vars()') . ', %var)', $args ?: 'variables');
}