mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/15508] Remove call to getEnvironment() from parser
PHPBB3-15508
This commit is contained in:
parent
e75077fc5b
commit
23b13c239b
17 changed files with 78 additions and 39 deletions
|
@ -37,6 +37,7 @@ services:
|
||||||
class: phpbb\template\twig\extension
|
class: phpbb\template\twig\extension
|
||||||
arguments:
|
arguments:
|
||||||
- '@template_context'
|
- '@template_context'
|
||||||
|
- '@template.twig.environment'
|
||||||
- '@language'
|
- '@language'
|
||||||
tags:
|
tags:
|
||||||
- { name: twig.extension }
|
- { name: twig.extension }
|
||||||
|
|
|
@ -18,6 +18,9 @@ class extension extends \Twig_Extension
|
||||||
/** @var \phpbb\template\context */
|
/** @var \phpbb\template\context */
|
||||||
protected $context;
|
protected $context;
|
||||||
|
|
||||||
|
/** @var \phpbb\template\twig\environment */
|
||||||
|
protected $environment;
|
||||||
|
|
||||||
/** @var \phpbb\language\language */
|
/** @var \phpbb\language\language */
|
||||||
protected $language;
|
protected $language;
|
||||||
|
|
||||||
|
@ -25,12 +28,14 @@ class extension extends \Twig_Extension
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param \phpbb\template\context $context
|
* @param \phpbb\template\context $context
|
||||||
|
* @param \phpbb\template\twig\environment $environment
|
||||||
* @param \phpbb\language\language $language
|
* @param \phpbb\language\language $language
|
||||||
* @return \phpbb\template\twig\extension
|
* @return \phpbb\template\twig\extension
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\template\context $context, $language)
|
public function __construct(\phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language)
|
||||||
{
|
{
|
||||||
$this->context = $context;
|
$this->context = $context;
|
||||||
|
$this->environment = $environment;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +61,9 @@ class extension extends \Twig_Extension
|
||||||
new \phpbb\template\twig\tokenparser\includeparser,
|
new \phpbb\template\twig\tokenparser\includeparser,
|
||||||
new \phpbb\template\twig\tokenparser\includejs,
|
new \phpbb\template\twig\tokenparser\includejs,
|
||||||
new \phpbb\template\twig\tokenparser\includecss,
|
new \phpbb\template\twig\tokenparser\includecss,
|
||||||
new \phpbb\template\twig\tokenparser\event,
|
new \phpbb\template\twig\tokenparser\event($this->environment),
|
||||||
new \phpbb\template\twig\tokenparser\includephp,
|
new \phpbb\template\twig\tokenparser\includephp($this->environment),
|
||||||
new \phpbb\template\twig\tokenparser\php,
|
new \phpbb\template\twig\tokenparser\php($this->environment),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,15 +15,11 @@ namespace phpbb\template\twig\node;
|
||||||
|
|
||||||
abstract class includeasset extends \Twig_Node
|
abstract class includeasset extends \Twig_Node
|
||||||
{
|
{
|
||||||
/** @var \Twig_Environment */
|
public function __construct(\Twig_Node_Expression $expr, $lineno, $tag = null)
|
||||||
protected $environment;
|
|
||||||
|
|
||||||
public function __construct(\Twig_Node_Expression $expr, \phpbb\template\twig\environment $environment, $lineno, $tag = null)
|
|
||||||
{
|
{
|
||||||
$this->environment = $environment;
|
|
||||||
|
|
||||||
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
|
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles the node to PHP.
|
* Compiles the node to PHP.
|
||||||
*
|
*
|
||||||
|
@ -33,27 +29,25 @@ abstract class includeasset extends \Twig_Node
|
||||||
{
|
{
|
||||||
$compiler->addDebugInfo($this);
|
$compiler->addDebugInfo($this);
|
||||||
|
|
||||||
$config = $this->environment->get_phpbb_config();
|
|
||||||
|
|
||||||
$compiler
|
$compiler
|
||||||
->write("\$asset_file = ")
|
->write("\$asset_file = ")
|
||||||
->subcompile($this->getNode('expr'))
|
->subcompile($this->getNode('expr'))
|
||||||
->raw(";\n")
|
->raw(";\n")
|
||||||
->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper(), \$this->getEnvironment()->get_filesystem());\n")
|
->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->env->get_path_helper(), \$this->env->get_filesystem());\n")
|
||||||
->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n")
|
->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$asset_path = \$asset->get_path();")
|
->write("\$asset_path = \$asset->get_path();")
|
||||||
->write("\$local_file = \$this->getEnvironment()->get_phpbb_root_path() . \$asset_path;\n")
|
->write("\$local_file = \$this->env->get_phpbb_root_path() . \$asset_path;\n")
|
||||||
->write("if (!file_exists(\$local_file)) {\n")
|
->write("if (!file_exists(\$local_file)) {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$local_file = \$this->getEnvironment()->findTemplate(\$asset_path);\n")
|
->write("\$local_file = \$this->env->findTemplate(\$asset_path);\n")
|
||||||
->write("\$asset->set_path(\$local_file, true);\n")
|
->write("\$asset->set_path(\$local_file, true);\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("}\n")
|
->write("}\n")
|
||||||
->write("\$asset->add_assets_version('{$config['assets_version']}');\n")
|
->write("\$asset->add_assets_version(\$this->env->get_phpbb_config()['assets_version']);\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("}\n")
|
->write("}\n")
|
||||||
->write("\$this->getEnvironment()->get_assets_bag()->add_{$this->get_setters_name()}(\$asset);")
|
->write("\$this->env->get_assets_bag()->add_{$this->get_setters_name()}(\$asset);")
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,15 +63,15 @@ class includephp extends \Twig_Node
|
||||||
// Absolute path specified
|
// Absolute path specified
|
||||||
->write("require(\$location);\n")
|
->write("require(\$location);\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("} else if (file_exists(\$this->getEnvironment()->get_phpbb_root_path() . \$location)) {\n")
|
->write("} else if (file_exists(\$this->env->get_phpbb_root_path() . \$location)) {\n")
|
||||||
->indent()
|
->indent()
|
||||||
// PHP file relative to phpbb_root_path
|
// PHP file relative to phpbb_root_path
|
||||||
->write("require(\$this->getEnvironment()->get_phpbb_root_path() . \$location);\n")
|
->write("require(\$this->env->get_phpbb_root_path() . \$location);\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("} else {\n")
|
->write("} else {\n")
|
||||||
->indent()
|
->indent()
|
||||||
// Local path (behaves like INCLUDE)
|
// Local path (behaves like INCLUDE)
|
||||||
->write("require(\$this->getEnvironment()->getLoader()->getCacheKey(\$location));\n")
|
->write("require(\$this->env->getLoader()->getCacheKey(\$location));\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("}\n")
|
->write("}\n")
|
||||||
;
|
;
|
||||||
|
|
|
@ -15,6 +15,19 @@ namespace phpbb\template\twig\tokenparser;
|
||||||
|
|
||||||
class event extends \Twig_TokenParser
|
class event extends \Twig_TokenParser
|
||||||
{
|
{
|
||||||
|
/** @var \phpbb\template\twig\environment */
|
||||||
|
protected $environment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param \phpbb\template\twig\environment $environment
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\template\twig\environment $environment)
|
||||||
|
{
|
||||||
|
$this->environment = $environment;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a token and returns a node.
|
* Parses a token and returns a node.
|
||||||
*
|
*
|
||||||
|
@ -29,7 +42,7 @@ class event extends \Twig_TokenParser
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
return new \phpbb\template\twig\node\event($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
|
return new \phpbb\template\twig\node\event($expr, $this->environment, $token->getLine(), $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,7 +29,7 @@ class includecss extends \Twig_TokenParser
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
return new \phpbb\template\twig\node\includecss($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
|
return new \phpbb\template\twig\node\includecss($expr, $token->getLine(), $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,7 +29,7 @@ class includejs extends \Twig_TokenParser
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
return new \phpbb\template\twig\node\includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
|
return new \phpbb\template\twig\node\includejs($expr, $token->getLine(), $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,6 +16,19 @@ namespace phpbb\template\twig\tokenparser;
|
||||||
|
|
||||||
class includephp extends \Twig_TokenParser
|
class includephp extends \Twig_TokenParser
|
||||||
{
|
{
|
||||||
|
/** @var \phpbb\template\twig\environment */
|
||||||
|
protected $environment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param \phpbb\template\twig\environment $environment
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\template\twig\environment $environment)
|
||||||
|
{
|
||||||
|
$this->environment = $environment;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a token and returns a node.
|
* Parses a token and returns a node.
|
||||||
*
|
*
|
||||||
|
@ -40,7 +53,7 @@ class includephp extends \Twig_TokenParser
|
||||||
|
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
return new \phpbb\template\twig\node\includephp($expr, $this->parser->getEnvironment(), $token->getLine(), $ignoreMissing, $this->getTag());
|
return new \phpbb\template\twig\node\includephp($expr, $this->environment, $token->getLine(), $ignoreMissing, $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,6 +15,19 @@ namespace phpbb\template\twig\tokenparser;
|
||||||
|
|
||||||
class php extends \Twig_TokenParser
|
class php extends \Twig_TokenParser
|
||||||
{
|
{
|
||||||
|
/** @var \phpbb\template\twig\environment */
|
||||||
|
protected $environment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param \phpbb\template\twig\environment $environment
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\template\twig\environment $environment)
|
||||||
|
{
|
||||||
|
$this->environment = $environment;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a token and returns a node.
|
* Parses a token and returns a node.
|
||||||
*
|
*
|
||||||
|
@ -32,7 +45,7 @@ class php extends \Twig_TokenParser
|
||||||
|
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
return new \phpbb\template\twig\node\php($body, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
|
return new \phpbb\template\twig\node\php($body, $this->environment, $token->getLine(), $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function decideEnd(\Twig_Token $token)
|
public function decideEnd(\Twig_Token $token)
|
||||||
|
|
|
@ -121,7 +121,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
|
||||||
'autoescape' => false,
|
'autoescape' => false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
|
$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
|
||||||
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
||||||
|
|
||||||
$this->extension_manager = new phpbb_mock_extension_manager(
|
$this->extension_manager = new phpbb_mock_extension_manager(
|
||||||
|
|
|
@ -66,13 +66,6 @@ class phpbb_email_parsing_test extends phpbb_test_case
|
||||||
$phpbb_container->set('ext.manager', $extension_manager);
|
$phpbb_container->set('ext.manager', $extension_manager);
|
||||||
|
|
||||||
$context = new \phpbb\template\context();
|
$context = new \phpbb\template\context();
|
||||||
$twig_extension = new \phpbb\template\twig\extension($context, $lang);
|
|
||||||
$phpbb_container->set('template.twig.extensions.phpbb', $twig_extension);
|
|
||||||
|
|
||||||
$twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container);
|
|
||||||
$twig_extensions_collection->add('template.twig.extensions.phpbb');
|
|
||||||
$phpbb_container->set('template.twig.extensions.collection', $twig_extensions_collection);
|
|
||||||
|
|
||||||
$twig = new \phpbb\template\twig\environment(
|
$twig = new \phpbb\template\twig\environment(
|
||||||
$config,
|
$config,
|
||||||
$filesystem,
|
$filesystem,
|
||||||
|
@ -88,6 +81,13 @@ class phpbb_email_parsing_test extends phpbb_test_case
|
||||||
'autoescape' => false,
|
'autoescape' => false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$twig_extension = new \phpbb\template\twig\extension($context, $twig, $lang);
|
||||||
|
$phpbb_container->set('template.twig.extensions.phpbb', $twig_extension);
|
||||||
|
|
||||||
|
$twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container);
|
||||||
|
$twig_extensions_collection->add('template.twig.extensions.phpbb');
|
||||||
|
$phpbb_container->set('template.twig.extensions.collection', $twig_extensions_collection);
|
||||||
|
|
||||||
$twig->addExtension($twig_extension);
|
$twig->addExtension($twig_extension);
|
||||||
$phpbb_container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
|
$phpbb_container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
|
||||||
$lang = new \phpbb\language\language($lang_loader);
|
$lang = new \phpbb\language\language($lang_loader);
|
||||||
$this->user = new \phpbb\user($lang, '\phpbb\datetime');
|
$this->user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||||
|
|
||||||
$this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
|
$this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
|
||||||
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
|
||||||
'autoescape' => false,
|
'autoescape' => false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager);
|
$this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)), $this->extension_manager);
|
||||||
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
||||||
|
|
||||||
$this->template_path = $this->test_path . '/templates';
|
$this->template_path = $this->test_path . '/templates';
|
||||||
|
|
|
@ -168,7 +168,7 @@ Zeta test event in all',
|
||||||
'autoescape' => false,
|
'autoescape' => false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager);
|
$this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)), $this->extension_manager);
|
||||||
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
||||||
|
|
||||||
$this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));
|
$this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));
|
||||||
|
|
|
@ -67,7 +67,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
|
||||||
$twig,
|
$twig,
|
||||||
$cache_path,
|
$cache_path,
|
||||||
$this->user,
|
$this->user,
|
||||||
array(new \phpbb\template\twig\extension($context, $this->user)),
|
array(new \phpbb\template\twig\extension($context, $twig, $this->user)),
|
||||||
new phpbb_mock_extension_manager(
|
new phpbb_mock_extension_manager(
|
||||||
dirname(__FILE__) . '/',
|
dirname(__FILE__) . '/',
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -112,7 +112,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||||
'autoescape' => false,
|
'autoescape' => false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
|
$this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
|
||||||
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
||||||
$this->template->set_custom_style('tests', $this->template_path);
|
$this->template->set_custom_style('tests', $this->template_path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
|
||||||
'autoescape' => false,
|
'autoescape' => false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
|
$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
|
||||||
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
|
||||||
$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
|
$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue