1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-05 05:55:15 +02:00

Merge PR #761 branch 'naderman/ticket/10756' into develop

* naderman/ticket/10756:
  [ticket/10756] Fixing variable declarations in style and template classes
  [ticket/10756] Renaming phpbb_style_template to phpbb_template
  [ticket/10756] Removing path provider from template class
  [ticket/10756] Creating locator interface
  [ticket/10756] Renaming template classes
  [ticket/10756] Moving template classes
This commit is contained in:
Oleg Pudeyev 2012-04-18 22:36:13 -04:00
commit a650da79cb
18 changed files with 183 additions and 58 deletions

View File

@ -124,7 +124,7 @@ $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_ro
// Initialize style
$phpbb_style_resource_locator = new phpbb_style_resource_locator();
$phpbb_style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider());
$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider);
$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator);
$phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template);
$phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager);

View File

@ -134,7 +134,7 @@ class bbcode
$style_resource_locator = new phpbb_style_resource_locator();
$style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider());
$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider);
$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator);
$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $template);
$style->set_style();
$template->set_filenames(array('bbcode.html' => 'bbcode.html'));

View File

@ -210,8 +210,9 @@ class messenger
{
$style_resource_locator = new phpbb_style_resource_locator();
$style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider());
$tpl = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider);
$tpl = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator);
$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $tpl);
$this->tpl_msg[$template_lang . $template_file] = $tpl;
$fallback_template_path = false;

View File

