Latte\PhpWriter::write PHP 메소드

write() 공개 메소드

Expands %node.word, %node.array, %node.args, %escape(), %modify(), %var, %raw, %word in code.
public write ( $mask ) : string
리턴 string
    public function write($mask)
    {
        $mask = preg_replace('#%(node|\\d+)\\.#', '%$1_', $mask);
        $mask = preg_replace_callback('#%escape(\\(([^()]*+|(?1))+\\))#', function ($m) {
            return $this->escapePass(new MacroTokens(substr($m[1], 1, -1)))->joinAll();
        }, $mask);
        $mask = preg_replace_callback('#%modify(Content)?(\\(([^()]*+|(?2))+\\))#', function ($m) {
            return $this->formatModifiers(substr($m[2], 1, -1), (bool) $m[1]);
        }, $mask);
        $args = func_get_args();
        $pos = $this->tokens->position;
        $word = strpos($mask, '%node_word') === FALSE ? NULL : $this->tokens->fetchWord();
        $code = preg_replace_callback('#([,+]\\s*)?%(node_|\\d+_|)(word|var|raw|array|args)(\\?)?(\\s*\\+\\s*)?()#', function ($m) use($word, &$args) {
            list(, $l, $source, $format, $cond, $r) = $m;
            switch ($source) {
                case 'node_':
                    $arg = $word;
                    break;
                case '':
                    $arg = next($args);
                    break;
                default:
                    $arg = $args[(int) $source + 1];
                    break;
            }
            switch ($format) {
                case 'word':
                    $code = $this->formatWord($arg);
                    break;
                case 'args':
                    $code = $this->formatArgs();
                    break;
                case 'array':
                    $code = $this->formatArray();
                    $code = $cond && $code === '[]' ? '' : $code;
                    break;
                case 'var':
                    $code = var_export($arg, TRUE);
                    break;
                case 'raw':
                    $code = (string) $arg;
                    break;
            }
            if ($cond && $code === '') {
                return $r ? $l : $r;
            } else {
                return $l . $code . $r;
            }
        }, $mask);
        $this->tokens->position = $pos;
        return $code;
    }

Usage Example

예제 #1
0
 public function macroSecured(Latte\MacroNode $node, Latte\PhpWriter $writer)
 {
     if ($node->prefix === $node::PREFIX_TAG) {
         return $writer->write($node->htmlNode->closing ? 'if(array_pop($_l->secured)){' : 'if($_l->secured[] = $acl->isUserAllowedTo(%node.args)) {');
     }
     return $writer->write('if ($acl->isUserAllowedTo(%node.args)) {');
 }
All Usage Examples Of Latte\PhpWriter::write