From b12f9a285546641415d9ea2dd9e3a3dba6527d1a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:21:26 +0200 Subject: [feature/dic] Remove cache factory, now handled by DIC PHPBB3-10739 --- phpBB/includes/cache/factory.php | 42 ---------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 phpBB/includes/cache/factory.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/factory.php b/phpBB/includes/cache/factory.php deleted file mode 100644 index 01c4d0b901..0000000000 --- a/phpBB/includes/cache/factory.php +++ /dev/null @@ -1,42 +0,0 @@ -acm_type = $acm_type; - } - - public function get_driver() - { - $class_name = 'phpbb_cache_driver_' . $this->acm_type; - return new $class_name(); - } - - public function get_service() - { - $driver = $this->get_driver(); - $service = new phpbb_cache_service($driver); - return $service; - } -} -- cgit v1.2.1 From 2e76620c8824da62f97cfdaee8f9b1014159fd7c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 00:22:55 +0200 Subject: [feature/dic] Rewrite cron system to use DIC PHPBB3-10739 --- phpBB/includes/cron/manager.php | 36 +++--------------- phpBB/includes/cron/task/core/prune_all_forums.php | 25 +++++++----- phpBB/includes/cron/task/core/prune_forum.php | 44 +++++++++------------- phpBB/includes/cron/task/core/queue.php | 18 ++++++--- phpBB/includes/cron/task/core/tidy_cache.php | 17 ++++++--- phpBB/includes/cron/task/core/tidy_database.php | 15 ++++++-- phpBB/includes/cron/task/core/tidy_search.php | 24 +++++++----- phpBB/includes/cron/task/core/tidy_sessions.php | 14 +++++-- phpBB/includes/cron/task/core/tidy_warnings.php | 18 ++++++--- phpBB/includes/cron/task/provider.php | 37 ++++++++++-------- 10 files changed, 130 insertions(+), 118 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index 7a78a1b054..5abbc987dd 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -35,26 +35,25 @@ class phpbb_cron_manager /** * Constructor. Loads all available tasks. * - * @param array|Traversable $task_names Provides an iterable set of task names + * @param array|Traversable $tasks Provides an iterable set of task names */ - public function __construct($task_names) + public function __construct($tasks) { - $this->load_tasks($task_names); + $this->load_tasks($tasks); } /** * Loads tasks given by name, wraps them * and puts them into $this->tasks. * - * @param array|Traversable $task_names Array of strings + * @param array|Traversable $tasks Array of instances of phpbb_cron_task * * @return void */ - public function load_tasks($task_names) + public function load_tasks($tasks) { - foreach ($task_names as $task_name) + foreach ($tasks as $task) { - $task = new $task_name(); $wrapper = new phpbb_cron_task_wrapper($task); $this->tasks[] = $wrapper; } @@ -120,27 +119,4 @@ class phpbb_cron_manager } return null; } - - /** - * Creates an instance of parametrized cron task $name with args $args. - * The constructed task is wrapped with cron task wrapper before being returned. - * - * @param string $name The task name, which is the same as cron task class name. - * @param array $args Will be passed to the task class's constructor. - * - * @return phpbb_cron_task_wrapper|null - */ - public function instantiate_task($name, array $args) - { - $task = $this->find_task($name); - if ($task) - { - // task here is actually an instance of cron task wrapper - $class = $task->get_name(); - $task = new $class($args); - // need to wrap the new task too - $task = new phpbb_cron_task_wrapper($task); - } - return $task; - } } diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index 15b93a9ca6..f3a179d81b 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -26,6 +26,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config, $db; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, dbal $db) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->db = $db; + } + /** * Runs this cron task. * @@ -33,19 +43,17 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx, $db; - if (!function_exists('auto_prune')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq FROM ' . FORUMS_TABLE . " - WHERE enable_prune = 1 + WHERE enable_prune = 1 AND prune_next < " . time(); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if ($row['prune_days']) { @@ -57,7 +65,7 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } /** @@ -69,7 +77,6 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base */ public function is_runnable() { - global $config; - return (bool) $config['use_system_cron']; + return (bool) $this->config['use_system_cron']; } } diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 7686fd4281..1f717904ef 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -26,31 +26,25 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements phpbb_cron_task_parametrized { + private $phpbb_root_path, $phpEx, $config, $db; private $forum_data; + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, dbal $db) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->db = $db; + } + /** - * Constructor. - * - * If $forum_data is given, it is assumed to contain necessary information - * about a single forum that is to be pruned. - * - * If $forum_data is not given, forum id will be retrieved via request_var - * and a database query will be performed to load the necessary information - * about the forum. + * Manually set forum data. * * @param array $forum_data Information about a forum to be pruned. */ - public function __construct($forum_data = null) + public function set_forum_data($forum_data) { - global $db; - if ($forum_data) - { - $this->forum_data = $forum_data; - } - else - { - $this->forum_data = null; - } + $this->forum_data = $forum_data; } /** @@ -60,10 +54,9 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ public function run() { - global $phpbb_root_path, $phpEx; if (!function_exists('auto_prune')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } if ($this->forum_data['prune_days']) @@ -90,8 +83,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ public function is_runnable() { - global $config; - return !$config['use_system_cron'] && $this->forum_data; + return !$this->config['use_system_cron'] && $this->forum_data; } /** @@ -130,8 +122,6 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ public function parse_parameters(phpbb_request_interface $request) { - global $db; - $this->forum_data = null; if ($request->is_set('f')) { @@ -140,9 +130,9 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if ($row) { diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index 1c72eec7c7..70db94f31d 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -22,6 +22,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_queue extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -29,10 +38,9 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx; if (!class_exists('queue')) { - include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->phpEx); } $queue = new queue(); $queue->process(); @@ -47,8 +55,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function is_runnable() { - global $phpbb_root_path, $phpEx; - return file_exists($phpbb_root_path . 'cache/queue.' . $phpEx); + return file_exists($this->phpbb_root_path . 'cache/queue.' . $this->phpEx); } /** @@ -61,7 +68,6 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['last_queue_run'] < time() - $config['queue_interval_config']; + return $this->config['last_queue_run'] < time() - $this->config['queue_interval_config']; } } diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index c9dc0bd9ae..530f25dacb 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -22,6 +22,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base { + private $config, $cache; + + public function __construct(phpbb_config $config, phpbb_cache_driver_interface $cache) + { + $this->config = $config; + $this->cache = $cache; + } + /** * Runs this cron task. * @@ -29,8 +37,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function run() { - global $cache; - $cache->tidy(); + $this->cache->tidy(); } /** @@ -43,8 +50,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function is_runnable() { - global $cache; - return method_exists($cache, 'tidy'); + return method_exists($this->cache, 'tidy'); } /** @@ -58,7 +64,6 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['cache_last_gc'] < time() - $config['cache_gc']; + return $this->config['cache_last_gc'] < time() - $this->config['cache_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index 80a1901b1e..910e27cf20 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -22,6 +22,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -29,10 +38,9 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx; if (!function_exists('tidy_database')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } tidy_database(); } @@ -48,7 +56,6 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['database_last_gc'] < time() - $config['database_gc']; + return $this->config['database_last_gc'] < time() - $this->config['database_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 8a0b1b690a..1b8a0b8151 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -24,6 +24,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -31,14 +40,12 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx, $config, $error; - // Select the search method - $search_type = basename($config['search_type']); + $search_type = basename($this->config['search_type']); if (!class_exists($search_type)) { - include("{$phpbb_root_path}includes/search/$search_type.$phpEx"); + include($this->phpbb_root_path . "includes/search/$search_type." . $this->phpEx); } // We do some additional checks in the module to ensure it can actually be utilised @@ -62,12 +69,10 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function is_runnable() { - global $phpbb_root_path, $phpEx, $config; - // Select the search method - $search_type = basename($config['search_type']); + $search_type = basename($this->config['search_type']); - return file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx); + return file_exists($this->phpbb_root_path . 'includes/search/' . $search_type . '.' . $this->phpEx); } /** @@ -81,7 +86,6 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['search_last_gc'] < time() - $config['search_gc']; + return $this->config['search_last_gc'] < time() - $this->config['search_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index ae7bb242b8..b409c93868 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -22,6 +22,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base { + private $config, $user; + + public function __construct(phpbb_config $config, phpbb_user $user) + { + $this->config = $config; + $this->user = $user; + } + /** * Runs this cron task. * @@ -29,8 +37,7 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base */ public function run() { - global $user; - $user->session_gc(); + $this->user->session_gc(); } /** @@ -44,7 +51,6 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['session_last_gc'] < time() - $config['session_gc']; + return $this->config['session_last_gc'] < time() - $this->config['session_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index e1434e7087..3b87a300d0 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -24,6 +24,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -31,10 +40,9 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx; if (!function_exists('tidy_warnings')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } tidy_warnings(); } @@ -48,8 +56,7 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base */ public function is_runnable() { - global $config; - return (bool) $config['warnings_expire_days']; + return (bool) $this->config['warnings_expire_days']; } /** @@ -63,7 +70,6 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['warnings_last_gc'] < time() - $config['warnings_gc']; + return $this->config['warnings_last_gc'] < time() - $this->config['warnings_gc']; } } diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 1482051699..acc3d455ec 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\Container; + /** * Provides cron manager with tasks * @@ -22,27 +24,30 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_cron_task_provider extends phpbb_extension_provider +class phpbb_cron_task_provider implements IteratorAggregate { + private $container; + + public function __construct(Container $container) + { + $this->container = $container; + } + /** - * Finds cron task names using the extension manager. - * - * All PHP files in includes/cron/task/core/ are considered tasks. Tasks - * in extensions have to be located in a directory called cron or a subdir - * of a directory called cron. The class and filename must end in a _task - * suffix. Additionally all PHP files in includes/cron/task/core/ are - * tasks. + * Retrieve an iterator over all items * - * @return array List of task names + * @return ArrayIterator An iterator for the array of cron tasks */ - protected function find() + public function getIterator() { - $finder = $this->extension_manager->get_finder(); + $definitions = $this->container->findTaggedServiceIds('cron.task'); + + $tasks = array(); + foreach ($definitions as $name => $definition) + { + $tasks[] = $this->container->get($name); + } - return $finder - ->extension_suffix('_task') - ->extension_directory('/cron') - ->core_path('includes/cron/task/core/') - ->get_classes(); + return new ArrayIterator($tasks); } } -- cgit v1.2.1 From 3896ee953fbdb45d0485c0b5dcdfca47409a22ed Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 14:34:35 +0200 Subject: [feature/dic] Give all cron tasks a name, change some manager usage PHPBB3-10739 --- phpBB/includes/cron/manager.php | 15 ++++++++++++--- phpBB/includes/cron/task/base.php | 22 ++++++++++++++++++++++ phpBB/includes/cron/task/provider.php | 7 ++++++- phpBB/includes/cron/task/task.php | 7 +++++++ phpBB/includes/cron/task/wrapper.php | 20 ++++++-------------- 5 files changed, 53 insertions(+), 18 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index 5abbc987dd..5ea909eb2c 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -32,13 +32,18 @@ class phpbb_cron_manager */ protected $tasks = array(); + protected $phpbb_root_path, $phpEx; + /** * Constructor. Loads all available tasks. * * @param array|Traversable $tasks Provides an iterable set of task names */ - public function __construct($tasks) + public function __construct($tasks, $phpbb_root_path, $phpEx) { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->load_tasks($tasks); } @@ -54,8 +59,7 @@ class phpbb_cron_manager { foreach ($tasks as $task) { - $wrapper = new phpbb_cron_task_wrapper($task); - $this->tasks[] = $wrapper; + $this->tasks[] = $this->wrap_task($task); } } @@ -119,4 +123,9 @@ class phpbb_cron_manager } return null; } + + public function wrap_task(phpbb_cron_task $task) + { + return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->phpEx); + } } diff --git a/phpBB/includes/cron/task/base.php b/phpBB/includes/cron/task/base.php index c05fb9a87c..94a2f267b4 100644 --- a/phpBB/includes/cron/task/base.php +++ b/phpBB/includes/cron/task/base.php @@ -28,6 +28,28 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_cron_task_base implements phpbb_cron_task { + private $name; + + /** + * Returns the name of the task. + * + * @return string Name of wrapped task. + */ + public function get_name() + { + return $this->name; + } + + /** + * Sets the name of the task. + * + * @param string $name The task name + */ + public function set_name($name) + { + $this->name = $name; + } + /** * Returns whether this cron task can run, given current board configuration. * diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index acc3d455ec..9994d707f2 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -45,7 +45,12 @@ class phpbb_cron_task_provider implements IteratorAggregate $tasks = array(); foreach ($definitions as $name => $definition) { - $tasks[] = $this->container->get($name); + $task = $this->container->get($name); + if ($task instanceof phpbb_cron_task_base) { + $task->set_name($name); + } + + $tasks[] = $task; } return new ArrayIterator($tasks); diff --git a/phpBB/includes/cron/task/task.php b/phpBB/includes/cron/task/task.php index 2f2a9e51f9..7b08fed413 100644 --- a/phpBB/includes/cron/task/task.php +++ b/phpBB/includes/cron/task/task.php @@ -21,6 +21,13 @@ if (!defined('IN_PHPBB')) */ interface phpbb_cron_task { + /** + * Returns the name of the task. + * + * @return string Name of wrapped task. + */ + public function get_name(); + /** * Runs this cron task. * diff --git a/phpBB/includes/cron/task/wrapper.php b/phpBB/includes/cron/task/wrapper.php index 66c45189e5..75b7fbdaa3 100644 --- a/phpBB/includes/cron/task/wrapper.php +++ b/phpBB/includes/cron/task/wrapper.php @@ -23,6 +23,8 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_wrapper { + private $task, $phpbb_root_path, $phpEx; + /** * Constructor. * @@ -30,9 +32,11 @@ class phpbb_cron_task_wrapper * * @param phpbb_cron_task $task The cron task to wrap. */ - public function __construct(phpbb_cron_task $task) + public function __construct(phpbb_cron_task $task, $phpbb_root_path, $phpEx) { $this->task = $task; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; } /** @@ -61,16 +65,6 @@ class phpbb_cron_task_wrapper return $this->task->is_runnable() && $this->task->should_run(); } - /** - * Returns the name of wrapped task. It is the same as the wrapped class's class name. - * - * @return string Class name of wrapped task. - */ - public function get_name() - { - return get_class($this->task); - } - /** * Returns a url through which this task may be invoked via web. * @@ -82,8 +76,6 @@ class phpbb_cron_task_wrapper */ public function get_url() { - global $phpbb_root_path, $phpEx; - $name = $this->get_name(); if ($this->is_parametrized()) { @@ -98,7 +90,7 @@ class phpbb_cron_task_wrapper { $extra = ''; } - $url = append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $name . $extra); + $url = append_sid($this->phpbb_root_path . 'cron.' . $this->phpEx, 'cron_type=' . $name . $extra); return $url; } -- cgit v1.2.1 From 3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 15:05:28 +0200 Subject: [feature/dic] Fix test suite for dic-powered cron PHPBB3-10739 --- phpBB/includes/cron/task/provider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 9994d707f2..6adac77eb8 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -15,7 +15,7 @@ if (!defined('IN_PHPBB')) exit; } -use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\DependencyInjection\TaggedContainerInterface; /** * Provides cron manager with tasks @@ -28,7 +28,7 @@ class phpbb_cron_task_provider implements IteratorAggregate { private $container; - public function __construct(Container $container) + public function __construct(TaggedContainerInterface $container) { $this->container = $container; } -- cgit v1.2.1 From 32d2ee61f78e3aeaac5f4f1bcb672c67aa10b10e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 16:14:21 +0200 Subject: [feature/dic] Configure container via config.php, use compiler pass PHPBB3-10739 --- phpBB/includes/di/compiler/config_pass.php | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 phpBB/includes/di/compiler/config_pass.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/compiler/config_pass.php b/phpBB/includes/di/compiler/config_pass.php new file mode 100644 index 0000000000..9288c1760c --- /dev/null +++ b/phpBB/includes/di/compiler/config_pass.php @@ -0,0 +1,51 @@ +config_file = $config_file; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + public function process(ContainerBuilder $container) + { + require $this->config_file; + + $container->setParameter('core.root_path', $this->phpbb_root_path); + $container->setParameter('core.php_ext', $this->php_ext); + + $container->setParameter('core.table_prefix', $table_prefix); + $container->setParameter('cache.driver.class', $acm_type); + $container->setParameter('dbal.driver.class', $dbms); + $container->setParameter('dbal.dbhost', $dbhost); + $container->setParameter('dbal.dbuser', $dbuser); + $container->setParameter('dbal.dbpasswd', $dbpasswd); + $container->setParameter('dbal.dbname', $dbname); + $container->setParameter('dbal.dbport', $dbport); + $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); + + $container->set('container', $container); + } +} -- cgit v1.2.1 From 40af25115baf10d367516857f69e3f9807c1ae41 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 20:20:31 +0200 Subject: [feature/dic] Add dbal_ class prefix to dbal.driver.class PHPBB3-10739 --- phpBB/includes/di/compiler/config_pass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/compiler/config_pass.php b/phpBB/includes/di/compiler/config_pass.php index 9288c1760c..0234ab4ebf 100644 --- a/phpBB/includes/di/compiler/config_pass.php +++ b/phpBB/includes/di/compiler/config_pass.php @@ -38,7 +38,7 @@ class phpbb_di_compiler_config_pass implements CompilerPassInterface $container->setParameter('core.table_prefix', $table_prefix); $container->setParameter('cache.driver.class', $acm_type); - $container->setParameter('dbal.driver.class', $dbms); + $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); $container->setParameter('dbal.dbhost', $dbhost); $container->setParameter('dbal.dbuser', $dbuser); $container->setParameter('dbal.dbpasswd', $dbpasswd); -- cgit v1.2.1 From 967cc550ed9bb74480f46212768502627f26d62d Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 20:42:07 +0200 Subject: [feature/dic] Introduce DI processors instead of abusing compiler passes PHPBB3-10739 --- phpBB/includes/di/compiler/config_pass.php | 51 ----------------------------- phpBB/includes/di/processor/config.php | 52 ++++++++++++++++++++++++++++++ phpBB/includes/di/processor/interface.php | 23 +++++++++++++ 3 files changed, 75 insertions(+), 51 deletions(-) delete mode 100644 phpBB/includes/di/compiler/config_pass.php create mode 100644 phpBB/includes/di/processor/config.php create mode 100644 phpBB/includes/di/processor/interface.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/compiler/config_pass.php b/phpBB/includes/di/compiler/config_pass.php deleted file mode 100644 index 0234ab4ebf..0000000000 --- a/phpBB/includes/di/compiler/config_pass.php +++ /dev/null @@ -1,51 +0,0 @@ -config_file = $config_file; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } - - public function process(ContainerBuilder $container) - { - require $this->config_file; - - $container->setParameter('core.root_path', $this->phpbb_root_path); - $container->setParameter('core.php_ext', $this->php_ext); - - $container->setParameter('core.table_prefix', $table_prefix); - $container->setParameter('cache.driver.class', $acm_type); - $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); - $container->setParameter('dbal.dbhost', $dbhost); - $container->setParameter('dbal.dbuser', $dbuser); - $container->setParameter('dbal.dbpasswd', $dbpasswd); - $container->setParameter('dbal.dbname', $dbname); - $container->setParameter('dbal.dbport', $dbport); - $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); - - $container->set('container', $container); - } -} diff --git a/phpBB/includes/di/processor/config.php b/phpBB/includes/di/processor/config.php new file mode 100644 index 0000000000..d9f866992e --- /dev/null +++ b/phpBB/includes/di/processor/config.php @@ -0,0 +1,52 @@ +config_file = $config_file; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + public function process(ContainerBuilder $container) + { + require $this->config_file; + + $container->setParameter('core.root_path', $this->phpbb_root_path); + $container->setParameter('core.php_ext', $this->php_ext); + + $container->setParameter('core.table_prefix', $table_prefix); + $container->setParameter('cache.driver.class', $acm_type); + $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); + $container->setParameter('dbal.dbhost', $dbhost); + $container->setParameter('dbal.dbuser', $dbuser); + $container->setParameter('dbal.dbpasswd', $dbpasswd); + $container->setParameter('dbal.dbname', $dbname); + $container->setParameter('dbal.dbport', $dbport); + $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); + + $container->set('container', $container); + } +} diff --git a/phpBB/includes/di/processor/interface.php b/phpBB/includes/di/processor/interface.php new file mode 100644 index 0000000000..51bd85a076 --- /dev/null +++ b/phpBB/includes/di/processor/interface.php @@ -0,0 +1,23 @@ + Date: Sat, 21 Jul 2012 21:02:55 +0200 Subject: [feature/dic] Load services from extensions PHPBB3-10739 --- phpBB/includes/di/processor/ext.php | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 phpBB/includes/di/processor/ext.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/processor/ext.php b/phpBB/includes/di/processor/ext.php new file mode 100644 index 0000000000..b39ba5e686 --- /dev/null +++ b/phpBB/includes/di/processor/ext.php @@ -0,0 +1,41 @@ +extension_manager = $extension_manager; + } + + public function process(ContainerBuilder $container) + { + $enabled_exts = $this->extension_manager->all_enabled(); + foreach ($enabled_exts as $name => $path) { + if (file_exists($path . '/config/services.yml')) { + $loader = new YamlFileLoader($container, new FileLocator($path . '/config')); + $loader->load('services.yml'); + } + } + } +} -- cgit v1.2.1 From 5cdcaaa5318c05a04c544eeb25ced571737c2ce3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 26 Jul 2012 16:15:56 +0200 Subject: [feature/dic] Rename {phpEx => php_ext} for consistency PHPBB3-10739 --- phpBB/includes/cron/manager.php | 8 ++++---- phpBB/includes/cron/task/core/prune_all_forums.php | 8 ++++---- phpBB/includes/cron/task/core/prune_forum.php | 8 ++++---- phpBB/includes/cron/task/core/queue.php | 10 +++++----- phpBB/includes/cron/task/core/tidy_database.php | 8 ++++---- phpBB/includes/cron/task/core/tidy_search.php | 10 +++++----- phpBB/includes/cron/task/core/tidy_warnings.php | 8 ++++---- phpBB/includes/cron/task/wrapper.php | 8 ++++---- 8 files changed, 34 insertions(+), 34 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index 5ea909eb2c..018ae39f18 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -32,17 +32,17 @@ class phpbb_cron_manager */ protected $tasks = array(); - protected $phpbb_root_path, $phpEx; + protected $phpbb_root_path, $php_ext; /** * Constructor. Loads all available tasks. * * @param array|Traversable $tasks Provides an iterable set of task names */ - public function __construct($tasks, $phpbb_root_path, $phpEx) + public function __construct($tasks, $phpbb_root_path, $php_ext) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->load_tasks($tasks); } @@ -126,6 +126,6 @@ class phpbb_cron_manager public function wrap_task(phpbb_cron_task $task) { - return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->phpEx); + return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->php_ext); } } diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index f3a179d81b..f175dde650 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -26,12 +26,12 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base { - private $phpbb_root_path, $phpEx, $config, $db; + private $phpbb_root_path, $php_ext, $config, $db; - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, dbal $db) + public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->config = $config; $this->db = $db; } @@ -45,7 +45,7 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base { if (!function_exists('auto_prune')) { - include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); } $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 1f717904ef..d3b14ff68e 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -26,13 +26,13 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements phpbb_cron_task_parametrized { - private $phpbb_root_path, $phpEx, $config, $db; + private $phpbb_root_path, $php_ext, $config, $db; private $forum_data; - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, dbal $db) + public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->config = $config; $this->db = $db; } @@ -56,7 +56,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p { if (!function_exists('auto_prune')) { - include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); } if ($this->forum_data['prune_days']) diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index 70db94f31d..1c5cd8c5db 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -22,12 +22,12 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_queue extends phpbb_cron_task_base { - private $phpbb_root_path, $phpEx, $config; + private $phpbb_root_path, $php_ext, $config; - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->config = $config; } @@ -40,7 +40,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base { if (!class_exists('queue')) { - include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); } $queue = new queue(); $queue->process(); @@ -55,7 +55,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function is_runnable() { - return file_exists($this->phpbb_root_path . 'cache/queue.' . $this->phpEx); + return file_exists($this->phpbb_root_path . 'cache/queue.' . $this->php_ext); } /** diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index 910e27cf20..d0e6c9a253 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -22,12 +22,12 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base { - private $phpbb_root_path, $phpEx, $config; + private $phpbb_root_path, $php_ext, $config; - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->config = $config; } @@ -40,7 +40,7 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base { if (!function_exists('tidy_database')) { - include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); } tidy_database(); } diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 1b8a0b8151..fcd639cfee 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -24,12 +24,12 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base { - private $phpbb_root_path, $phpEx, $config; + private $phpbb_root_path, $php_ext, $config; - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->config = $config; } @@ -45,7 +45,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base if (!class_exists($search_type)) { - include($this->phpbb_root_path . "includes/search/$search_type." . $this->phpEx); + include($this->phpbb_root_path . "includes/search/$search_type." . $this->php_ext); } // We do some additional checks in the module to ensure it can actually be utilised @@ -72,7 +72,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base // Select the search method $search_type = basename($this->config['search_type']); - return file_exists($this->phpbb_root_path . 'includes/search/' . $search_type . '.' . $this->phpEx); + return file_exists($this->phpbb_root_path . 'includes/search/' . $search_type . '.' . $this->php_ext); } /** diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index 3b87a300d0..9d9139b950 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -24,12 +24,12 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base { - private $phpbb_root_path, $phpEx, $config; + private $phpbb_root_path, $php_ext, $config; - public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->config = $config; } @@ -42,7 +42,7 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base { if (!function_exists('tidy_warnings')) { - include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); } tidy_warnings(); } diff --git a/phpBB/includes/cron/task/wrapper.php b/phpBB/includes/cron/task/wrapper.php index 75b7fbdaa3..d1ddf20156 100644 --- a/phpBB/includes/cron/task/wrapper.php +++ b/phpBB/includes/cron/task/wrapper.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_wrapper { - private $task, $phpbb_root_path, $phpEx; + private $task, $phpbb_root_path, $php_ext; /** * Constructor. @@ -32,11 +32,11 @@ class phpbb_cron_task_wrapper * * @param phpbb_cron_task $task The cron task to wrap. */ - public function __construct(phpbb_cron_task $task, $phpbb_root_path, $phpEx) + public function __construct(phpbb_cron_task $task, $phpbb_root_path, $php_ext) { $this->task = $task; $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; } /** @@ -90,7 +90,7 @@ class phpbb_cron_task_wrapper { $extra = ''; } - $url = append_sid($this->phpbb_root_path . 'cron.' . $this->phpEx, 'cron_type=' . $name . $extra); + $url = append_sid($this->phpbb_root_path . 'cron.' . $this->php_ext, 'cron_type=' . $name . $extra); return $url; } -- cgit v1.2.1 From 5a548fa3442b0f63e1c2ff892b93335487cd616c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 26 Jul 2012 16:37:59 +0200 Subject: [feature/dic] Adjust cache driver class name for BC PHPBB3-10739 --- phpBB/includes/di/processor/config.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/processor/config.php b/phpBB/includes/di/processor/config.php index d9f866992e..45b750c31e 100644 --- a/phpBB/includes/di/processor/config.php +++ b/phpBB/includes/di/processor/config.php @@ -38,7 +38,7 @@ class phpbb_di_processor_config implements phpbb_di_processor_interface $container->setParameter('core.php_ext', $this->php_ext); $container->setParameter('core.table_prefix', $table_prefix); - $container->setParameter('cache.driver.class', $acm_type); + $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); $container->setParameter('dbal.dbhost', $dbhost); $container->setParameter('dbal.dbuser', $dbuser); @@ -49,4 +49,13 @@ class phpbb_di_processor_config implements phpbb_di_processor_interface $container->set('container', $container); } + + protected function fix_acm_type($acm_type) + { + if (preg_match('#^[a-z]+$#', $acm_type)) { + return 'phpbb_cache_driver_'.$acm_type; + } + + return $acm_type; + } } -- cgit v1.2.1 From a9c10a480ce10ebecd9f83e4c362729872f08678 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 26 Jul 2012 16:58:18 +0200 Subject: [feature/dic] Generate full cache driver class name on fresh install PHPBB3-10739 --- phpBB/includes/functions_install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 46541acd44..a6af69cfac 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -540,7 +540,7 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = 'dbuser' => $data['dbuser'], 'dbpasswd' => htmlspecialchars_decode($data['dbpasswd']), 'table_prefix' => $data['table_prefix'], - 'acm_type' => 'file', + 'acm_type' => 'phpbb_cache_driver_file', 'load_extensions' => $load_extensions, ); -- cgit v1.2.1 From fbdc956a1cc2352e3392a392e54a2125c297b78e Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 11:52:06 -0400 Subject: [feature/add_events] Replaced current append_sid() hook with new event The new event, core.append_sid_override can either supplement or override the append_sid() function. PHPBB3-9550 --- phpBB/includes/functions.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index ecec1e5e4a..584d88aaf6 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2238,14 +2238,34 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } - // Developers using the hook function need to globalise the $_SID and $_EXTRA_URL on their own and also handle it appropriately. - // They could mimic most of what is within this function - if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id)) + $append_sid_override = false; + + /** + * This event can either supplement or override the append_sid() function + * + * To override this function, the event must set $append_sid_override to + * the new URL value, which will be returned following the event + * + * @event core.append_sid_override + * @var string url The url the session id needs to be + * appended to (can have params) + * @var mixed params String or array of additional url + * parameters + * @var bool is_amp Is url using & (true) or + * & (false) + * @var bool|string session_id Possibility to use a custom session + * id (string) instead of the global + * one (false) + * @var bool|string append_sid_override Overwrite function (string URL) + * or not (false) + * @since 3.1-A1 + */ + $vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_override'); + extract($phpbb_dispatcher->trigger_event('core.append_sid_override', compact($vars))); + + if ($append_sid_override) { - if ($phpbb_hook->hook_return(__FUNCTION__)) - { - return $phpbb_hook->hook_return_result(__FUNCTION__); - } + return $append_sid; } $params_is_array = is_array($params); -- cgit v1.2.1 From abc0ee753d4799270a20bfe756e1b7f9c302394d Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 11:57:43 -0400 Subject: [feature/add_events] Return the correct variable PHPBB3-9550 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 584d88aaf6..8ca15a4908 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2265,7 +2265,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) if ($append_sid_override) { - return $append_sid; + return $append_sid_override; } $params_is_array = is_array($params); -- cgit v1.2.1 From 808af65819d447d35a8129c98fcc2feecb03e25e Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 12:01:08 -0400 Subject: [feature/add_events] Globalize the event dispatcher object PHPBB3-9550 --- phpBB/includes/functions.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 8ca15a4908..3c26337f91 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2231,6 +2231,7 @@ function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $star function append_sid($url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL, $phpbb_hook; + global $phpbb_dispatcher; if ($params === '' || (is_array($params) && empty($params))) { -- cgit v1.2.1 From e80e3809b9c1a2139817aa180aae87576570acaa Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 12:21:44 -0400 Subject: [feature/add_events] Add event core.alter_username_string to change username PHPBB3-9550 --- phpBB/includes/functions_content.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 6b2ee98d7a..1638b5c1c6 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1175,6 +1175,7 @@ function truncate_string($string, $max_length = 60, $max_store_length = 255, $al function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false) { static $_profile_cache; + global $phpbb_dispatcher; // We cache some common variables we need within this function if (empty($_profile_cache)) @@ -1252,10 +1253,34 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', if (($mode == 'full' && !$profile_url) || $mode == 'no_profile') { - return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']); + $username_string = str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']); } + else + { + $username_string = str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']); + } + + /** + * Use this event to change the output of get_username_string() + * + * @event core.alter_username_string + * @var string mode profile|username|colour|full|no_profile + * @var int user_id String or array of additional url + * parameters + * @var string username The user's username + * @var string username_colour Is url using & (true) or + * & (false) + * @var string guest_username optional parameter to specify the + * guest username. + * @var string custom_profile_url Optional parameter to specify a + * profile url. + * @var string username_string The string that has been generated + * @since 3.1-A1 + */ + $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username', 'custom_profile_url', 'username_string'); + extract($phpbb_dispatcher->trigger_event('core.alter_username_string', compact($vars))); - return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']); + return $username_string; } /** -- cgit v1.2.1 From 0ba755f1bdc6329be1e58f6392b67e125abfbff5 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 20:45:09 -0400 Subject: [feature/add_events] Rename core.append_sid_override to just core.append_sid Also, I added the hook back in below the event for backwards compatibility. PHPBB3-9550 --- phpBB/includes/functions.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3c26337f91..404288083b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2247,7 +2247,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) * To override this function, the event must set $append_sid_override to * the new URL value, which will be returned following the event * - * @event core.append_sid_override + * @event core.append_sid * @var string url The url the session id needs to be * appended to (can have params) * @var mixed params String or array of additional url @@ -2262,13 +2262,25 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) * @since 3.1-A1 */ $vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_override'); - extract($phpbb_dispatcher->trigger_event('core.append_sid_override', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.append_sid', compact($vars))); if ($append_sid_override) { return $append_sid_override; } + // The following hook remains for backwards compatibility, though use of + // the event above is preferred. + // Developers using the hook function need to globalise the $_SID and $_EXTRA_URL on their own and also handle it appropriately. + // They could mimic most of what is within this function + if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id)) + { + if ($phpbb_hook->hook_return(__FUNCTION__)) + { + return $phpbb_hook->hook_return_result(__FUNCTION__); + } + } + $params_is_array = is_array($params); // Get anchor -- cgit v1.2.1 From 6c6b179dd4b239030891fcc3b72472fbf4f78bc9 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:25:52 -0400 Subject: [feature/add_events] Rename override to overwrite, made docs 79 chars/line PHPBB3-9550 --- phpBB/includes/functions.php | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 404288083b..9f1172e61e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2239,38 +2239,39 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } - $append_sid_override = false; + $append_sid_overwrite = false; /** * This event can either supplement or override the append_sid() function * - * To override this function, the event must set $append_sid_override to + * To override this function, the event must set $append_sid_overwrite to * the new URL value, which will be returned following the event * * @event core.append_sid - * @var string url The url the session id needs to be - * appended to (can have params) - * @var mixed params String or array of additional url - * parameters - * @var bool is_amp Is url using & (true) or - * & (false) - * @var bool|string session_id Possibility to use a custom session - * id (string) instead of the global - * one (false) - * @var bool|string append_sid_override Overwrite function (string URL) - * or not (false) + * @var string url The url the session id needs + * to be appended to (can have + * params) + * @var mixed params String or array of additional + * url parameters + * @var bool is_amp Is url using & (true) or + * & (false) + * @var bool|string session_id Possibility to use a custom + * session id (string) instead of + * the global one (false) + * @var bool|string append_sid_overwrite Overwrite function (string + * URL) or not (false) * @since 3.1-A1 */ - $vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_override'); + $vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_overwrite'); extract($phpbb_dispatcher->trigger_event('core.append_sid', compact($vars))); - if ($append_sid_override) + if ($append_sid_overwrite) { - return $append_sid_override; + return $append_sid_overwrite; } // The following hook remains for backwards compatibility, though use of - // the event above is preferred. + // the event above is preferred. // Developers using the hook function need to globalise the $_SID and $_EXTRA_URL on their own and also handle it appropriately. // They could mimic most of what is within this function if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id)) -- cgit v1.2.1 From c0cd1fcb4f42e373dad6317ec85fe33474079de2 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:27:28 -0400 Subject: [feature/add_events] Change alter -> modify in event name PHPBB3-9550 --- phpBB/includes/functions_content.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 1638b5c1c6..b1f9cf4434 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1263,7 +1263,7 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', /** * Use this event to change the output of get_username_string() * - * @event core.alter_username_string + * @event core.modify_username_string * @var string mode profile|username|colour|full|no_profile * @var int user_id String or array of additional url * parameters @@ -1278,7 +1278,7 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', * @since 3.1-A1 */ $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username', 'custom_profile_url', 'username_string'); - extract($phpbb_dispatcher->trigger_event('core.alter_username_string', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.modify_username_string', compact($vars))); return $username_string; } -- cgit v1.2.1 From 05755e1b3798d7fdb95bee462890ff94ae76533a Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:31:18 -0400 Subject: [feature/add_events] Fixed docs, added _profile_cache to event parameters PHPBB3-9550 --- phpBB/includes/functions_content.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index b1f9cf4434..8b7565d8f1 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1268,16 +1268,16 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', * @var int user_id String or array of additional url * parameters * @var string username The user's username - * @var string username_colour Is url using & (true) or - * & (false) - * @var string guest_username optional parameter to specify the + * @var string username_colour The user's colour + * @var string guest_username Optional parameter to specify the * guest username. * @var string custom_profile_url Optional parameter to specify a * profile url. * @var string username_string The string that has been generated + * @var array _profile_cache Array of original return templates * @since 3.1-A1 */ - $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username', 'custom_profile_url', 'username_string'); + $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username', 'custom_profile_url', 'username_string', '_profile_cache'); extract($phpbb_dispatcher->trigger_event('core.modify_username_string', compact($vars))); return $username_string; -- cgit v1.2.1 From 1e29f064e87dcab1a3bb65c63d254bde03d6422d Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 12:51:41 -0400 Subject: [feature/add_events] Added events for modifying generate_text_for_display() The events allow you to perform extra functions on the text before nad/or after it has been parsed for BBCode and Smilies. PHPBB3-9550 --- phpBB/includes/functions_content.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 8b7565d8f1..6bad2111ef 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -411,12 +411,26 @@ function strip_bbcode(&$text, $uid = '') function generate_text_for_display($text, $uid, $bitfield, $flags) { static $bbcode; + global $phpbb_dispatcher; if (!$text) { return ''; } + /** + * Use this event to modify the text before it is parsed + * + * @event core.modify_text_for_display_before + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'bitfield', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars))); + $text = censor_text($text); // Parse bbcode if bbcode uid stored and bbcode enabled @@ -443,6 +457,19 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) $text = bbcode_nl2br($text); $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); + /** + * Use this event to modify the text after it is parsed + * + * @event core.modify_text_for_display_after + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'bitfield', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_after', compact($vars))); + return $text; } -- cgit v1.2.1 From 0358db2184885dfec6c9b73573ee457cfccdd644 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 16:42:30 -0400 Subject: [feature/add_events] Before and after events for generate_text_for_* functions PHPBB3-9550 --- phpBB/includes/functions_content.php | 80 ++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 6bad2111ef..f6319284b0 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -418,23 +418,31 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) return ''; } + $censor_text = $allow_bbcode = $allow_smilies = true; + /** * Use this event to modify the text before it is parsed * * @event core.modify_text_for_display_before - * @var string text The text to parse - * @var string uid The BBCode UID - * @var string bitfield The BBCode Bitfield - * @var int flags The BBCode Flags + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @var bool censor_text Whether or not to apply word censors + * @var bool allow_bbcode Whether or not to parse BBCode + * @var bool allow_smilies Whether or not to parse Smilies * @since 3.1-A1 */ - $vars = array('text', 'uid', 'bitfield', 'flags'); + $vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text', 'allow_bbcode', 'allow_smilies'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars))); - $text = censor_text($text); + if ($censor_text) + { + $text = censor_text($text); + } // Parse bbcode if bbcode uid stored and bbcode enabled - if ($uid && ($flags & OPTION_FLAG_BBCODE)) + if ($uid && ($flags & OPTION_FLAG_BBCODE) && $allow_bbcode) { if (!class_exists('bbcode')) { @@ -455,7 +463,11 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) } $text = bbcode_nl2br($text); - $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); + + if ($allow_smilies) + { + $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); + } /** * Use this event to modify the text after it is parsed @@ -482,6 +494,22 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb { global $phpbb_root_path, $phpEx; + /** + * Use this event to modify the text before it is prepared for storage + * + * @event core.modify_text_for_storage_before + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @var bool allow_bbcode Whether or not to parse BBCode + * @var bool allow_urls Whether or not to parse URLs + * @var bool allow_smilies Whether or not to parse Smilies + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'bitfield', 'flags', 'allow_bbcode', 'allow_urls', 'allow_smilies'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_storage_before', compact($vars))); + $uid = $bitfield = ''; $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0); @@ -509,6 +537,19 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb $bitfield = $message_parser->bbcode_bitfield; + /** + * Use this event to modify the text after it is prepared for storage + * + * @event core.modify_text_for_storage_after + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'bitfield', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_storage_after', compact($vars))); + return; } @@ -520,8 +561,31 @@ function generate_text_for_edit($text, $uid, $flags) { global $phpbb_root_path, $phpEx; + /** + * Use this event to modify the text before it is decoded for editing + * + * @event core.modify_text_for_edit_before + * @var string text The text to parse + * @var string uid The BBCode UID + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_edit_before', compact($vars))); + decode_message($text, $uid); + /** + * Use this event to modify the text after it is decoded for editing + * + * @event core.modify_text_for_edit_after + * @var string text The text to parse + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_edit_after', compact($vars))); + return array( 'allow_bbcode' => ($flags & OPTION_FLAG_BBCODE) ? 1 : 0, 'allow_smilies' => ($flags & OPTION_FLAG_SMILIES) ? 1 : 0, -- cgit v1.2.1 From 4f6f0c08979d420a47f5cc4bcab2709d27853222 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 17:04:16 -0400 Subject: [feature/add_events] Event to modify the data array for when a user is added PHPBB3-9550 --- phpBB/includes/functions_user.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 9e33a5122e..f4ecb7cdc3 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -255,6 +255,16 @@ function user_add($user_row, $cp_data = false) } } + /** + * Use this event to modify the values to be inserted when a user is added + * + * @event core.user_add_modify_data + * @var array sql_ary Array of data to be inserted when a user is added + * @since 3.1-A1 + */ + $vars = array('sql_ary'); + extract($phpbb_dispatcher->trigger_event('core.user_add_modify_data', compact($vars))); + $sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); -- cgit v1.2.1 From 46597be1a372f1215ffc18cfd645c1e977b44d84 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 08:37:33 -0400 Subject: [feature/add_events] Globalize event dispatcher object in some functions PHPBB3-9550 --- phpBB/includes/functions_content.php | 2 ++ phpBB/includes/functions_user.php | 1 + 2 files changed, 3 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index f6319284b0..81ac15f168 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -493,6 +493,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false) { global $phpbb_root_path, $phpEx; + global $phpbb_dispatcher; /** * Use this event to modify the text before it is prepared for storage @@ -560,6 +561,7 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb function generate_text_for_edit($text, $uid, $flags) { global $phpbb_root_path, $phpEx; + global $phpbb_dispatcher; /** * Use this event to modify the text before it is decoded for editing diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index f4ecb7cdc3..f843902dd5 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -162,6 +162,7 @@ function user_update_name($old_name, $new_name) function user_add($user_row, $cp_data = false) { global $db, $user, $auth, $config, $phpbb_root_path, $phpEx; + global $phpbb_dispatcher; if (empty($user_row['username']) || !isset($user_row['group_id']) || !isset($user_row['user_email']) || !isset($user_row['user_type'])) { -- cgit v1.2.1 From 575980cba981c2522cc7d3e66e64b9c8fbc36511 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 09:37:47 -0400 Subject: [feature/add_events] Remove $allow_bbcode and $allow_smilies Upon testing it was discovered that these did not work as originally intended. PHPBB3-9550 --- phpBB/includes/functions_content.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 81ac15f168..7fb6ff44cf 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -418,7 +418,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) return ''; } - $censor_text = $allow_bbcode = $allow_smilies = true; + $censor_text = true; /** * Use this event to modify the text before it is parsed @@ -429,11 +429,9 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) * @var string bitfield The BBCode Bitfield * @var int flags The BBCode Flags * @var bool censor_text Whether or not to apply word censors - * @var bool allow_bbcode Whether or not to parse BBCode - * @var bool allow_smilies Whether or not to parse Smilies * @since 3.1-A1 */ - $vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text', 'allow_bbcode', 'allow_smilies'); + $vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars))); if ($censor_text) @@ -442,7 +440,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) } // Parse bbcode if bbcode uid stored and bbcode enabled - if ($uid && ($flags & OPTION_FLAG_BBCODE) && $allow_bbcode) + if ($uid && ($flags & OPTION_FLAG_BBCODE)) { if (!class_exists('bbcode')) { @@ -463,11 +461,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) } $text = bbcode_nl2br($text); - - if ($allow_smilies) - { - $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); - } + $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); /** * Use this event to modify the text after it is parsed -- cgit v1.2.1 From e67b010846389b649aa46729fc4180f2a177e24d Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 10:41:59 -0400 Subject: [feature/add_events] Put globals on one line PHPBB3-9550 --- phpBB/includes/functions_content.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 7fb6ff44cf..e7772e14fe 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -486,8 +486,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) */ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false) { - global $phpbb_root_path, $phpEx; - global $phpbb_dispatcher; + global $phpbb_root_path, $phpEx, $phpbb_dispatcher; /** * Use this event to modify the text before it is prepared for storage @@ -554,8 +553,7 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb */ function generate_text_for_edit($text, $uid, $flags) { - global $phpbb_root_path, $phpEx; - global $phpbb_dispatcher; + global $phpbb_root_path, $phpEx, $phpbb_dispatcher; /** * Use this event to modify the text before it is decoded for editing -- cgit v1.2.1 From 4feb9aa8d7bda303b62acec924008f75042eb757 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 16:43:41 +0200 Subject: [feature/dic] Coding style: Braces PHPBB3-10739 --- phpBB/includes/cron/task/provider.php | 3 ++- phpBB/includes/di/processor/config.php | 3 ++- phpBB/includes/di/processor/ext.php | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 6adac77eb8..134723ebd1 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -46,7 +46,8 @@ class phpbb_cron_task_provider implements IteratorAggregate foreach ($definitions as $name => $definition) { $task = $this->container->get($name); - if ($task instanceof phpbb_cron_task_base) { + if ($task instanceof phpbb_cron_task_base) + { $task->set_name($name); } diff --git a/phpBB/includes/di/processor/config.php b/phpBB/includes/di/processor/config.php index 45b750c31e..1a5ec15854 100644 --- a/phpBB/includes/di/processor/config.php +++ b/phpBB/includes/di/processor/config.php @@ -52,7 +52,8 @@ class phpbb_di_processor_config implements phpbb_di_processor_interface protected function fix_acm_type($acm_type) { - if (preg_match('#^[a-z]+$#', $acm_type)) { + if (preg_match('#^[a-z]+$#', $acm_type)) + { return 'phpbb_cache_driver_'.$acm_type; } diff --git a/phpBB/includes/di/processor/ext.php b/phpBB/includes/di/processor/ext.php index b39ba5e686..04a586a086 100644 --- a/phpBB/includes/di/processor/ext.php +++ b/phpBB/includes/di/processor/ext.php @@ -31,8 +31,10 @@ class phpbb_di_processor_ext implements phpbb_di_processor_interface public function process(ContainerBuilder $container) { $enabled_exts = $this->extension_manager->all_enabled(); - foreach ($enabled_exts as $name => $path) { - if (file_exists($path . '/config/services.yml')) { + foreach ($enabled_exts as $name => $path) + { + if (file_exists($path . '/config/services.yml')) + { $loader = new YamlFileLoader($container, new FileLocator($path . '/config')); $loader->load('services.yml'); } -- cgit v1.2.1 From 4f0f63ae8feb8efc70954e64bdca1f81ae98b212 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 16:51:19 +0200 Subject: [feature/dic] Make cron task attributes protected, one per line PHPBB3-10739 --- phpBB/includes/cron/manager.php | 3 ++- phpBB/includes/cron/task/core/prune_all_forums.php | 5 ++++- phpBB/includes/cron/task/core/prune_forum.php | 8 ++++++-- phpBB/includes/cron/task/core/queue.php | 4 +++- phpBB/includes/cron/task/core/tidy_cache.php | 3 ++- phpBB/includes/cron/task/core/tidy_database.php | 4 +++- phpBB/includes/cron/task/core/tidy_search.php | 4 +++- phpBB/includes/cron/task/core/tidy_sessions.php | 3 ++- phpBB/includes/cron/task/core/tidy_warnings.php | 4 +++- phpBB/includes/cron/task/wrapper.php | 4 +++- 10 files changed, 31 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index 018ae39f18..7d2931b502 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -32,7 +32,8 @@ class phpbb_cron_manager */ protected $tasks = array(); - protected $phpbb_root_path, $php_ext; + protected $phpbb_root_path; + protected $php_ext; /** * Constructor. Loads all available tasks. diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index f175dde650..5164087b68 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -26,7 +26,10 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base { - private $phpbb_root_path, $php_ext, $config, $db; + protected $phpbb_root_path; + protected $php_ext; + protected $config; + protected $db; public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) { diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index d3b14ff68e..428224a527 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -26,8 +26,12 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements phpbb_cron_task_parametrized { - private $phpbb_root_path, $php_ext, $config, $db; - private $forum_data; + protected $phpbb_root_path; + protected $php_ext; + protected $config; + protected $db; + + protected $forum_data; public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) { diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index 1c5cd8c5db..c436c9bbad 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -22,7 +22,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_queue extends phpbb_cron_task_base { - private $phpbb_root_path, $php_ext, $config; + protected $phpbb_root_path; + protected $php_ext + protected $config; public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index 530f25dacb..0c8e8b25fb 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -22,7 +22,8 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base { - private $config, $cache; + protected $config; + protected $cache; public function __construct(phpbb_config $config, phpbb_cache_driver_interface $cache) { diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index d0e6c9a253..4b4679f203 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -22,7 +22,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base { - private $phpbb_root_path, $php_ext, $config; + protected $phpbb_root_path; + protected $php_ext + protected $config; public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index fcd639cfee..a2f1b55763 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -24,7 +24,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base { - private $phpbb_root_path, $php_ext, $config; + protected $phpbb_root_path; + protected $php_ext; + protected $config; public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index b409c93868..695a537274 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -22,7 +22,8 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base { - private $config, $user; + protected $config; + protected $user; public function __construct(phpbb_config $config, phpbb_user $user) { diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index 9d9139b950..acffd12052 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -24,7 +24,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base { - private $phpbb_root_path, $php_ext, $config; + protected $phpbb_root_path; + protected $php_ext; + protected $config; public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { diff --git a/phpBB/includes/cron/task/wrapper.php b/phpBB/includes/cron/task/wrapper.php index d1ddf20156..386fb5b383 100644 --- a/phpBB/includes/cron/task/wrapper.php +++ b/phpBB/includes/cron/task/wrapper.php @@ -23,7 +23,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_wrapper { - private $task, $phpbb_root_path, $php_ext; + protected $task; + protected $phpbb_root_path; + protected $php_ext; /** * Constructor. -- cgit v1.2.1 From fd9fd71a88fad2b33d75722587dbfc0bd100ae50 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 16:54:30 +0200 Subject: [feature/dic] Add docblock for cron_manager::wrap_task() PHPBB3-10739 --- phpBB/includes/cron/manager.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index 7d2931b502..ccaa4f3764 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -125,6 +125,12 @@ class phpbb_cron_manager return null; } + /** + * Wraps a task inside an instance of phpbb_cron_task_wrapper. + * + * @param phpbb_cron_task $task The task. + * @return phpbb_cron_task_wrapper The wrapped task. + */ public function wrap_task(phpbb_cron_task $task) { return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->php_ext); -- cgit v1.2.1 From e103b2f0cc8c8317ce4cb2ca8c4e0e42fca283a2 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 17:04:42 +0200 Subject: [feature/dic] Fix parse errors PHPBB3-10739 --- phpBB/includes/cron/task/core/queue.php | 2 +- phpBB/includes/cron/task/core/tidy_database.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index c436c9bbad..3278ce9d76 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) class phpbb_cron_task_core_queue extends phpbb_cron_task_base { protected $phpbb_root_path; - protected $php_ext + protected $php_ext; protected $config; public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index 4b4679f203..c9f81cbb51 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base { protected $phpbb_root_path; - protected $php_ext + protected $php_ext; protected $config; public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) -- cgit v1.2.1 From c6e522afb6060a9294defe31eafc0130ee3aff15 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 17:16:20 +0200 Subject: [feature/dic] Add a doc block for the prune_forum cron task forum_data PHPBB3-10739 --- phpBB/includes/cron/task/core/prune_forum.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 428224a527..8bb13ffe36 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -31,6 +31,14 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p protected $config; protected $db; + /** + * If $forum_data is given, it is assumed to contain necessary information + * about a single forum that is to be pruned. + * + * If $forum_data is not given, forum id will be retrieved via request_var + * and a database query will be performed to load the necessary information + * about the forum. + */ protected $forum_data; public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) -- cgit v1.2.1 From 7dfe26dd781e7bd0438041058e2a1d95176e7836 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 1 Sep 2012 10:35:46 -0400 Subject: [task/functional] Allow tests to bypass certain restrictions with DEBUG_TEST PHPBB3-10758 --- phpBB/includes/functions.php | 2 +- phpBB/includes/functions_install.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 5914831539..8e7e84bf83 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2811,7 +2811,7 @@ function check_form_key($form_name, $timespan = false, $return_page = '', $trigg $diff = time() - $creation_time; // If creation_time and the time() now is zero we can assume it was not a human doing this (the check for if ($diff)... - if ($diff && ($diff <= $timespan || $timespan === -1)) + if (defined('DEBUG_TEST') || $diff && ($diff <= $timespan || $timespan === -1)) { $token_sid = ($user->data['user_id'] == ANONYMOUS && !empty($config['form_token_sid_guests'])) ? $user->session_id : ''; $key = sha1($creation_time . $user->data['user_form_salt'] . $form_name . $token_sid); diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 89dfb7cd2f..2e10db6b24 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -551,10 +551,12 @@ function adjust_language_keys_callback($matches) * @param string $dbms The name of the DBAL class to use * @param array $load_extensions Array of additional extensions that should be loaded * @param bool $debug If the debug constants should be enabled by default or not +* @param bool $debug_test If the DEBUG_TEST constant should be added +* NOTE: Only for use within the testing framework * * @return string The output to write to the file */ -function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = false) +function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = false, $debug_test = false) { $load_extensions = implode(',', $load_extensions); @@ -584,6 +586,7 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = { $config_data .= "@define('DEBUG', true);\n"; $config_data .= "@define('DEBUG_EXTRA', true);\n"; + $config_data .= "@define('DEBUG_TEST', true);\n"; } else { -- cgit v1.2.1 From 4dd1bbc5879ae5fcae04341a9152e0366ed68bdd Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 1 Sep 2012 10:53:01 -0400 Subject: [task/functional] Fixed DEBUG_TEST related issues PHPBB3-10758 --- phpBB/includes/functions_install.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 2e10db6b24..eae136808c 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -586,7 +586,6 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = { $config_data .= "@define('DEBUG', true);\n"; $config_data .= "@define('DEBUG_EXTRA', true);\n"; - $config_data .= "@define('DEBUG_TEST', true);\n"; } else { @@ -594,6 +593,11 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = $config_data .= "// @define('DEBUG_EXTRA', true);\n"; } + if ($debug_test) + { + $config_data .= "@define('DEBUG_TEST', true);\n"; + } + return $config_data; } -- cgit v1.2.1 From ed052290a70ae3a42f9e7c59f3dca95aba0c0ac7 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 17:40:19 +0200 Subject: [ticket/11082] Remove executable permission from redis driver file PHPBB3-11082 --- phpBB/includes/cache/driver/redis.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 phpBB/includes/cache/driver/redis.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php old mode 100755 new mode 100644 -- cgit v1.2.1 From 8741bcdaf5bb815a228188b4dfe4e3beebcca3b3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 17:51:27 +0200 Subject: [ticket/11083] Mark memory cache driver as abstract PHPBB3-11083 --- phpBB/includes/cache/driver/memory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 92971c6cb2..e0771ab1d3 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * ACM Abstract Memory Class * @package acm */ -class phpbb_cache_driver_memory extends phpbb_cache_driver_base +abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base { var $key_prefix; -- cgit v1.2.1 From 282a80077d4630ba59043fffe59e8a7ce8619ecb Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 19:17:01 +0200 Subject: [feature/dic] Spaces to tabs, add useless docblocks Fully documents the constructors of the processors and the cron tasks. PHPBB3-10739 --- phpBB/includes/cron/task/core/prune_all_forums.php | 8 ++ phpBB/includes/cron/task/core/prune_forum.php | 8 ++ phpBB/includes/cron/task/core/queue.php | 7 ++ phpBB/includes/cron/task/core/tidy_cache.php | 6 ++ phpBB/includes/cron/task/core/tidy_database.php | 7 ++ phpBB/includes/cron/task/core/tidy_search.php | 10 +++ phpBB/includes/cron/task/core/tidy_sessions.php | 6 ++ phpBB/includes/cron/task/core/tidy_warnings.php | 7 ++ phpBB/includes/di/processor/config.php | 96 +++++++++++++--------- phpBB/includes/di/processor/ext.php | 47 +++++++---- phpBB/includes/di/processor/interface.php | 9 +- 11 files changed, 150 insertions(+), 61 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index 5164087b68..252e16e57d 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -31,6 +31,14 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base protected $config; protected $db; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + * @param dbal $db The db connection + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 8bb13ffe36..41d60af921 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -41,6 +41,14 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ protected $forum_data; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + * @param dbal $db The db connection + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index 3278ce9d76..c765660906 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -26,6 +26,13 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base protected $php_ext; protected $config; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index 573243c166..6017eea561 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -25,6 +25,12 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base protected $config; protected $cache; + /** + * Constructor. + * + * @param phpbb_config $config The config + * @param phpbb_cache_driver_interface $cache The cache driver + */ public function __construct(phpbb_config $config, phpbb_cache_driver_interface $cache) { $this->config = $config; diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index c9f81cbb51..1d256f964f 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -26,6 +26,13 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base protected $php_ext; protected $config; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 00af293b6d..2e5f3d79d5 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -31,6 +31,16 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base protected $db; protected $user; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_auth $auth The auth + * @param phpbb_config $config The config + * @param dbal $db The db connection + * @param phpbb_user $user The user + */ public function __construct($phpbb_root_path, $php_ext, phpbb_auth $auth, phpbb_config $config, dbal $db, phpbb_user $user) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index 695a537274..13531aa30b 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -25,6 +25,12 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base protected $config; protected $user; + /** + * Constructor. + * + * @param phpbb_config $config The config + * @param phpbb_user $user The user + */ public function __construct(phpbb_config $config, phpbb_user $user) { $this->config = $config; diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index acffd12052..8dd0674fe5 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -28,6 +28,13 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base protected $php_ext; protected $config; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/di/processor/config.php b/phpBB/includes/di/processor/config.php index 1a5ec15854..22b6252a6d 100644 --- a/phpBB/includes/di/processor/config.php +++ b/phpBB/includes/di/processor/config.php @@ -12,51 +12,65 @@ */ if (!defined('IN_PHPBB')) { - exit; + exit; } use Symfony\Component\DependencyInjection\ContainerBuilder; +/** +* Configure the container for phpBB's services though +* user-defined parameters defined in the config.php file. +*/ class phpbb_di_processor_config implements phpbb_di_processor_interface { - private $config_file; - private $phpbb_root_path; - private $php_ext; - - public function __construct($config_file, $phpbb_root_path, $php_ext) - { - $this->config_file = $config_file; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } - - public function process(ContainerBuilder $container) - { - require $this->config_file; - - $container->setParameter('core.root_path', $this->phpbb_root_path); - $container->setParameter('core.php_ext', $this->php_ext); - - $container->setParameter('core.table_prefix', $table_prefix); - $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); - $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); - $container->setParameter('dbal.dbhost', $dbhost); - $container->setParameter('dbal.dbuser', $dbuser); - $container->setParameter('dbal.dbpasswd', $dbpasswd); - $container->setParameter('dbal.dbname', $dbname); - $container->setParameter('dbal.dbport', $dbport); - $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); - - $container->set('container', $container); - } - - protected function fix_acm_type($acm_type) - { - if (preg_match('#^[a-z]+$#', $acm_type)) - { - return 'phpbb_cache_driver_'.$acm_type; - } - - return $acm_type; - } + private $config_file; + private $phpbb_root_path; + private $php_ext; + + /** + * Constructor. + * + * @param string $config_file The config file + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + */ + public function __construct($config_file, $phpbb_root_path, $php_ext) + { + $this->config_file = $config_file; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * @inheritdoc + */ + public function process(ContainerBuilder $container) + { + require $this->config_file; + + $container->setParameter('core.root_path', $this->phpbb_root_path); + $container->setParameter('core.php_ext', $this->php_ext); + + $container->setParameter('core.table_prefix', $table_prefix); + $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); + $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); + $container->setParameter('dbal.dbhost', $dbhost); + $container->setParameter('dbal.dbuser', $dbuser); + $container->setParameter('dbal.dbpasswd', $dbpasswd); + $container->setParameter('dbal.dbname', $dbname); + $container->setParameter('dbal.dbport', $dbport); + $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); + + $container->set('container', $container); + } + + protected function fix_acm_type($acm_type) + { + if (preg_match('#^[a-z]+$#', $acm_type)) + { + return 'phpbb_cache_driver_'.$acm_type; + } + + return $acm_type; + } } diff --git a/phpBB/includes/di/processor/ext.php b/phpBB/includes/di/processor/ext.php index 04a586a086..e69a3d73b3 100644 --- a/phpBB/includes/di/processor/ext.php +++ b/phpBB/includes/di/processor/ext.php @@ -12,32 +12,43 @@ */ if (!defined('IN_PHPBB')) { - exit; + exit; } use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +/** +* Load the service configurations from all extensions into the container. +*/ class phpbb_di_processor_ext implements phpbb_di_processor_interface { - private $extension_manager; + private $extension_manager; - public function __construct($extension_manager) - { - $this->extension_manager = $extension_manager; - } + /** + * Constructor. + * + * @param string $extension_manager The extension manager + */ + public function __construct($extension_manager) + { + $this->extension_manager = $extension_manager; + } - public function process(ContainerBuilder $container) - { - $enabled_exts = $this->extension_manager->all_enabled(); - foreach ($enabled_exts as $name => $path) - { - if (file_exists($path . '/config/services.yml')) - { - $loader = new YamlFileLoader($container, new FileLocator($path . '/config')); - $loader->load('services.yml'); - } - } - } + /** + * @inheritdoc + */ + public function process(ContainerBuilder $container) + { + $enabled_exts = $this->extension_manager->all_enabled(); + foreach ($enabled_exts as $name => $path) + { + if (file_exists($path . '/config/services.yml')) + { + $loader = new YamlFileLoader($container, new FileLocator($path . '/config')); + $loader->load('services.yml'); + } + } + } } diff --git a/phpBB/includes/di/processor/interface.php b/phpBB/includes/di/processor/interface.php index 51bd85a076..b8563791cc 100644 --- a/phpBB/includes/di/processor/interface.php +++ b/phpBB/includes/di/processor/interface.php @@ -12,12 +12,17 @@ */ if (!defined('IN_PHPBB')) { - exit; + exit; } use Symfony\Component\DependencyInjection\ContainerBuilder; interface phpbb_di_processor_interface { - public function process(ContainerBuilder $container); + /** + * Mutate the container. + * + * @param ContainerBuilder $container The container + */ + public function process(ContainerBuilder $container); } -- cgit v1.2.1