@ -30,7 +30,7 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
class phpbb_style_resource_locator
class phpbb_style_resource_locator implements phpbb_template_locator
{
/**
* Paths to style directories.

View File

@ -22,28 +22,33 @@ if (!defined('IN_PHPBB'))
class phpbb_style
{
/**
* @var phpbb_style_template Template class.
* Template class.
* Handles everything related to templates.
* @var phpbb_template
*/
private $template;
/**
* @var string phpBB root path
* phpBB root path
* @var string
*/
private $phpbb_root_path;
/**
* @var phpEx PHP file extension
* PHP file extension
* @var string
*/
private $phpEx;
/**
* @var phpbb_config phpBB config instance
* phpBB config instance
* @var phpbb_config
*/
private $config;
/**
* @var user current user
* Current user
* @var phpbb_user
*/
private $user;
@ -66,9 +71,9 @@ class phpbb_style
* @param user $user current user
* @param phpbb_style_resource_locator $locator style resource locator
* @param phpbb_style_path_provider $provider style path provider
* @param phpbb_style_template $template template
* @param phpbb_template $template template
*/
public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider, phpbb_style_template $template)
public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider, phpbb_template $template)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
@ -119,7 +124,7 @@ class phpbb_style
$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_';
$this->template->context = new phpbb_style_template_context();
$this->template->context = new phpbb_template_context();
if ($template_path !== false)
{

View File

@ -15,7 +15,7 @@ if (!defined('IN_PHPBB'))
exit;
}
stream_filter_register('phpbb_template', 'phpbb_style_template_filter');
stream_filter_register('phpbb_template', 'phpbb_template_filter');
/**
* Extension of template class - Functions needed for compiling templates only.
@ -23,7 +23,7 @@ stream_filter_register('phpbb_template', 'phpbb_style_template_filter');
* @package phpBB3
* @uses template_filter As a PHP stream filter to perform compilation of templates
*/
class phpbb_style_template_compile
class phpbb_template_compile
{
/**
* Array of parameters to forward to template filter

View File

@ -20,7 +20,7 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
class phpbb_style_template_context
class phpbb_template_context
{
/**
* variable that holds all the data we'll be substituting into
@ -86,7 +86,7 @@ class phpbb_style_template_context
* Returns a reference to template data array.
*
* This function is public so that template renderer may invoke it.
* Users should alter template variables via functions in phpbb_style_template.
* Users should alter template variables via functions in phpbb_template.
*
* Note: modifying returned array will affect data stored in the context.
*

View File

@ -35,7 +35,7 @@ if (!defined('IN_PHPBB'))
* @see template_compile
* @package phpBB3
*/
class phpbb_style_template_filter extends php_user_filter
class phpbb_template_filter extends php_user_filter
{
const REGEX_NS = '[a-z_][a-z_0-9]+';

View File

@ -0,0 +1,121 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Resource locator interface.
*
* Objects implementing this interface maintain mapping from template handles
* to source template file paths and locate templates.
*
* Locates style files.
*
* Resource locator is aware of styles tree, and can return actual
* filesystem paths (i.e., the "child" style or the "parent" styles)
* depending on what files exist.
*
* Root paths stored in locator are paths to style directories. Templates are
* stored in subdirectory that $template_path points to.
*
* @package phpBB3
*/
interface phpbb_template_locator
{
/**
* Sets the template filenames for handles. $filename_array
* should be a hash of handle => filename pairs.
*
* @param array $filname_array Should be a hash of handle => filename pairs.
*/
public function set_filenames(array $filename_array);
/**
* Determines the filename for a template handle.
*
* The filename comes from array used in a set_filenames call,
* which should have been performed prior to invoking this function.
* Return value is a file basename (without path).
*
* @param $handle string Template handle
* @return string Filename corresponding to the template handle
*/
public function get_filename_for_handle($handle);
/**
* Determines the source file path for a template handle without
* regard for styles tree.
*
* This function returns the path in "primary" style directory
* corresponding to the given template handle. That path may or
* may not actually exist on the filesystem. Because this function
* does not perform stat calls to determine whether the path it
* returns actually exists, it is faster than get_source_file_for_handle.
*
* Use get_source_file_for_handle to obtain the actual path that is
* guaranteed to exist (which might come from the parent style
* directory if primary style has parent styles).
*
* This function will trigger an error if the handle was never
* associated with a template file via set_filenames.
*
* @param $handle string Template handle
* @return string Path to source file path in primary style directory
*/
public function get_virtual_source_file_for_handle($handle);
/**
* Determines the source file path for a template handle, accounting
* for styles tree and verifying that the path exists.
*
* This function returns the actual path that may be compiled for
* the specified template handle. It will trigger an error if
* the template handle was never associated with a template path
* via set_filenames or if the template file does not exist on the
* filesystem.
*
* Use get_virtual_source_file_for_handle to just resolve a template
* handle to a path without any filesystem or styles tree checks.
*
* @param string $handle Template handle (i.e. "friendly" template name)
* @param bool $find_all If true, each root path will be checked and function
* will return array of files instead of string and will not
* trigger a error if template does not exist
* @return string Source file path
*/
public function get_source_file_for_handle($handle, $find_all = false);
/**
* Locates source file path, accounting for styles tree and verifying that
* the path exists.
*
* Unlike previous functions, this function works without template handle
* and it can search for more than one file. If more than one file name is
* specified, it will return location of file that it finds first.
*
* @param array $files List of files to locate.
* @param bool $return_default Determines what to return if file does not
* exist. If true, function will return location where file is
* supposed to be. If false, function will return false.
* @param bool $return_full_path If true, function will return full path
* to file. If false, function will return file name. This
* parameter can be used to check which one of set of files
* is available.
* @return string or boolean Source file path if file exists or $return_default is
* true. False if file does not exist and $return_default is false
*/
public function get_first_file_location($files, $return_default = false, $return_full_path = true);
}

View File

@ -23,12 +23,12 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
interface phpbb_style_template_renderer
interface phpbb_template_renderer
{
/**
* Displays the template managed by this renderer.
*
* @param phpbb_style_template_context $context Template context to use
* @param phpbb_template_context $context Template context to use
* @param array $lang Language entries to use
*/
public function render($context, $lang);

View File

@ -21,7 +21,7 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
class phpbb_style_template_renderer_eval implements phpbb_style_template_renderer
class phpbb_template_renderer_eval implements phpbb_template_renderer
{
/**
* Template code to be eval'ed.
@ -33,7 +33,7 @@ class phpbb_style_template_renderer_eval implements phpbb_style_template_rendere
* Template includes are delegated to template object $template.
*
* @param string $code php code of the template
* @param phpbb_style_template $template template object
* @param phpbb_template $template template object
*/
public function __construct($code, $template)
{
@ -45,7 +45,7 @@ class phpbb_style_template_renderer_eval implements phpbb_style_template_rendere
* Displays the template managed by this renderer by eval'ing php code
* of the template.
*
* @param phpbb_style_template_context $context Template context to use
* @param phpbb_template_context $context Template context to use
* @param array $lang Language entries to use
*/
public function render($context, $lang)

View File

@ -22,7 +22,7 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
class phpbb_style_template_renderer_include implements phpbb_style_template_renderer
class phpbb_template_renderer_include implements phpbb_template_renderer
{
/**
* Template path to be included.
@ -45,7 +45,7 @@ class phpbb_style_template_renderer_include implements phpbb_style_template_rend
* Displays the template managed by this renderer by including
* the php file containing the template.
*
* @param phpbb_style_template_context $context Template context to use
* @param phpbb_template_context $context Template context to use
* @param array $lang Language entries to use
*/
public function render($context, $lang)

View File

@ -29,51 +29,51 @@ if (!defined('IN_PHPBB'))
* Base Template class.
* @package phpBB3
*/
class phpbb_style_template
class phpbb_template
{
/**
* @var phpbb_style_template_context Template context.
* Template context.
* Stores template data used during template rendering.
* @var phpbb_template_context
*/
public $context;
/**
* @var string Path of the cache directory for the template
* Path of the cache directory for the template
* @var string
*/
public $cachepath = '';
/**
* @var string phpBB root path
* phpBB root path
* @var string
*/
private $phpbb_root_path;
/**
* @var phpEx PHP file extension
* PHP file extension
* @var string
*/
private $phpEx;
/**
* @var phpbb_config phpBB config instance
* phpBB config instance
* @var phpbb_config
*/
private $config;
/**
* @var user current user
* Current user
* @var phpbb_user
*/
private $user;
/**
* Style resource locator
* @var phpbb_style_resource_locator
* Template locator
* @var phpbb_template_locator
*/
private $locator;
/**
* Template path provider
* @var phpbb_style_path_provider
*/
private $provider;
/**
* Location of templates directory within style directories
* @var string
@ -85,10 +85,9 @@ class phpbb_style_template
*
* @param string $phpbb_root_path phpBB root path
* @param user $user current user
* @param phpbb_style_resource_locator $locator style resource locator
* @param phpbb_style_path_provider $provider style path provider
* @param phpbb_template_locator $locator template locator
*/
public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider)
public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_template_locator $locator)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
@ -96,7 +95,6 @@ class phpbb_style_template
$this->user = $user;
$this->locator = $locator;
$this->template_path = $this->locator->template_path;
$this->provider = $provider;
}
/**
@ -253,15 +251,15 @@ class phpbb_style_template
* configuration setting may be used to force templates to be always
* recompiled.
*
* Returns an object implementing phpbb_style_template_renderer, or null
* Returns an object implementing phpbb_template_renderer, or null
* if template loading or compilation failed. Call render() on the
* renderer to display the template. This will result in template
* contents sent to the output stream (unless, of course, output
* buffering is in effect).
*
* @param string $handle Handle of the template to load
* @return phpbb_style_template_renderer Template renderer object, or null on failure
* @uses phpbb_style_template_compile is used to compile template source
* @return phpbb_template_renderer Template renderer object, or null on failure
* @uses phpbb_template_compile is used to compile template source
*/
private function _tpl_load($handle)
{
@ -285,18 +283,18 @@ class phpbb_style_template
// Recompile page if the original template is newer, otherwise load the compiled version
if (!$recompile)
{
return new phpbb_style_template_renderer_include($output_file, $this);
return new phpbb_template_renderer_include($output_file, $this);
}
$compile = new phpbb_style_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path);
$compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path);
if ($compile->compile_file_to_file($source_file, $output_file) !== false)
{
$renderer = new phpbb_style_template_renderer_include($output_file, $this);
$renderer = new phpbb_template_renderer_include($output_file, $this);
}
else if (($code = $compile->compile_file($source_file)) !== false)
{
$renderer = new phpbb_style_template_renderer_eval($code, $this);
$renderer = new phpbb_template_renderer_eval($code, $this);
}
else
{
@ -358,7 +356,7 @@ class phpbb_style_template
$this->context->append_var($varname, $varval);
}
// Docstring is copied from phpbb_style_template_context method with the same name.
// Docstring is copied from phpbb_template_context method with the same name.
/**
* Assign key variable pairs from an array to a specified block
* @param string $blockname Name of block to assign $vararray to
@ -369,7 +367,7 @@ class phpbb_style_template
return $this->context->assign_block_vars($blockname, $vararray);
}
// Docstring is copied from phpbb_style_template_context method with the same name.
// Docstring is copied from phpbb_template_context method with the same name.
/**
* Change already assigned key variable pair (one-dimensional - single loop entry)
*

View File

@ -202,7 +202,7 @@ $config = new phpbb_config(array(
$phpbb_style_resource_locator = new phpbb_style_resource_locator();
$phpbb_style_path_provider = new phpbb_style_path_provider();
$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider);
$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator);
$phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template);
$phpbb_style->set_ext_dir_prefix('adm/');
$phpbb_style->set_custom_style('admin', '../adm/style', '');

View File

@ -13,8 +13,8 @@ class phpbb_template_renderer_eval_test extends phpbb_test_case
{
$compiled_code = '<a href="<?php echo \'Test\'; ?>">';
$valid_code = '<a href="Test">';
$context = new phpbb_style_template_context();
$template = new phpbb_style_template_renderer_eval($compiled_code, NULL);
$context = new phpbb_template_context();
$template = new phpbb_template_renderer_eval($compiled_code, NULL);
ob_start();
try
{

View File

@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case
protected function setUp()
{
$this->template_compile = new phpbb_style_template_compile(false, null, '');
$this->template_compile = new phpbb_template_compile(false, null, '');
$this->template_path = dirname(__FILE__) . '/templates';
}

View File

@ -66,7 +66,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
$this->template_path = dirname(__FILE__) . '/templates';
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->style_provider = new phpbb_style_path_provider();
$this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider);
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator);
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
$this->style->set_custom_style('tests', $this->template_path, '');
}

View File

@ -22,7 +22,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
$this->parent_template_path = dirname(__FILE__) . '/parent_templates';
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->style_provider = new phpbb_style_path_provider();
$this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider);
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator);
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), '');
}