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 * Loops over each item of a sequence.
015 *
016 * <pre>
017 * <ul>
018 * {% for user in users %}
019 * <li>{{ user.username|e }}</li>
020 * {% endfor %}
021 * </ul>
022 * </pre>
023 */
024 class Twig_TokenParser_For extends Twig_TokenParser
025 {
026 public function parse(Twig_Token $token)
027 {
028 $lineno = $token->getLine();
029 $stream = $this->parser->getStream();
030 $targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
031 $stream->expect(Twig_Token::OPERATOR_TYPE, 'in');
032 $seq = $this->parser->getExpressionParser()->parseExpression();
033
034 $ifexpr = null;
035 if ($stream->nextIf(Twig_Token::NAME_TYPE, 'if')) {
036 $ifexpr = $this->parser->getExpressionParser()->parseExpression();
037 }
038
039 $stream->expect(Twig_Token::BLOCK_END_TYPE);
040 $body = $this->parser->subparse(array($this, 'decideForFork'));
041 if ($stream->next()->getValue() == 'else') {
042 $stream->expect(Twig_Token::BLOCK_END_TYPE);
043 $else = $this->parser->subparse(array($this, 'decideForEnd'), true);
044 } else {
045 $else = null;
046 }
047 $stream->expect(Twig_Token::BLOCK_END_TYPE);
048
049 if (count($targets) > 1) {
050 $keyTarget = $targets->getNode(0);
051 $keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getLine());
052 $valueTarget = $targets->getNode(1);
053 $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine());
054 } else {
055 $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno);
056 $valueTarget = $targets->getNode(0);
057 $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine());
058 }
059
060 if ($ifexpr) {
061 $this->checkLoopUsageCondition($stream, $ifexpr);
062 $this->checkLoopUsageBody($stream, $body);
063 }
064
065 return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag());
066 }
067
068 public function decideForFork(Twig_Token $token)
069 {
070 return $token->test(array('else', 'endfor'));
071 }
072
073 public function decideForEnd(Twig_Token $token)
074 {
075 return $token->test('endfor');
076 }
077
078 // the loop variable cannot be used in the condition
079 protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node)
080 {
081 if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
082 throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getLine(), $stream->getFilename());
083 }
084
085 foreach ($node as $n) {
086 if (!$n) {
087 continue;
088 }
089
090 $this->checkLoopUsageCondition($stream, $n);
091 }
092 }
093
094 // check usage of non-defined loop-items
095 // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include)
096 protected function checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node)
097 {
098 if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
099 $attribute = $node->getNode('attribute');
100 if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), array('length', 'revindex0', 'revindex', 'last'))) {
101 throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getLine(), $stream->getFilename());
102 }
103 }
104
105 // should check for parent.loop.XXX usage
106 if ($node instanceof Twig_Node_For) {
107 return;
108 }
109
110 foreach ($node as $n) {
111 if (!$n) {
112 continue;
113 }
114
115 $this->checkLoopUsageBody($stream, $n);
116 }
117 }
118
119 public function getTag()
120 {
121 return 'for';
122 }
123 }
124