[feature/twig] No longer using the phpbb_template_locator

This functionality is handled by the Twig Filesystem Loader

PHPBB3-11598
This commit is contained in:
Nathaniel Guse 2013-06-25 19:23:42 -05:00
parent 25f0ee9fb6
commit 7a9aec5fda

View file

@ -58,12 +58,6 @@ class phpbb_template_twig implements phpbb_template
*/
protected $user;
/**
* Template locator
* @var phpbb_template_locator
*/
protected $locator;
/**
* Extension manager.
*
@ -88,6 +82,13 @@ class phpbb_template_twig implements phpbb_template
*/
protected $twig;
/**
* Array of filenames assigned to set_filenames
*
* @var array
*/
protected $filenames = array();
/**
* Constructor.
*
@ -105,7 +106,6 @@ class phpbb_template_twig implements phpbb_template
$this->php_ext = $php_ext;
$this->config = $config;
$this->user = $user;
$this->locator = $locator;
$this->context = $context;
$this->extension_manager = $extension_manager;
@ -161,7 +161,7 @@ class phpbb_template_twig implements phpbb_template
*/
public function set_filenames(array $filename_array)
{
$this->locator->set_filenames($filename_array);
$this->filenames = array_merge($filename_array, $this->filenames);
return $this;
}
@ -181,13 +181,17 @@ class phpbb_template_twig implements phpbb_template
$this->twig->getLoader()->setPaths($style_paths);
// Core style namespace from phpbb_style::set_style()
if ($style_names === array($this->user->style['style_path']) || $style_names[0] == $this->user->style['style_path'])
if ($this->user && ($style_names === array($this->user->style['style_path']) || $style_names[0] == $this->user->style['style_path']))
{
$this->twig->getLoader()->setPaths($style_paths, 'core');
}
// Add admin namespace
// @todo use phpbb_admin path
$this->twig->getLoader()->addPath($this->phpbb_root_path . 'adm/style/', 'admin');
if (is_dir($this->phpbb_root_path . 'adm/style/'))
{
$this->twig->getLoader()->setPaths($this->phpbb_root_path . 'adm/style/', 'admin');
}
// Add all namespaces for all extensions
if ($this->extension_manager instanceof phpbb_extension_manager)
@ -196,15 +200,21 @@ class phpbb_template_twig implements phpbb_template
foreach ($this->extension_manager->all_enabled() as $ext_namespace => $ext_path)
{
// namespaces cannot contain /
$namespace = str_replace('/', '_', $ext_namespace);
$paths = array();
foreach ($style_names as $style_name)
{
if (is_dir($ext_path . 'styles/' . $style_name))
$ext_style_path = $ext_path . 'styles/' . $style_name . '/template';
if (is_dir($ext_style_path))
{
// namespaces cannot contain /
$this->twig->getLoader()->addPath($ext_path . 'styles/' . $style_name . '/template', str_replace('/', '_', $ext_namespace));
}
$paths[] = $ext_style_path;
}
}
$this->twig->getLoader()->setPaths($paths, $namespace);
}
}
@ -253,7 +263,7 @@ class phpbb_template_twig implements phpbb_template
try
{
$this->twig->display($this->locator->get_filename_for_handle($handle), $this->get_template_vars());
$this->twig->display($this->filenames[$handle], $this->get_template_vars());
}
catch (Twig_Error $e)
{