Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
includenode
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 compile
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\template\twig\node;
15
16class includenode extends \Twig\Node\IncludeNode
17{
18    /**
19    * Compiles the node to PHP.
20    *
21    * @param \Twig\Compiler A Twig\Compiler instance
22    */
23    public function compile(\Twig\Compiler $compiler) : void
24    {
25        $compiler->addDebugInfo($this);
26
27        $compiler
28            ->write("\$location = ")
29            ->subcompile($this->getNode('expr'))
30            ->raw(";\n")
31            ->write("\$namespace = false;\n")
32            ->write("if (strpos(\$location, '@') === 0) {\n")
33            ->indent()
34                ->write("\$namespace = substr(\$location, 1, strpos(\$location, '/') - 1);\n")
35                ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")
36
37                // We set the namespace lookup order to be this namespace first, then the main path
38                ->write("\$this->env->setNamespaceLookUpOrder(array(\$namespace, '__main__'));\n")
39            ->outdent()
40            ->write("}\n")
41        ;
42
43        parent::compile($compiler);
44
45        $compiler
46            ->write("if (\$namespace) {\n")
47            ->indent()
48                ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n")
49            ->outdent()
50            ->write("}\n")
51        ;
52    }
53}