mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-18 17:28:56 +00:00
This is done so that when event template files are included, if they include files themselves, that namespace is checked first, then __main__ is checked to include the correct template file. Also, when template files are included from a particular namespace, this is done so that the files from that namespace are included first, then the main namespace is checked. We may want to change this behavior in the future to allow choosing which locations have priority, but for now, this is what I am doing to make sure the behavior is simple and always the same. PHPBB3-11598
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* @package phpBB3
|
|
* @copyright (c) 2013 phpBB Group
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
*
|
|
*/
|
|
|
|
class phpbb_template_twig_node_include extends Twig_Node_Include
|
|
{
|
|
/**
|
|
* Compiles the node to PHP.
|
|
*
|
|
* @param Twig_Compiler A Twig_Compiler instance
|
|
*/
|
|
public function compile(Twig_Compiler $compiler)
|
|
{
|
|
$compiler->addDebugInfo($this);
|
|
|
|
$location = $this->getNode('expr')->getAttribute('value');
|
|
$namespace = false;
|
|
|
|
if (strpos($location, '@') === 0)
|
|
{
|
|
$namespace = substr($location, 1, strpos($location, '/') - 1);
|
|
|
|
$compiler
|
|
->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")
|
|
|
|
// We set the namespace lookup order to be this namespace first, then the main path
|
|
->write("\$this->env->setNamespaceLookUpOrder(array('" . $namespace . "', '__main__'));\n")
|
|
;
|
|
}
|
|
|
|
parent::compile($compiler);
|
|
|
|
if ($namespace)
|
|
{
|
|
$compiler
|
|
->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n")
|
|
;
|
|
}
|
|
}
|
|
}
|