Latte\PhpWriter::formatArgs PHP Method

formatArgs() public method

Formats macro arguments to PHP code. (It advances tokenizer to the end as a side effect.)
public formatArgs ( MacroTokens $tokens = NULL ) : string
$tokens MacroTokens
return string
    public function formatArgs(MacroTokens $tokens = NULL)
    {
        $tokens = $this->preprocess($tokens);
        $tokens = $this->quotingPass($tokens);
        return $tokens->joinAll();
    }

Usage Example

 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++; } ?>';
     }
 }
All Usage Examples Of Latte\PhpWriter::formatArgs