Security update to Drupal 8.4.6 with PHP held back to 7.0.27 to match the stoneboat...
[yaffs-website] / vendor / twig / twig / lib / Twig / TokenParser / Use.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * Imports blocks defined in another template into the current template.
14  *
15  * <pre>
16  * {% extends "base.html" %}
17  *
18  * {% use "blocks.html" %}
19  *
20  * {% block title %}{% endblock %}
21  * {% block content %}{% endblock %}
22  * </pre>
23  *
24  * @see http://www.twig-project.org/doc/templates.html#horizontal-reuse for details.
25  *
26  * @final
27  */
28 class Twig_TokenParser_Use extends Twig_TokenParser
29 {
30     public function parse(Twig_Token $token)
31     {
32         $template = $this->parser->getExpressionParser()->parseExpression();
33         $stream = $this->parser->getStream();
34
35         if (!$template instanceof Twig_Node_Expression_Constant) {
36             throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
37         }
38
39         $targets = array();
40         if ($stream->nextIf('with')) {
41             do {
42                 $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
43
44                 $alias = $name;
45                 if ($stream->nextIf('as')) {
46                     $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
47                 }
48
49                 $targets[$name] = new Twig_Node_Expression_Constant($alias, -1);
50
51                 if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
52                     break;
53                 }
54             } while (true);
55         }
56
57         $stream->expect(Twig_Token::BLOCK_END_TYPE);
58
59         $this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets))));
60
61         return new Twig_Node();
62     }
63
64     public function getTag()
65     {
66         return 'use';
67     }
68 }
69
70 class_alias('Twig_TokenParser_Use', 'Twig\TokenParser\UseTokenParser', false);