Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
For.php
001 <?php
002
003 /*
004 * This file is part of Twig.
005 *
006 * (c) 2009 Fabien Potencier
007 * (c) 2009 Armin Ronacher
008 *
009 * For the full copyright and license information, please view the LICENSE
010 * file that was distributed with this source code.
011 */
012
013 /**
014 * Represents a for node.
015 *
016 * @author Fabien Potencier <fabien@symfony.com>
017 */
018 class Twig_Node_For extends Twig_Node
019 {
020 protected $loop;
021
022 public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null)
023 {
024 $body = new Twig_Node(array($body, $this->loop = new Twig_Node_ForLoop($lineno, $tag)));
025
026 if (null !== $ifexpr) {
027 $body = new Twig_Node_If(new Twig_Node(array($ifexpr, $body)), null, $lineno, $tag);
028 }
029
030 parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else), array('with_loop' => true, 'ifexpr' => null !== $ifexpr), $lineno, $tag);
031 }
032
033 public function compile(Twig_Compiler $compiler)
034 {
035 $compiler
036 ->addDebugInfo($this)
037 ->write("\$context['_parent'] = \$context;\n")
038 ->write("\$context['_seq'] = twig_ensure_traversable(")
039 ->subcompile($this->getNode('seq'))
040 ->raw(");\n")
041 ;
042
043 if (null !== $this->getNode('else')) {
044 $compiler->write("\$context['_iterated'] = false;\n");
045 }
046
047 if ($this->getAttribute('with_loop')) {
048 $compiler
049 ->write("\$context['loop'] = array(\n")
050 ->write(" 'parent' => \$context['_parent'],\n")
051 ->write(" 'index0' => 0,\n")
052 ->write(" 'index' => 1,\n")
053 ->write(" 'first' => true,\n")
054 ->write(");\n")
055 ;
056
057 if (!$this->getAttribute('ifexpr')) {
058 $compiler
059 ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) {\n")
060 ->indent()
061 ->write("\$length = count(\$context['_seq']);\n")
062 ->write("\$context['loop']['revindex0'] = \$length - 1;\n")
063 ->write("\$context['loop']['revindex'] = \$length;\n")
064 ->write("\$context['loop']['length'] = \$length;\n")
065 ->write("\$context['loop']['last'] = 1 === \$length;\n")
066 ->outdent()
067 ->write("}\n")
068 ;
069 }
070 }
071
072 $this->loop->setAttribute('else', null !== $this->getNode('else'));
073 $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop'));
074 $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr'));
075
076 $compiler
077 ->write("foreach (\$context['_seq'] as ")
078 ->subcompile($this->getNode('key_target'))
079 ->raw(' => ')
080 ->subcompile($this->getNode('value_target'))
081 ->raw(") {\n")
082 ->indent()
083 ->subcompile($this->getNode('body'))
084 ->outdent()
085 ->write("}\n")
086 ;
087
088 if (null !== $this->getNode('else')) {
089 $compiler
090 ->write("if (!\$context['_iterated']) {\n")
091 ->indent()
092 ->subcompile($this->getNode('else'))
093 ->outdent()
094 ->write("}\n")
095 ;
096 }
097
098 $compiler->write("\$_parent = \$context['_parent'];\n");
099
100 // remove some "private" loop variables (needed for nested loops)
101 $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n");
102
103 // keep the values set in the inner context for variables defined in the outer context
104 $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n");
105 }
106 }
107