From 3997ffac2a2e6f422dcd5cd5bd076edee6fa91dd Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 13:13:21 +0200 Subject: [PATCH] [feature/merging-style-components] Creating style class Creating phpbb_style class, changing template initialization to style initialization PHPBB3-10632 --- phpBB/common.php | 6 +- phpBB/includes/bbcode.php | 9 +- phpBB/includes/functions_messenger.php | 6 +- phpBB/includes/style/style.php | 89 ++++++++++++++++++++ phpBB/install/index.php | 5 +- tests/template/template_inheritance_test.php | 5 +- tests/template/template_test_case.php | 8 +- 7 files changed, 106 insertions(+), 22 deletions(-) create mode 100644 phpBB/includes/style/style.php diff --git a/phpBB/common.php b/phpBB/common.php index a38a986280..dd49b29528 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -120,9 +120,9 @@ set_config_count(null, null, null, $config); // load extensions $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); -$phpbb_style_locator = new phpbb_style_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_locator, $phpbb_style_path_provider); +// Initialize style +$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); +$template = $style->template; // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 61271545bd..3831cb03ad 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -132,12 +132,11 @@ class bbcode { $this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']); - $template_locator = new phpbb_style_locator(); - $template_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, $template_locator, $template_path_provider); + $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); + $template = $style->template; $template->set_template(); - $template_locator->set_filenames(array('bbcode.html' => 'bbcode.html')); - $this->template_filename = $template_locator->get_source_file_for_handle('bbcode.html'); + $template->set_filenames(array('bbcode.html' => 'bbcode.html')); + $this->template_filename = $style->locator->get_source_file_for_handle('bbcode.html'); } $bbcode_ids = $rowset = $sql = array(); diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 1fb5f15879..4e1ec160af 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -208,10 +208,9 @@ class messenger // tpl_msg now holds a template object we can use to parse the template file if (!isset($this->tpl_msg[$template_lang . $template_file])) { - $template_locator = new phpbb_style_locator(); - $template_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); - $this->tpl_msg[$template_lang . $template_file] = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $template_locator, $template_path_provider); + $this->tpl_msg[$template_lang . $template_file] = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); $tpl = &$this->tpl_msg[$template_lang . $template_file]; + $tpl = $tpl->template; $fallback_template_path = false; @@ -237,6 +236,7 @@ class messenger } $this->tpl_obj = &$this->tpl_msg[$template_lang . $template_file]; + $this->tpl_obj = $this->tpl_obj->template; $this->vars = &$this->tpl_obj->_rootref; $this->tpl_msg = ''; diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php new file mode 100644 index 0000000000..217a70e237 --- /dev/null +++ b/phpBB/includes/style/style.php @@ -0,0 +1,89 @@ +phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->user = $user; + $this->locator = new phpbb_style_locator(); + $this->provider = new phpbb_style_path_provider(); + if ($phpbb_extension_manager !== false) + { + $this->provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, $this->provider); + } + $this->template = new phpbb_style_template($this->phpbb_root_path, $this->phpEx, $this->config, $this->user, $this->locator, $this->provider); + } +} diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 9b0dde1009..7c6dd10d03 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -201,9 +201,8 @@ $config = new phpbb_config(array( 'load_tplcompile' => '1' )); -$phpbb_style_locator = new phpbb_style_locator(); -$phpbb_style_path_provider = new phpbb_style_path_provider(); -$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_locator, $phpbb_style_path_provider); +$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); +$template = $style->template; $template->set_ext_dir_prefix('adm/'); $template->set_custom_template('../adm/style', 'admin'); $template->assign_var('T_ASSETS_PATH', '../assets'); diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index e2a2ac2261..2c67b38641 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -71,9 +71,8 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t $this->template_path = dirname(__FILE__) . '/templates'; $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; - $this->template_locator = new phpbb_style_locator(); - $this->template_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); + $this->template = $this->style->template; $this->template->set_custom_template($this->template_path, 'tests', $this->parent_template_path, 'parent'); } } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 8eea11e84f..a0e980621d 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -12,10 +12,9 @@ require_once dirname(__FILE__) . '/../mock/extension_manager.php'; class phpbb_template_template_test_case extends phpbb_test_case { + protected $style; protected $template; protected $template_path; - protected $template_locator; - protected $template_provider; // Keep the contents of the cache for debugging? const PRESERVE_CACHE = true; @@ -63,9 +62,8 @@ class phpbb_template_template_test_case extends phpbb_test_case $config = new phpbb_config(array_merge($defaults, $new_config)); $this->template_path = dirname(__FILE__) . '/templates'; - $this->template_locator = new phpbb_style_locator(); - $this->template_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); + $this->template = $this->style->template; $this->template->set_custom_template($this->template_path, 'tests'); }