⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ast.php

📁 博客系统源码 博客系统源码 博客系统源码
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * Twig::AST * ~~~~~~~~~ * * This module implements the abstract syntax tree and compiler. * * :copyright: 2008 by Armin Ronacher. * :license: BSD. */class Twig_Node{    public $lineno;    public function __construct($lineno)    {        $this->lineno = $lineno;    }    public function compile($compiler)    {    }}class Twig_NodeList extends Twig_Node{    public $nodes;    public function __construct($nodes, $lineno)    {        parent::__construct($lineno);        $this->nodes = $nodes;    }    public function compile($compiler)    {        foreach ($this->nodes as $node)            $node->compile($compiler);    }    public static function fromArray($array, $lineno)    {        if (count($array) == 1)            return $array[0];        return new Twig_NodeList($array, $lineno);    }}class Twig_Module extends Twig_Node{    public $body;    public $extends;    public $blocks;    public $filename;    public $id;    public function __construct($body, $extends, $blocks, $filename)    {        parent::__construct(1);        $this->body = $body;        $this->extends = $extends;        $this->blocks = $blocks;        $this->filename = $filename;    }    public function compile($compiler)    {        $compiler->raw("<?php\n");        if (!is_null($this->extends)) {            $compiler->raw('$this->requireTemplate(');            $compiler->repr($this->extends);            $compiler->raw(");\n");        }        $compiler->raw('class __TwigTemplate_' . md5($this->filename));        if (!is_null($this->extends)) {            $parent = md5($this->extends);            $compiler->raw(" extends __TwigTemplate_$parent {\n");        }        else {            $compiler->raw(" {\npublic function render(\$context) {\n");            $this->body->compile($compiler);            $compiler->raw("}\n");        }        foreach ($this->blocks as $node)            $node->compile($compiler);        $compiler->raw("}\n");    }}class Twig_Print extends Twig_Node{    public $expr;    public function __construct($expr, $lineno)    {        parent::__construct($lineno);        $this->expr = $expr;    }    public function compile($compiler)    {        $compiler->addDebugInfo($this);        $compiler->raw('echo ');        $this->expr->compile($compiler);        $compiler->raw(";\n");    }}class Twig_Text extends Twig_Node{    public $data;    public function __construct($data, $lineno)    {        parent::__construct($lineno);        $this->data = $data;    }    public function compile($compiler)    {        $compiler->addDebugInfo($this);        $compiler->raw('echo ');        $compiler->string($this->data);        $compiler->raw(";\n");    }}class Twig_ForLoop extends Twig_Node{    public $is_multitarget;    public $item;    public $seq;    public $body;    public $else;    public function __construct($is_multitarget, $item, $seq, $body, $else,                    $lineno)    {        parent::__construct($lineno);        $this->is_multitarget = $is_multitarget;        $this->item = $item;        $this->seq = $seq;        $this->body = $body;        $this->else = $else;        $this->lineno = $lineno;    }    public function compile($compiler)    {        $compiler->addDebugInfo($this);        $compiler->pushContext();        $compiler->raw('foreach (twig_iterate($context, ');        $this->seq->compile($compiler);        $compiler->raw(") as \$iterator) {\n");        if ($this->is_multitarget) {            $compiler->raw('twig_set_loop_context_multitarget($context, ' .                       '$iterator, array(');            $idx = 0;            foreach ($this->item as $node) {                if ($idx++)                    $compiler->raw(', ');                $compiler->repr($node->name);            }            $compiler->raw("));\n");        }        else {            $compiler->raw('twig_set_loop_context($context, $iterator, ');            $compiler->repr($this->item->name);            $compiler->raw(");\n");        }        $this->body->compile($compiler);        $compiler->raw("}\n");        if (!is_null($this->else)) {            $compiler->raw("if (!\$context['loop']['iterated']) {\n");            $this->else->compile($compiler);            $compiler->raw('}');        }        $compiler->popContext();    }}class Twig_PaginateLoop extends Twig_Node{    public $is_multitarget;    public $item;    public $seq;    public $body;    public $else;    public function __construct($is_multitarget, $item, $per_page, $target,                    $as, $body, $else, $lineno)    {        parent::__construct($lineno);        $this->is_multitarget = $is_multitarget;        $this->item = $item;        $this->per_page = $per_page;        $this->seq = $target;        $this->as = $as;        $this->body = $body;        $this->else = $else;        $this->lineno = $lineno;    }    public function compile($compiler)    {        $compiler->addDebugInfo($this);        $compiler->pushContext();        $compiler->raw('twig_paginate($context,');        $compiler->raw('"'.$this->as->name.'", ');        if (isset($this->seq->node) and isset($this->seq->attr)) {            $compiler->raw('array($context["::parent"]["');            $compiler->raw($this->seq->node->name.'"],');            $compiler->raw('"'.$this->seq->attr->value.'")');        } else            $this->seq->compile($compiler);        $compiler->raw(', ');        $this->per_page->compile($compiler);        $compiler->raw(");\n");        $compiler->raw('foreach (twig_iterate($context,');        $compiler->raw(' $context["::parent"]["'.$this->as->name);        $compiler->raw("\"]->paginated) as \$iterator) {\n");        if ($this->is_multitarget) {            $compiler->raw('twig_set_loop_context_multitarget($context, ' .                       '$iterator, array(');            $idx = 0;            foreach ($this->item as $node) {                if ($idx++)                    $compiler->raw(', ');                $compiler->repr($node->name);            }            $compiler->raw("));\n");        }        else {            $compiler->raw('twig_set_loop_context($context, $iterator, ');            $compiler->repr($this->item->name);            $compiler->raw(");\n");        }        $this->body->compile($compiler);        $compiler->raw("}\n");        if (!is_null($this->else)) {            $compiler->raw("if (!\$context['loop']['iterated']) {\n");            $this->else->compile($compiler);            $compiler->raw('}');        }        $compiler->popContext();    }}class Twig_IfCondition extends Twig_Node{    public $tests;    public $else;    public function __construct($tests, $else, $lineno)    {        parent::__construct($lineno);        $this->tests = $tests;        $this->else = $else;    }    public function compile($compiler)    {        $compiler->addDebugInfo($this);        $idx = 0;        foreach ($this->tests as $test) {            $compiler->raw(($idx++ ? "}\nelse" : '') . 'if (');            $test[0]->compile($compiler);            $compiler->raw(") {\n");            $test[1]->compile($compiler);        }        if (!is_null($this->else)) {            $compiler->raw("} else {\n");            $this->else->compile($compiler);        }        $compiler->raw("}\n");    }}class Twig_Block extends Twig_Node{    public $name;    public $body;    public $parent;    public function __construct($name, $body, $lineno, $parent=NULL)    {        parent::__construct($lineno);        $this->name = $name;        $this->body = $body;        $this->parent = $parent;    }    public function replace($other)    {        $this->body = $other->body;    }    public function compile($compiler)    {        $compiler->addDebugInfo($this);        $compiler->format('public function block_%s($context) {' . "\n",                  $this->name);        if (!is_null($this->parent))            $compiler->raw('$context[\'::superblock\'] = array($this, ' .                       "'parent::block_$this->name');\n");        $this->body->compile($compiler);        $compiler->format("}\n\n");    }}class Twig_BlockReference extends Twig_Node{    public $name;    public function __construct($name, $lineno)    {        parent::__construct($lineno);        $this->name = $name;    }    public function compile($compiler)    {        $compiler->addDebugInfo($this);        $compiler->format('$this->block_%s($context);' . "\n", $this->name);    }}class Twig_Super extends Twig_Node{    public $block_name;    public function __construct($block_name, $lineno)    {        parent::__construct($lineno);        $this->block_name = $block_name;    }    public function compile($compiler)    {        $compiler->addDebugInfo($this);        $compiler->raw('parent::block_' . $this->block_name . '($context);' . "\n");    }}class Twig_Include extends Twig_Node{    public $expr;    public function __construct($expr, $lineno)    {        parent::__construct($lineno);        $this->expr = $expr;    }    public function compile($compiler)    {        $compiler->addDebugInfo($this);        $compiler->raw('twig_get_current_template()->loader->getTemplate(');        $this->expr->compile($compiler);        $compiler->raw(')->display($context);' . "\n");    }}class Twig_URL extends Twig_Node{    public $expr;    public function __construct($expr, $lineno)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -