mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[feature/twig] Use twig loader filesystem with namespaces to add paths
Twig now handles loading style files on its own PHPBB3-11598
This commit is contained in:
parent
38d8025f12
commit
30a1f21735
3 changed files with 65 additions and 11 deletions
|
@ -135,15 +135,29 @@ class phpbb_style
|
||||||
$this->provider->set_styles($paths);
|
$this->provider->set_styles($paths);
|
||||||
$this->locator->set_paths($this->provider);
|
$this->locator->set_paths($this->provider);
|
||||||
|
|
||||||
$this->template->set_style_names($names);
|
|
||||||
|
|
||||||
if ($template_path !== false)
|
if ($template_path !== false)
|
||||||
{
|
{
|
||||||
$this->locator->set_template_path($template_path);
|
$this->locator->set_template_path($template_path);
|
||||||
|
|
||||||
|
$appended_paths = array();
|
||||||
|
foreach ($paths as $path)
|
||||||
|
{
|
||||||
|
$appended_paths[] = $path . '/' . $template_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->template->set_style_names($names, $appended_paths);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->locator->set_default_template_path();
|
$this->locator->set_default_template_path();
|
||||||
|
|
||||||
|
$appended_paths = array();
|
||||||
|
foreach ($paths as $path)
|
||||||
|
{
|
||||||
|
$appended_paths[] = $path . '/template/';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->template->set_style_names($names, $appended_paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_';
|
$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_';
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// @todo remove if not needed
|
||||||
class phpbb_template_twig_loader extends Twig_Loader_Filesystem
|
class phpbb_template_twig_loader extends Twig_Loader_Filesystem
|
||||||
{
|
{
|
||||||
protected $phpbb_locator;
|
protected $phpbb_locator;
|
||||||
|
|
|
@ -91,6 +91,8 @@ class phpbb_template_twig implements phpbb_template
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
* @todo remove unnecessary dependencies
|
||||||
|
*
|
||||||
* @param string $phpbb_root_path phpBB root path
|
* @param string $phpbb_root_path phpBB root path
|
||||||
* @param user $user current user
|
* @param user $user current user
|
||||||
* @param phpbb_template_locator $locator template locator
|
* @param phpbb_template_locator $locator template locator
|
||||||
|
@ -107,17 +109,44 @@ class phpbb_template_twig implements phpbb_template
|
||||||
$this->context = $context;
|
$this->context = $context;
|
||||||
$this->extension_manager = $extension_manager;
|
$this->extension_manager = $extension_manager;
|
||||||
|
|
||||||
$loader = new phpbb_template_twig_loader($phpbb_root_path . 'styles/prosilver/template/', $this->locator);
|
$this->cachepath = $phpbb_root_path . 'cache/twig/';
|
||||||
//$loader = new Twig_Loader_Filesystem($phpbb_root_path . 'adm/style/');
|
|
||||||
|
// Setup loader with __main__ paths
|
||||||
|
$loader = new Twig_Loader_Filesystem(array(
|
||||||
|
$phpbb_root_path . 'styles/prosilver/template/',
|
||||||
|
), $this->locator);
|
||||||
|
|
||||||
|
// Add core namespace
|
||||||
|
$loader->addPath($this->phpbb_root_path . 'styles/prosilver/template/', 'core');
|
||||||
|
|
||||||
|
// Add admin namespace
|
||||||
|
// @todo use phpbb_admin path
|
||||||
|
$loader->addPath($this->phpbb_root_path . 'adm/style/', 'admin');
|
||||||
|
|
||||||
|
// Add all namespaces for all extensions
|
||||||
|
if ($this->extension_manager instanceof phpbb_extension_manager)
|
||||||
|
{
|
||||||
|
foreach ($this->extension_manager->all_enabled() as $ext_namespace => $ext_path)
|
||||||
|
{
|
||||||
|
// @todo proper style chain
|
||||||
|
$loader->addPath($ext_path . 'styles/prosilver/', $ext_namespace);
|
||||||
|
$loader->addPath($ext_path . 'styles/all/', $ext_namespace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->twig = new Twig_Environment($loader, array(
|
$this->twig = new Twig_Environment($loader, array(
|
||||||
'cache' => $phpbb_root_path . 'cache/twig/',
|
'cache' => $this->cachepath,
|
||||||
'debug' => true,
|
'debug' => true, // @todo
|
||||||
'auto_reload' => true,
|
'auto_reload' => true, // @todo
|
||||||
'autoescape' => false,
|
'autoescape' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Clear previous cache files (while WIP)
|
// Clear previous cache files (while WIP)
|
||||||
$this->twig->clearCacheFiles();
|
// @todo remove
|
||||||
|
if (is_dir($this->cachepath))
|
||||||
|
{
|
||||||
|
$this->twig->clearCacheFiles();
|
||||||
|
}
|
||||||
|
|
||||||
$this->twig->addExtension(new phpbb_template_twig_extension);
|
$this->twig->addExtension(new phpbb_template_twig_extension);
|
||||||
|
|
||||||
|
@ -130,12 +159,13 @@ class phpbb_template_twig implements phpbb_template
|
||||||
* Sets the template filenames for handles.
|
* Sets the template filenames for handles.
|
||||||
*
|
*
|
||||||
* @param array $filename_array Should be a hash of handle => filename pairs.
|
* @param array $filename_array Should be a hash of handle => filename pairs.
|
||||||
|
* @return phpbb_template $this
|
||||||
*/
|
*/
|
||||||
public function set_filenames(array $filename_array)
|
public function set_filenames(array $filename_array)
|
||||||
{
|
{
|
||||||
$this->locator->set_filenames($filename_array);
|
$this->locator->set_filenames($filename_array);
|
||||||
|
|
||||||
return true;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,19 +173,27 @@ class phpbb_template_twig implements phpbb_template
|
||||||
* and/or rendered.
|
* and/or rendered.
|
||||||
*
|
*
|
||||||
* @param array $style_names List of style names in inheritance tree order
|
* @param array $style_names List of style names in inheritance tree order
|
||||||
* @return null
|
* @return phpbb_template $this
|
||||||
*/
|
*/
|
||||||
public function set_style_names(array $style_names)
|
public function set_style_names(array $style_names, $style_paths = array())
|
||||||
{
|
{
|
||||||
$this->style_names = $style_names;
|
$this->style_names = $style_names;
|
||||||
|
|
||||||
|
$this->twig->getLoader()->setPaths($style_paths);
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all variables and blocks assigned to this template.
|
* Clears all variables and blocks assigned to this template.
|
||||||
|
*
|
||||||
|
* @return phpbb_template $this
|
||||||
*/
|
*/
|
||||||
public function destroy()
|
public function destroy()
|
||||||
{
|
{
|
||||||
$this->context = array();
|
$this->context = array();
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -236,6 +274,7 @@ class phpbb_template_twig implements phpbb_template
|
||||||
{
|
{
|
||||||
$lang = array();
|
$lang = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $lang;
|
return $lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue