From 8e2cbe39cdd7672638dbc0d6a0f65a7365db0d91 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 04:06:52 +0200 Subject: [PATCH 01/63] [feature/dic] Convert common.php to Symfony2 DependencyInjection component PHPBB3-10739 --- phpBB/common.php | 43 +++++++++--------- phpBB/composer.json | 5 ++- phpBB/composer.lock | 16 ++++++- phpBB/config/parameters.yml | 11 +++++ phpBB/config/services.yml | 87 +++++++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+), 24 deletions(-) create mode 100644 phpBB/config/parameters.yml create mode 100644 phpBB/config/services.yml diff --git a/phpBB/common.php b/phpBB/common.php index b3b8d7e4f7..aa6115fe1c 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -15,6 +15,9 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\EventDispatcher\EventDispatcher; require($phpbb_root_path . 'includes/startup.' . $phpEx); @@ -91,43 +94,41 @@ $phpbb_class_loader_ext->register(); $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); $phpbb_class_loader->register(); +$container = new ContainerBuilder(); +$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/config')); +$loader->load('parameters.yml'); +$loader->load('services.yml'); + +$container->setParameter('core.root_path', $phpbb_root_path); +$container->setParameter('core.php_ext', $phpEx); + // set up caching -$cache_factory = new phpbb_cache_factory($acm_type); -$cache = $cache_factory->get_service(); +$cache = $container->get('cache'); $phpbb_class_loader_ext->set_cache($cache->get_driver()); $phpbb_class_loader->set_cache($cache->get_driver()); // Instantiate some basic classes -$phpbb_dispatcher = new phpbb_event_dispatcher(); -$request = new phpbb_request(); -$user = new phpbb_user(); -$auth = new phpbb_auth(); -$db = new $sql_db(); +$phpbb_dispatcher = $container->get('dispatcher'); +$request = $container->get('request'); +$user = $container->get('user'); +$auth = $container->get('auth'); +$db = $container->get('dbal.conn'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function -// Connect to DB -$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false); - -// We do not need this any longer, unset for safety purposes -unset($dbpasswd); - // Grab global variables, re-cache if necessary -$config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); +$config = $container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions -$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); +$phpbb_extension_manager = $container->get('ext.manager'); -// Initialize style -$phpbb_style_resource_locator = new phpbb_style_resource_locator(); -$phpbb_style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); -$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider); -$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template); +$template = $container->get('template'); +$style = $container->get('style'); -$phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); +$phpbb_subscriber_loader = $container->get('event.subscriber_loader'); $phpbb_subscriber_loader->load(); // Add own hook handler diff --git a/phpBB/composer.json b/phpBB/composer.json index 1059b97f84..56fb2454d1 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -1,5 +1,8 @@ { "require": { - "symfony/event-dispatcher": "2.0.*" + "symfony/config": "2.0.*", + "symfony/dependency-injection": "2.0.*", + "symfony/event-dispatcher": "2.0.*", + "symfony/yaml": "2.0.*" } } diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 062ad4b3aa..1707524da1 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,9 +1,21 @@ { - "hash": "9bada3748ec2933fe0864dcfafbcd671", + "hash": "b1e9c3bcfcee0c5630742abb3e49685f", "packages": [ + { + "package": "symfony/config", + "version": "v2.0.12" + }, + { + "package": "symfony/dependency-injection", + "version": "v2.0.12" + }, { "package": "symfony/event-dispatcher", - "version": "v2.0.10" + "version": "v2.0.12" + }, + { + "package": "symfony/yaml", + "version": "v2.0.12" } ], "aliases": [] diff --git a/phpBB/config/parameters.yml b/phpBB/config/parameters.yml new file mode 100644 index 0000000000..8a90c8e99d --- /dev/null +++ b/phpBB/config/parameters.yml @@ -0,0 +1,11 @@ +parameters: + cache.acm_type: file + dbal.driver: dbal_mysqli + dbal.dbhost: + dbal.dbuser: root + dbal.dbpasswd: + dbal.dbname: phpbb_dev + dbal.dbport: + dbal.new_link: false + tables.config: phpbb_config + tables.ext: phpbb_ext diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml new file mode 100644 index 0000000000..2bf8478f82 --- /dev/null +++ b/phpBB/config/services.yml @@ -0,0 +1,87 @@ +services: + cache_factory: + class: phpbb_cache_factory + arguments: + - %cache.acm_type% + + cache: + class: phpbb_cache_service + factory_service: cache_factory + factory_method: get_service + + cache.driver: + class: phpbb_cache_driver_interface + factory_service: cache + factory_method: get_driver + + dispatcher: + class: phpbb_event_dispatcher + + request: + class: phpbb_request + + user: + class: phpbb_user + + auth: + class: phpbb_auth + + dbal.conn: + class: %dbal.driver% + calls: + - [sql_connect, [%dbal.dbhost%, %dbal.dbuser%, %dbal.dbpasswd%, %dbal.dbname%, %dbal.dbport%, false, %dbal.new_link%]] + + config: + class: phpbb_config_db + arguments: + - @dbal.conn + - @cache.driver + - %tables.config% + + ext.manager: + class: phpbb_extension_manager + arguments: + - @dbal.conn + - %tables.ext% + - %core.root_path% + - .%core.php_ext% + - @cache.driver + + style.resource_locator: + class: phpbb_style_resource_locator + + style.path_provider_ext: + class: phpbb_style_extension_path_provider + arguments: + - @ext.manager + - @style.path_provider + + style.path_provider: + class: phpbb_style_path_provider + + template: + class: phpbb_style_template + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @user + - @style.resource_locator + - @style.path_provider_ext + + style: + class: phpbb_style + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @user + - @style.resource_locator + - @style.path_provider_ext + - @template + + event.subscriber_loader: + class: phpbb_event_extension_subscriber_loader + arguments: + - @dispatcher + - @ext.manager From b12f9a285546641415d9ea2dd9e3a3dba6527d1a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:21:26 +0200 Subject: [PATCH 02/63] [feature/dic] Remove cache factory, now handled by DIC PHPBB3-10739 --- phpBB/config/parameters.yml | 4 +-- phpBB/config/services.yml | 15 ++++-------- phpBB/includes/cache/factory.php | 42 -------------------------------- 3 files changed, 7 insertions(+), 54 deletions(-) delete mode 100644 phpBB/includes/cache/factory.php diff --git a/phpBB/config/parameters.yml b/phpBB/config/parameters.yml index 8a90c8e99d..da29ae8417 100644 --- a/phpBB/config/parameters.yml +++ b/phpBB/config/parameters.yml @@ -1,6 +1,6 @@ parameters: - cache.acm_type: file - dbal.driver: dbal_mysqli + cache.driver.class: phpbb_cache_driver_file + dbal.driver.class: dbal_mysqli dbal.dbhost: dbal.dbuser: root dbal.dbpasswd: diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 2bf8478f82..09eb993ca6 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -1,18 +1,13 @@ services: - cache_factory: - class: phpbb_cache_factory - arguments: - - %cache.acm_type% - cache: class: phpbb_cache_service - factory_service: cache_factory - factory_method: get_service + arguments: + - @cache.driver cache.driver: class: phpbb_cache_driver_interface - factory_service: cache - factory_method: get_driver + arguments: + - %cache.driver.class% dispatcher: class: phpbb_event_dispatcher @@ -27,7 +22,7 @@ services: class: phpbb_auth dbal.conn: - class: %dbal.driver% + class: %dbal.driver.class% calls: - [sql_connect, [%dbal.dbhost%, %dbal.dbuser%, %dbal.dbpasswd%, %dbal.dbname%, %dbal.dbport%, false, %dbal.new_link%]] 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; - } -} From 776160a7e35a1f82325b7acf573906310791c573 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:23:33 +0200 Subject: [PATCH 03/63] [feature/dic] Fetch cache driver explicitly PHPBB3-10739 --- phpBB/common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index aa6115fe1c..591969df74 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -104,8 +104,8 @@ $container->setParameter('core.php_ext', $phpEx); // set up caching $cache = $container->get('cache'); -$phpbb_class_loader_ext->set_cache($cache->get_driver()); -$phpbb_class_loader->set_cache($cache->get_driver()); +$phpbb_class_loader_ext->set_cache($container->get('cache.driver')); +$phpbb_class_loader->set_cache($container->get('cache.driver')); // Instantiate some basic classes $phpbb_dispatcher = $container->get('dispatcher'); From bca600877cbd92246949366238d365bbc3039d5a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:27:46 +0200 Subject: [PATCH 04/63] [feature/dic] Move cron manager into DIC PHPBB3-10739 --- phpBB/common.php | 2 +- phpBB/config/services.yml | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/phpBB/common.php b/phpBB/common.php index 591969df74..0446b5c15e 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -142,5 +142,5 @@ foreach ($cache->obtain_hooks() as $hook) if (!$config['use_system_cron']) { - $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver()); + $cron = $container->get('cron.manager'); } diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 09eb993ca6..85a230de52 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -80,3 +80,14 @@ services: arguments: - @dispatcher - @ext.manager + + cron.task_provider: + class: phpbb_cron_task_provider + arguments: + - @ext.manager + + cron.manager: + class: phpbb_cron_manager + arguments: + - @cron.task_provider + - @cache.driver From 873630f04e6502cc69e6b208f596414f240bc923 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:45:33 +0200 Subject: [PATCH 05/63] [feature/dic] Move class loader into DIC PHPBB3-10739 --- phpBB/common.php | 17 ++++++++--------- phpBB/config/services.yml | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 0446b5c15e..117dc2051e 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -88,12 +88,6 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -// Setup class loader first -$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); -$phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); -$phpbb_class_loader->register(); - $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/config')); $loader->load('parameters.yml'); @@ -102,6 +96,12 @@ $loader->load('services.yml'); $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $phpEx); +// Setup class loader first +$phpbb_class_loader_ext = $container->get('class_loader.ext'); +$phpbb_class_loader_ext->register(); +$phpbb_class_loader = $container->get('class_loader'); +$phpbb_class_loader->register(); + // set up caching $cache = $container->get('cache'); $phpbb_class_loader_ext->set_cache($container->get('cache.driver')); @@ -124,13 +124,12 @@ set_config_count(null, null, null, $config); // load extensions $phpbb_extension_manager = $container->get('ext.manager'); +$phpbb_subscriber_loader = $container->get('event.subscriber_loader'); +$phpbb_subscriber_loader->load(); $template = $container->get('template'); $style = $container->get('style'); -$phpbb_subscriber_loader = $container->get('event.subscriber_loader'); -$phpbb_subscriber_loader->load(); - // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display'))); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 85a230de52..ef459f4903 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -1,13 +1,28 @@ services: + class_loader: + class: phpbb_class_loader + arguments: + - phpbb_ + - %core.root_path%includes/ + - .%core.php_ext% + + class_loader.ext: + class: phpbb_class_loader + arguments: + - phpbb_ext_ + - %core.root_path%ext/ + - .%core.php_ext% + cache: class: phpbb_cache_service arguments: - @cache.driver cache.driver: - class: phpbb_cache_driver_interface - arguments: - - %cache.driver.class% + class: %cache.driver.class% + + cache.driver.install: + class: phpbb_cache_driver_file dispatcher: class: phpbb_event_dispatcher From a7f61b91b7feec80cd9d544502aef937f036ae7c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:45:58 +0200 Subject: [PATCH 06/63] [feature/dic] Use DIC in download/file and install/index PHPBB3-10739 --- phpBB/download/file.php | 39 ++++++++++++++++++++++----------------- phpBB/install/index.php | 24 ++++++++++++++++-------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index c01b0789de..bc7042fbc8 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -14,7 +14,6 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); - // Thank you sun. if (isset($_SERVER['CONTENT_TYPE'])) { @@ -45,20 +44,27 @@ if (isset($_GET['avatar'])) require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); - $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); + $loader->load('parameters.yml'); + $loader->load('services.yml'); + + $container->setParameter('core.root_path', $phpbb_root_path); + $container->setParameter('core.php_ext', $phpEx); + + $phpbb_class_loader_ext = $container->get('class_loader.ext'); $phpbb_class_loader_ext->register(); - $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); + $phpbb_class_loader = $container->get('class_loader'); $phpbb_class_loader->register(); // set up caching - $cache_factory = new phpbb_cache_factory($acm_type); - $cache = $cache_factory->get_service(); - $phpbb_class_loader_ext->set_cache($cache->get_driver()); - $phpbb_class_loader->set_cache($cache->get_driver()); + $cache = $container->get('cache'); + $phpbb_class_loader_ext->set_cache($container->get('cache.driver')); + $phpbb_class_loader->set_cache($container->get('cache.driver')); - $phpbb_dispatcher = new phpbb_event_dispatcher(); - $request = new phpbb_request(); - $db = new $sql_db(); + $phpbb_dispatcher = $container->get('dispatcher'); + $request = $container->get('request'); + $db = $container->get('dbal.conn'); // Connect to DB if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false)) @@ -69,19 +75,18 @@ if (isset($_GET['avatar'])) request_var('', 0, false, false, $request); - // worst-case default - $browser = strtolower($request->header('User-Agent', 'msie 6.0')); - - $config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); + $config = $container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions - $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); - - $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); + $phpbb_extension_manager = $container->get('ext.manager'); + $phpbb_subscriber_loader = $container->get('event.subscriber_loader'); $phpbb_subscriber_loader->load(); + // worst-case default + $browser = strtolower($request->header('User-Agent', 'msie 6.0')); + $filename = request_var('avatar', ''); $avatar_group = false; $exit = false; diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 13ab30a9fa..36c10c3ca6 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -79,19 +79,27 @@ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/functions_install.' . $phpEx); -$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); +$container = new ContainerBuilder(); +$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); +$loader->load('parameters.yml'); +$loader->load('services.yml'); + +$container->setParameter('core.root_path', $phpbb_root_path); +$container->setParameter('core.php_ext', $phpEx); +$container->setAlias('cache.driver.install', 'cache.driver'); + +$phpbb_class_loader_ext = $container->get('class_loader.ext'); $phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); +$phpbb_class_loader = $container->get('class_loader'); $phpbb_class_loader->register(); // set up caching -$cache_factory = new phpbb_cache_factory('file'); -$cache = $cache_factory->get_service(); -$phpbb_class_loader_ext->set_cache($cache->get_driver()); -$phpbb_class_loader->set_cache($cache->get_driver()); +$cache = $container->get('cache'); +$phpbb_class_loader_ext->set_cache($container->get('cache.driver')); +$phpbb_class_loader->set_cache($container->get('cache.driver')); -$phpbb_dispatcher = new phpbb_event_dispatcher(); -$request = new phpbb_request(); +$phpbb_dispatcher = $container->get('dispatcher'); +$request = $container->get('request'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function From dc9ccc432cd0b24cf762f8285d8a90f52b8efe5b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 21:20:58 +0200 Subject: [PATCH 07/63] [feature/dic] Make use of calls to cut down on boilerplate PHPBB3-10739 --- phpBB/common.php | 7 +------ phpBB/config/services.yml | 8 ++++++++ phpBB/download/file.php | 7 +------ phpBB/install/index.php | 6 +----- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 117dc2051e..51478662d7 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -97,15 +97,11 @@ $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $phpEx); // Setup class loader first -$phpbb_class_loader_ext = $container->get('class_loader.ext'); -$phpbb_class_loader_ext->register(); $phpbb_class_loader = $container->get('class_loader'); -$phpbb_class_loader->register(); +$phpbb_class_loader_ext = $container->get('class_loader.ext'); // set up caching $cache = $container->get('cache'); -$phpbb_class_loader_ext->set_cache($container->get('cache.driver')); -$phpbb_class_loader->set_cache($container->get('cache.driver')); // Instantiate some basic classes $phpbb_dispatcher = $container->get('dispatcher'); @@ -125,7 +121,6 @@ set_config_count(null, null, null, $config); // load extensions $phpbb_extension_manager = $container->get('ext.manager'); $phpbb_subscriber_loader = $container->get('event.subscriber_loader'); -$phpbb_subscriber_loader->load(); $template = $container->get('template'); $style = $container->get('style'); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index ef459f4903..6f2ed8c7c3 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -5,6 +5,9 @@ services: - phpbb_ - %core.root_path%includes/ - .%core.php_ext% + calls: + - [register, []] + - [set_cache, [@cache.driver]] class_loader.ext: class: phpbb_class_loader @@ -12,6 +15,9 @@ services: - phpbb_ext_ - %core.root_path%ext/ - .%core.php_ext% + calls: + - [register, []] + - [set_cache, [@cache.driver]] cache: class: phpbb_cache_service @@ -95,6 +101,8 @@ services: arguments: - @dispatcher - @ext.manager + calls: + - [load, []] cron.task_provider: class: phpbb_cron_task_provider diff --git a/phpBB/download/file.php b/phpBB/download/file.php index bc7042fbc8..eabb6edbbb 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -52,15 +52,11 @@ if (isset($_GET['avatar'])) $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $phpEx); - $phpbb_class_loader_ext = $container->get('class_loader.ext'); - $phpbb_class_loader_ext->register(); $phpbb_class_loader = $container->get('class_loader'); - $phpbb_class_loader->register(); + $phpbb_class_loader_ext = $container->get('class_loader.ext'); // set up caching $cache = $container->get('cache'); - $phpbb_class_loader_ext->set_cache($container->get('cache.driver')); - $phpbb_class_loader->set_cache($container->get('cache.driver')); $phpbb_dispatcher = $container->get('dispatcher'); $request = $container->get('request'); @@ -82,7 +78,6 @@ if (isset($_GET['avatar'])) // load extensions $phpbb_extension_manager = $container->get('ext.manager'); $phpbb_subscriber_loader = $container->get('event.subscriber_loader'); - $phpbb_subscriber_loader->load(); // worst-case default $browser = strtolower($request->header('User-Agent', 'msie 6.0')); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 36c10c3ca6..0d7a0a288c 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -88,15 +88,11 @@ $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $phpEx); $container->setAlias('cache.driver.install', 'cache.driver'); -$phpbb_class_loader_ext = $container->get('class_loader.ext'); -$phpbb_class_loader_ext->register(); $phpbb_class_loader = $container->get('class_loader'); -$phpbb_class_loader->register(); +$phpbb_class_loader_ext = $container->get('class_loader.ext'); // set up caching $cache = $container->get('cache'); -$phpbb_class_loader_ext->set_cache($container->get('cache.driver')); -$phpbb_class_loader->set_cache($container->get('cache.driver')); $phpbb_dispatcher = $container->get('dispatcher'); $request = $container->get('request'); From 35c78c127b8fefe56512faaf83c47bee28908e0f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 1 Apr 2012 00:59:23 +0200 Subject: [PATCH 08/63] [feature/dic] Make table_config a DIC parameter PHPBB3-10739 --- phpBB/config/parameters.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/config/parameters.yml b/phpBB/config/parameters.yml index da29ae8417..3bedc9a135 100644 --- a/phpBB/config/parameters.yml +++ b/phpBB/config/parameters.yml @@ -1,4 +1,5 @@ parameters: + core.table_prefix: phpbb_ cache.driver.class: phpbb_cache_driver_file dbal.driver.class: dbal_mysqli dbal.dbhost: @@ -7,5 +8,5 @@ parameters: dbal.dbname: phpbb_dev dbal.dbport: dbal.new_link: false - tables.config: phpbb_config - tables.ext: phpbb_ext + tables.config: %core.table_prefix%config + tables.ext: %core.table_prefix%ext From e78fbfef9c6aac1349d18454a4292781d661795c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 1 Apr 2012 01:13:00 +0200 Subject: [PATCH 09/63] [feature/dic] Move cron.lock_db into DIC PHPBB3-10739 --- phpBB/config/services.yml | 7 +++++++ phpBB/cron.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 6f2ed8c7c3..6817d8f015 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -114,3 +114,10 @@ services: arguments: - @cron.task_provider - @cache.driver + + cron.lock_db: + class: phpbb_lock_db + arguments: + - cron_lock + - @config + - @dbal.conn diff --git a/phpBB/cron.php b/phpBB/cron.php index 36b771f1b7..df48c2dc4d 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -71,7 +71,7 @@ else output_image(); } -$cron_lock = new phpbb_lock_db('cron_lock', $config, $db); +$cron_lock = $container->get('cron.lock_db'); if ($cron_lock->acquire()) { if ($config['use_system_cron']) From 2e76620c8824da62f97cfdaee8f9b1014159fd7c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 00:22:55 +0200 Subject: [PATCH 10/63] [feature/dic] Rewrite cron system to use DIC PHPBB3-10739 --- phpBB/common.php | 37 +++++----- phpBB/config/cron_tasks.yml | 72 +++++++++++++++++++ phpBB/config/services.yml | 5 +- phpBB/download/file.php | 27 +++---- phpBB/includes/cron/manager.php | 36 ++-------- .../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 +++-- .../includes/cron/task/core/tidy_database.php | 15 ++-- phpBB/includes/cron/task/core/tidy_search.php | 24 ++++--- .../includes/cron/task/core/tidy_sessions.php | 14 ++-- .../includes/cron/task/core/tidy_warnings.php | 18 +++-- phpBB/includes/cron/task/provider.php | 45 ++++++------ phpBB/install/index.php | 21 +++--- phpBB/viewforum.php | 4 +- 16 files changed, 257 insertions(+), 165 deletions(-) create mode 100644 phpBB/config/cron_tasks.yml diff --git a/phpBB/common.php b/phpBB/common.php index 51478662d7..c9eb5d217b 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -88,42 +88,43 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -$container = new ContainerBuilder(); -$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/config')); +$phpbb_container = new ContainerBuilder(); +$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config')); $loader->load('parameters.yml'); $loader->load('services.yml'); -$container->setParameter('core.root_path', $phpbb_root_path); -$container->setParameter('core.php_ext', $phpEx); +$phpbb_container->setParameter('core.root_path', $phpbb_root_path); +$phpbb_container->setParameter('core.php_ext', $phpEx); +$phpbb_container->set('container', $phpbb_container); // Setup class loader first -$phpbb_class_loader = $container->get('class_loader'); -$phpbb_class_loader_ext = $container->get('class_loader.ext'); +$phpbb_class_loader = $phpbb_container->get('class_loader'); +$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); // set up caching -$cache = $container->get('cache'); +$cache = $phpbb_container->get('cache'); // Instantiate some basic classes -$phpbb_dispatcher = $container->get('dispatcher'); -$request = $container->get('request'); -$user = $container->get('user'); -$auth = $container->get('auth'); -$db = $container->get('dbal.conn'); +$phpbb_dispatcher = $phpbb_container->get('dispatcher'); +$request = $phpbb_container->get('request'); +$user = $phpbb_container->get('user'); +$auth = $phpbb_container->get('auth'); +$db = $phpbb_container->get('dbal.conn'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function // Grab global variables, re-cache if necessary -$config = $container->get('config'); +$config = $phpbb_container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions -$phpbb_extension_manager = $container->get('ext.manager'); -$phpbb_subscriber_loader = $container->get('event.subscriber_loader'); +$phpbb_extension_manager = $phpbb_container->get('ext.manager'); +$phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); -$template = $container->get('template'); -$style = $container->get('style'); +$template = $phpbb_container->get('template'); +$style = $phpbb_container->get('style'); // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); @@ -136,5 +137,5 @@ foreach ($cache->obtain_hooks() as $hook) if (!$config['use_system_cron']) { - $cron = $container->get('cron.manager'); + $cron = $phpbb_container->get('cron.manager'); } diff --git a/phpBB/config/cron_tasks.yml b/phpBB/config/cron_tasks.yml new file mode 100644 index 0000000000..18a198fa27 --- /dev/null +++ b/phpBB/config/cron_tasks.yml @@ -0,0 +1,72 @@ +services: + cron.task.core.prune_all_forums: + class: phpbb_cron_task_core_prune_all_forums + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @dbal.conn + tags: + - { name: cron.task } + + cron.task.core.prune_forum: + class: phpbb_cron_task_core_prune_forum + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @dbal.conn + tags: + - { name: cron.task } + + cron.task.core.queue: + class: phpbb_cron_task_core_queue + arguments: + - %core.root_path% + - %core.php_ext% + - @config + tags: + - { name: cron.task } + + cron.task.core.tidy_cache: + class: phpbb_cron_task_core_tidy_cache + arguments: + - @config + - @cache.driver + tags: + - { name: cron.task } + + cron.task.core.tidy_database: + class: phpbb_cron_task_core_tidy_database + arguments: + - %core.root_path% + - %core.php_ext% + - @config + tags: + - { name: cron.task } + + cron.task.core.tidy_search: + class: phpbb_cron_task_core_tidy_search + arguments: + - %core.root_path% + - %core.php_ext% + - @config + tags: + - { name: cron.task } + + cron.task.core.tidy_sessions: + class: phpbb_cron_task_core_tidy_sessions + arguments: + - @config + - @user + tags: + - { name: cron.task } + + cron.task.core.tidy_warnings: + class: phpbb_cron_task_core_tidy_warnings + arguments: + - %core.root_path% + - %core.php_ext% + - @config + tags: + - { name: cron.task } diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 6817d8f015..f6e92112f7 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -1,3 +1,6 @@ +imports: + - { resource: cron_tasks.yml } + services: class_loader: class: phpbb_class_loader @@ -107,7 +110,7 @@ services: cron.task_provider: class: phpbb_cron_task_provider arguments: - - @ext.manager + - @container cron.manager: class: phpbb_cron_manager diff --git a/phpBB/download/file.php b/phpBB/download/file.php index eabb6edbbb..7213e3ac3f 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -44,23 +44,24 @@ if (isset($_GET['avatar'])) require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); - $container = new ContainerBuilder(); - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); + $phpbb_container = new ContainerBuilder(); + $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader->load('parameters.yml'); $loader->load('services.yml'); - $container->setParameter('core.root_path', $phpbb_root_path); - $container->setParameter('core.php_ext', $phpEx); + $phpbb_container->setParameter('core.root_path', $phpbb_root_path); + $phpbb_container->setParameter('core.php_ext', $phpEx); + $phpbb_container->set('container', $phpbb_container); - $phpbb_class_loader = $container->get('class_loader'); - $phpbb_class_loader_ext = $container->get('class_loader.ext'); + $phpbb_class_loader = $phpbb_container->get('class_loader'); + $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); // set up caching - $cache = $container->get('cache'); + $cache = $phpbb_container->get('cache'); - $phpbb_dispatcher = $container->get('dispatcher'); - $request = $container->get('request'); - $db = $container->get('dbal.conn'); + $phpbb_dispatcher = $phpbb_container->get('dispatcher'); + $request = $phpbb_container->get('request'); + $db = $phpbb_container->get('dbal.conn'); // Connect to DB if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false)) @@ -71,13 +72,13 @@ if (isset($_GET['avatar'])) request_var('', 0, false, false, $request); - $config = $container->get('config'); + $config = $phpbb_container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions - $phpbb_extension_manager = $container->get('ext.manager'); - $phpbb_subscriber_loader = $container->get('event.subscriber_loader'); + $phpbb_extension_manager = $phpbb_container->get('ext.manager'); + $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); // worst-case default $browser = strtolower($request->header('User-Agent', 'msie 6.0')); 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 { - /** - * 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. - * - * @return array List of task names - */ - protected function find() - { - $finder = $this->extension_manager->get_finder(); + private $container; - return $finder - ->extension_suffix('_task') - ->extension_directory('/cron') - ->core_path('includes/cron/task/core/') - ->get_classes(); + public function __construct(Container $container) + { + $this->container = $container; + } + + /** + * Retrieve an iterator over all items + * + * @return ArrayIterator An iterator for the array of cron tasks + */ + public function getIterator() + { + $definitions = $this->container->findTaggedServiceIds('cron.task'); + + $tasks = array(); + foreach ($definitions as $name => $definition) + { + $tasks[] = $this->container->get($name); + } + + return new ArrayIterator($tasks); } } diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 0d7a0a288c..dd84e2d519 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -79,23 +79,24 @@ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/functions_install.' . $phpEx); -$container = new ContainerBuilder(); -$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); +$phpbb_container = new ContainerBuilder(); +$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader->load('parameters.yml'); $loader->load('services.yml'); -$container->setParameter('core.root_path', $phpbb_root_path); -$container->setParameter('core.php_ext', $phpEx); -$container->setAlias('cache.driver.install', 'cache.driver'); +$phpbb_container->setParameter('core.root_path', $phpbb_root_path); +$phpbb_container->setParameter('core.php_ext', $phpEx); +$phpbb_container->setAlias('cache.driver.install', 'cache.driver'); +$phpbb_container->set('container', $phpbb_container); -$phpbb_class_loader = $container->get('class_loader'); -$phpbb_class_loader_ext = $container->get('class_loader.ext'); +$phpbb_class_loader = $phpbb_container->get('class_loader'); +$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); // set up caching -$cache = $container->get('cache'); +$cache = $phpbb_container->get('cache'); -$phpbb_dispatcher = $container->get('dispatcher'); -$request = $container->get('request'); +$phpbb_dispatcher = $phpbb_container->get('dispatcher'); +$request = $phpbb_container->get('request'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 2d91581cf4..16342ba1b3 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -193,7 +193,9 @@ if ($forum_data['forum_topics_per_page']) // Do the forum Prune thang - cron type job ... if (!$config['use_system_cron']) { - $task = $cron->instantiate_task('cron_task_core_prune_forum', $forum_data); + $task = $container->get('cron.task.core.prune_forum'); + $task = new phpbb_cron_task_wrapper($task); + $task->set_forum_data($forum_data); if ($task && $task->is_ready()) { $url = $task->get_url(); From aa0c995ed9cdafa2dfaca23b54d5b4cf6323f794 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 13:15:27 +0200 Subject: [PATCH 11/63] [feature/dic] Protect config directory via .htaccess PHPBB3-10739 --- phpBB/config/.htaccess | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 phpBB/config/.htaccess diff --git a/phpBB/config/.htaccess b/phpBB/config/.htaccess new file mode 100644 index 0000000000..aa5afc1640 --- /dev/null +++ b/phpBB/config/.htaccess @@ -0,0 +1,4 @@ + + Order Allow,Deny + Deny from All + \ No newline at end of file From 3896ee953fbdb45d0485c0b5dcdfca47409a22ed Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 14:34:35 +0200 Subject: [PATCH 12/63] [feature/dic] Give all cron tasks a name, change some manager usage PHPBB3-10739 --- phpBB/config/services.yml | 3 ++- phpBB/cron.php | 2 +- 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 ++++++-------------- phpBB/viewforum.php | 8 +++++--- 8 files changed, 61 insertions(+), 23 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index f6e92112f7..94d641ab8b 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -116,7 +116,8 @@ services: class: phpbb_cron_manager arguments: - @cron.task_provider - - @cache.driver + - %core.root_path% + - %core.php_ext% cron.lock_db: class: phpbb_lock_db diff --git a/phpBB/cron.php b/phpBB/cron.php index df48c2dc4d..be328db4de 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -61,7 +61,7 @@ function do_cron($cron_lock, $run_tasks) if ($config['use_system_cron']) { - $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver()); + $cron = $container->get('cron.manager'); } else { 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; } diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 16342ba1b3..25c8f5aa6d 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -193,10 +193,12 @@ if ($forum_data['forum_topics_per_page']) // Do the forum Prune thang - cron type job ... if (!$config['use_system_cron']) { - $task = $container->get('cron.task.core.prune_forum'); - $task = new phpbb_cron_task_wrapper($task); + $cron = $container->get('cron.manager'); + + $task = $cron->find_task('cron.task.core.prune_forum'); $task->set_forum_data($forum_data); - if ($task && $task->is_ready()) + + if ($task->is_ready()) { $url = $task->get_url(); $template->assign_var('RUN_CRON_TASK', 'cron'); From 0a5348a1376fafb487884086a70069bea8c5640b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 14:37:04 +0200 Subject: [PATCH 13/63] [feature/dic] Rename occurances of $container to $phpbb_container PHPBB3-10739 --- phpBB/cron.php | 4 ++-- phpBB/viewforum.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/cron.php b/phpBB/cron.php index be328db4de..95d2f8f9b6 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -61,7 +61,7 @@ function do_cron($cron_lock, $run_tasks) if ($config['use_system_cron']) { - $cron = $container->get('cron.manager'); + $cron = $phpbb_container->get('cron.manager'); } else { @@ -71,7 +71,7 @@ else output_image(); } -$cron_lock = $container->get('cron.lock_db'); +$cron_lock = $phpbb_container->get('cron.lock_db'); if ($cron_lock->acquire()) { if ($config['use_system_cron']) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 25c8f5aa6d..76d5c8ccff 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -193,7 +193,7 @@ if ($forum_data['forum_topics_per_page']) // Do the forum Prune thang - cron type job ... if (!$config['use_system_cron']) { - $cron = $container->get('cron.manager'); + $cron = $phpbb_container->get('cron.manager'); $task = $cron->find_task('cron.task.core.prune_forum'); $task->set_forum_data($forum_data); From 3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 15:05:28 +0200 Subject: [PATCH 14/63] [feature/dic] Fix test suite for dic-powered cron PHPBB3-10739 --- phpBB/includes/cron/task/provider.php | 4 +- tests/cron/ext/testext/cron/dummy_task.php | 5 +++ .../includes/cron/task/core/dummy_task.php | 5 +++ .../cron/task/core/second_dummy_task.php | 5 +++ tests/cron/manager_test.php | 32 +++++++-------- tests/cron/task_provider_test.php | 41 ++++++++++++------- tests/cron/tasks/simple_not_runnable.php | 5 +++ tests/cron/tasks/simple_ready.php | 5 +++ tests/cron/tasks/simple_should_not_run.php | 5 +++ 9 files changed, 74 insertions(+), 33 deletions(-) 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; } diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php index 996f5b39cf..a31806c1b1 100644 --- a/tests/cron/ext/testext/cron/dummy_task.php +++ b/tests/cron/ext/testext/cron/dummy_task.php @@ -11,6 +11,11 @@ class phpbb_ext_testext_cron_dummy_task extends phpbb_cron_task_base { public static $was_run = 0; + public function get_name() + { + return get_class($this); + } + public function run() { self::$was_run++; diff --git a/tests/cron/includes/cron/task/core/dummy_task.php b/tests/cron/includes/cron/task/core/dummy_task.php index 6e2e2db636..ce3e91a9ba 100644 --- a/tests/cron/includes/cron/task/core/dummy_task.php +++ b/tests/cron/includes/cron/task/core/dummy_task.php @@ -11,6 +11,11 @@ class phpbb_cron_task_core_dummy_task extends phpbb_cron_task_base { public static $was_run = 0; + public function get_name() + { + return get_class($this); + } + public function run() { self::$was_run++; diff --git a/tests/cron/includes/cron/task/core/second_dummy_task.php b/tests/cron/includes/cron/task/core/second_dummy_task.php index 8cd0bddfc0..76a55588f9 100644 --- a/tests/cron/includes/cron/task/core/second_dummy_task.php +++ b/tests/cron/includes/cron/task/core/second_dummy_task.php @@ -11,6 +11,11 @@ class phpbb_cron_task_core_second_dummy_task extends phpbb_cron_task_base { public static $was_run = 0; + public function get_name() + { + return get_class($this); + } + public function run() { self::$was_run++; diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php index f433fc9a9b..8ed33b06e2 100644 --- a/tests/cron/manager_test.php +++ b/tests/cron/manager_test.php @@ -19,10 +19,10 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase { public function setUp() { - $this->manager = new phpbb_cron_manager(array( - 'phpbb_cron_task_core_dummy_task', - 'phpbb_cron_task_core_second_dummy_task', - 'phpbb_ext_testext_cron_dummy_task', + $this->manager = $this->create_cron_manager(array( + new phpbb_cron_task_core_dummy_task(), + new phpbb_cron_task_core_second_dummy_task(), + new phpbb_ext_testext_cron_dummy_task(), )); $this->task_name = 'phpbb_cron_task_core_dummy_task'; } @@ -34,13 +34,6 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase $this->assertEquals($this->task_name, $task->get_name()); } - public function test_manager_instantiates_task_by_name() - { - $task = $this->manager->instantiate_task($this->task_name, array()); - $this->assertInstanceOf('phpbb_cron_task_wrapper', $task); - $this->assertEquals($this->task_name, $task->get_name()); - } - public function test_manager_finds_all_ready_tasks() { $tasks = $this->manager->find_all_ready_tasks(); @@ -55,10 +48,10 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase public function test_manager_finds_only_ready_tasks() { - $manager = new phpbb_cron_manager(array( - 'phpbb_cron_task_core_simple_ready', - 'phpbb_cron_task_core_simple_not_runnable', - 'phpbb_cron_task_core_simple_should_not_run', + $manager = $this->create_cron_manager(array( + new phpbb_cron_task_core_simple_ready(), + new phpbb_cron_task_core_simple_not_runnable(), + new phpbb_cron_task_core_simple_should_not_run(), )); $tasks = $manager->find_all_ready_tasks(); $task_names = $this->tasks_to_names($tasks); @@ -70,8 +63,15 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase $names = array(); foreach ($tasks as $task) { - $names[] = get_class($task->task); + $names[] = $task->get_name(); } return $names; } + + private function create_cron_manager($tasks) + { + global $phpbb_root_path, $phpEx; + + return new phpbb_cron_manager($tasks, $phpbb_root_path, $phpEx); + } } diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php index 4547c61a55..4458d811a5 100644 --- a/tests/cron/task_provider_test.php +++ b/tests/cron/task_provider_test.php @@ -7,37 +7,48 @@ * */ -require_once dirname(__FILE__) . '/../mock/extension_manager.php'; +require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php'; +require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php'; +require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php'; class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase { public function setUp() { - $this->extension_manager = new phpbb_mock_extension_manager( - dirname(__FILE__) . '/', - array( - 'testext' => array( - 'ext_name' => 'testext', - 'ext_active' => true, - 'ext_path' => 'ext/testext/' - ), - )); - $this->provider = new phpbb_cron_task_provider($this->extension_manager); + $this->tasks = array( + 'phpbb_cron_task_core_dummy_task', + 'phpbb_cron_task_core_second_dummy_task', + 'phpbb_ext_testext_cron_dummy_task', + ); + + $container = $this->getMock('Symfony\Component\DependencyInjection\TaggedContainerInterface'); + $container + ->expects($this->once()) + ->method('findTaggedServiceIds') + ->will($this->returnValue(array_flip($this->tasks))); + $container + ->expects($this->any()) + ->method('get') + ->will($this->returnCallback(function ($name) { + return new $name; + })); + + $this->provider = new phpbb_cron_task_provider($container); } public function test_manager_finds_shipped_tasks() { - $tasks = array(); + $task_names = array(); foreach ($this->provider as $task) { - $tasks[] = $task; + $task_names[] = $task->get_name(); } - sort($tasks); + sort($task_names); $this->assertEquals(array( 'phpbb_cron_task_core_dummy_task', 'phpbb_cron_task_core_second_dummy_task', 'phpbb_ext_testext_cron_dummy_task', - ), $tasks); + ), $task_names); } } diff --git a/tests/cron/tasks/simple_not_runnable.php b/tests/cron/tasks/simple_not_runnable.php index 837f28f1c0..56d484eacd 100644 --- a/tests/cron/tasks/simple_not_runnable.php +++ b/tests/cron/tasks/simple_not_runnable.php @@ -2,6 +2,11 @@ class phpbb_cron_task_core_simple_not_runnable extends phpbb_cron_task_base { + public function get_name() + { + return get_class($this); + } + public function run() { } diff --git a/tests/cron/tasks/simple_ready.php b/tests/cron/tasks/simple_ready.php index de5f10e491..8aa0507406 100644 --- a/tests/cron/tasks/simple_ready.php +++ b/tests/cron/tasks/simple_ready.php @@ -2,6 +2,11 @@ class phpbb_cron_task_core_simple_ready extends phpbb_cron_task_base { + public function get_name() + { + return get_class($this); + } + public function run() { } diff --git a/tests/cron/tasks/simple_should_not_run.php b/tests/cron/tasks/simple_should_not_run.php index c2a41616f6..58f6df2616 100644 --- a/tests/cron/tasks/simple_should_not_run.php +++ b/tests/cron/tasks/simple_should_not_run.php @@ -2,6 +2,11 @@ class phpbb_cron_task_core_simple_should_not_run extends phpbb_cron_task_base { + public function get_name() + { + return get_class($this); + } + public function run() { } From d908d932736775b0274564dbc6206babf64ba1be Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 12 Jul 2012 16:02:58 -0400 Subject: [PATCH 15/63] [ticket/10444] Do not default to the previous post edit reason. PHPBB3-10444 --- phpBB/posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/posting.php b/phpBB/posting.php index 7f57f693af..558520dbaa 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1376,7 +1376,7 @@ $template->assign_vars(array( 'POST_DATE' => ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '', 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'], - 'EDIT_REASON' => $post_data['post_edit_reason'], + 'EDIT_REASON' => $request->variable('edit_reason', ''), 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"), 'U_VIEW_TOPIC' => ($mode != 'post') ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id") : '', 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&mode=popup"), From 32d2ee61f78e3aeaac5f4f1bcb672c67aa10b10e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 16:14:21 +0200 Subject: [PATCH 16/63] [feature/dic] Configure container via config.php, use compiler pass PHPBB3-10739 --- phpBB/common.php | 21 ++++----- phpBB/config/parameters.yml | 12 ----- phpBB/config/services.yml | 1 + phpBB/config/tables.yml | 3 ++ phpBB/download/file.php | 14 ++++-- phpBB/includes/di/compiler/config_pass.php | 51 ++++++++++++++++++++++ phpBB/install/index.php | 15 +++++-- 7 files changed, 87 insertions(+), 30 deletions(-) delete mode 100644 phpBB/config/parameters.yml create mode 100644 phpBB/config/tables.yml create mode 100644 phpBB/includes/di/compiler/config_pass.php diff --git a/phpBB/common.php b/phpBB/common.php index a69b26c006..e7dabec4ca 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -8,6 +8,11 @@ * Minimum Requirement: PHP 5.3.2 */ +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\Compiler\Compiler; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + /** */ if (!defined('IN_PHPBB')) @@ -15,11 +20,6 @@ if (!defined('IN_PHPBB')) exit; } -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\EventDispatcher\EventDispatcher; - require($phpbb_root_path . 'includes/startup.' . $phpEx); if (file_exists($phpbb_root_path . 'config.' . $phpEx)) @@ -77,25 +77,26 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files require($phpbb_root_path . 'includes/class_loader.' . $phpEx); +require($phpbb_root_path . 'includes/di/compiler/config_pass.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); -require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); +require($phpbb_root_path . 'includes/db/' . ltrim($dbms, 'dbal_') . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config')); -$loader->load('parameters.yml'); $loader->load('services.yml'); -$phpbb_container->setParameter('core.root_path', $phpbb_root_path); -$phpbb_container->setParameter('core.php_ext', $phpEx); -$phpbb_container->set('container', $phpbb_container); +$phpbb_compiler = new Compiler(); +$phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); +$phpbb_compiler->compile($phpbb_container); // Setup class loader first $phpbb_class_loader = $phpbb_container->get('class_loader'); diff --git a/phpBB/config/parameters.yml b/phpBB/config/parameters.yml deleted file mode 100644 index 3c24382fc4..0000000000 --- a/phpBB/config/parameters.yml +++ /dev/null @@ -1,12 +0,0 @@ -parameters: - core.table_prefix: phpbb_ - cache.driver.class: phpbb_cache_driver_file - dbal.driver.class: dbal_mysqli - dbal.dbhost: - dbal.dbuser: root - dbal.dbpasswd: - dbal.dbname: phpbb - dbal.dbport: - dbal.new_link: false - tables.config: %core.table_prefix%config - tables.ext: %core.table_prefix%ext diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 0141641aaf..20f9d67dd0 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -1,4 +1,5 @@ imports: + - { resource: tables.yml } - { resource: cron_tasks.yml } services: diff --git a/phpBB/config/tables.yml b/phpBB/config/tables.yml new file mode 100644 index 0000000000..cfc6dbcfed --- /dev/null +++ b/phpBB/config/tables.yml @@ -0,0 +1,3 @@ +parameters: + tables.config: %core.table_prefix%config + tables.ext: %core.table_prefix%ext diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 7213e3ac3f..d4960dad0d 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -7,6 +7,11 @@ * */ +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\Compiler\Compiler; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + /** * @ignore */ @@ -38,6 +43,8 @@ if (isset($_GET['avatar'])) } require($phpbb_root_path . 'includes/class_loader.' . $phpEx); + require($phpbb_root_path . 'includes/di/compiler/config_pass.' . $phpEx); + require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); @@ -46,12 +53,11 @@ if (isset($_GET['avatar'])) $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); - $loader->load('parameters.yml'); $loader->load('services.yml'); - $phpbb_container->setParameter('core.root_path', $phpbb_root_path); - $phpbb_container->setParameter('core.php_ext', $phpEx); - $phpbb_container->set('container', $phpbb_container); + $phpbb_compiler = new Compiler(); + $phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); + $phpbb_compiler->compile($phpbb_container); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); 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); + } +} diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 88745b8bb9..3e14b719e8 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -7,6 +7,11 @@ * */ +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\Compiler\Compiler; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + /**#@+ * @ignore */ @@ -71,6 +76,8 @@ else // Include essential scripts require($phpbb_root_path . 'includes/class_loader.' . $phpEx); +require($phpbb_root_path . 'includes/di/compiler/config_pass.' . $phpEx); + require($phpbb_root_path . 'includes/functions.' . $phpEx); phpbb_require_updated('includes/functions_content.' . $phpEx, true); @@ -81,13 +88,13 @@ require($phpbb_root_path . 'includes/functions_install.' . $phpEx); $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); -$loader->load('parameters.yml'); $loader->load('services.yml'); -$phpbb_container->setParameter('core.root_path', $phpbb_root_path); -$phpbb_container->setParameter('core.php_ext', $phpEx); +$phpbb_compiler = new Compiler(); +$phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); +$phpbb_compiler->compile($phpbb_container); + $phpbb_container->setAlias('cache.driver.install', 'cache.driver'); -$phpbb_container->set('container', $phpbb_container); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); From 40af25115baf10d367516857f69e3f9807c1ae41 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 20:20:31 +0200 Subject: [PATCH 17/63] [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(-) 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); From 967cc550ed9bb74480f46212768502627f26d62d Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 20:42:07 +0200 Subject: [PATCH 18/63] [feature/dic] Introduce DI processors instead of abusing compiler passes PHPBB3-10739 --- phpBB/common.php | 8 +++---- phpBB/download/file.php | 8 +++---- .../config_pass.php => processor/config.php} | 5 ++-- phpBB/includes/di/processor/interface.php | 23 +++++++++++++++++++ phpBB/install/index.php | 8 +++---- 5 files changed, 38 insertions(+), 14 deletions(-) rename phpBB/includes/di/{compiler/config_pass.php => processor/config.php} (90%) create mode 100644 phpBB/includes/di/processor/interface.php diff --git a/phpBB/common.php b/phpBB/common.php index e7dabec4ca..406d8bb093 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -77,7 +77,8 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files require($phpbb_root_path . 'includes/class_loader.' . $phpEx); -require($phpbb_root_path . 'includes/di/compiler/config_pass.' . $phpEx); +require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx); +require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); @@ -94,9 +95,8 @@ $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config')); $loader->load('services.yml'); -$phpbb_compiler = new Compiler(); -$phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); -$phpbb_compiler->compile($phpbb_container); +$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); +$processor->process($phpbb_container); // Setup class loader first $phpbb_class_loader = $phpbb_container->get('class_loader'); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index d4960dad0d..d8fec8ef94 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -43,7 +43,8 @@ if (isset($_GET['avatar'])) } require($phpbb_root_path . 'includes/class_loader.' . $phpEx); - require($phpbb_root_path . 'includes/di/compiler/config_pass.' . $phpEx); + require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx); + require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -55,9 +56,8 @@ if (isset($_GET['avatar'])) $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader->load('services.yml'); - $phpbb_compiler = new Compiler(); - $phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); - $phpbb_compiler->compile($phpbb_container); + $processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); + $processor->process($phpbb_container); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); diff --git a/phpBB/includes/di/compiler/config_pass.php b/phpBB/includes/di/processor/config.php similarity index 90% rename from phpBB/includes/di/compiler/config_pass.php rename to phpBB/includes/di/processor/config.php index 0234ab4ebf..d9f866992e 100644 --- a/phpBB/includes/di/compiler/config_pass.php +++ b/phpBB/includes/di/processor/config.php @@ -15,12 +15,13 @@ if (!defined('IN_PHPBB')) exit; } -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; -class phpbb_di_compiler_config_pass implements CompilerPassInterface +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) { 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 @@ +load('services.yml'); -$phpbb_compiler = new Compiler(); -$phpbb_compiler->addPass(new phpbb_di_compiler_config_pass($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx)); -$phpbb_compiler->compile($phpbb_container); +$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); +$processor->process($phpbb_container); $phpbb_container->setAlias('cache.driver.install', 'cache.driver'); From 50bc453aa6c91ae9c9df5cb633615825c9df7b6d Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 21:02:55 +0200 Subject: [PATCH 19/63] [feature/dic] Load services from extensions PHPBB3-10739 --- phpBB/common.php | 7 ++++- phpBB/config/services.yml | 7 +++++ phpBB/download/file.php | 7 ++++- phpBB/includes/di/processor/ext.php | 41 +++++++++++++++++++++++++++++ phpBB/install/index.php | 7 ++++- 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 phpBB/includes/di/processor/ext.php diff --git a/phpBB/common.php b/phpBB/common.php index 406d8bb093..f958f06ce0 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -9,7 +9,6 @@ */ use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\Compiler\Compiler; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; @@ -102,6 +101,12 @@ $processor->process($phpbb_container); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); +$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); +foreach ($ids as $id) { + $processor = $phpbb_container->get($id); + $processor->process($phpbb_container); +} + // set up caching $cache = $phpbb_container->get('cache'); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 20f9d67dd0..61497cbcc1 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -126,3 +126,10 @@ services: - cron_lock - @config - @dbal.conn + + processor.config: + class: phpbb_di_processor_ext + arguments: + - @ext.manager + tags: + - { name: container.processor } diff --git a/phpBB/download/file.php b/phpBB/download/file.php index d8fec8ef94..656f1f38d6 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -8,7 +8,6 @@ */ use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\Compiler\Compiler; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; @@ -62,6 +61,12 @@ if (isset($_GET['avatar'])) $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); + $ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); + foreach ($ids as $id) { + $processor = $phpbb_container->get($id); + $processor->process($phpbb_container); + } + // set up caching $cache = $phpbb_container->get('cache'); 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'); + } + } + } +} diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 0e298c8cdc..1ba0798abc 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -8,7 +8,6 @@ */ use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\Compiler\Compiler; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; @@ -99,6 +98,12 @@ $phpbb_container->setAlias('cache.driver.install', 'cache.driver'); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); +$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); +foreach ($ids as $id) { + $processor = $phpbb_container->get($id); + $processor->process($phpbb_container); +} + // set up caching $cache = $phpbb_container->get('cache'); From 0f0622f625ca9fcf30a23de966fdb3829bfde4b4 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 26 Jul 2012 15:55:50 +0200 Subject: [PATCH 20/63] [feature/dic] Require symfony/* 2.1.*, tabs instead of spaces, --dev lock file PHPBB3-10739 --- phpBB/composer.json | 14 +++++------ phpBB/composer.lock | 57 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/phpBB/composer.json b/phpBB/composer.json index 366aea2ac3..2f4987afd8 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -1,12 +1,12 @@ { - "minimum-stability": "beta", - "require": { - "symfony/config": "2.0.*", - "symfony/dependency-injection": "2.0.*", + "minimum-stability": "beta", + "require": { + "symfony/config": "2.1.*", + "symfony/dependency-injection": "2.1.*", "symfony/event-dispatcher": "2.1.*", - "symfony/event-dispatcher": "2.0.*", - "symfony/yaml": "2.0.*" - }, + "symfony/event-dispatcher": "2.1.*", + "symfony/yaml": "2.1.*" + }, "require-dev": { "fabpot/goutte": "1.0.x-dev" } diff --git a/phpBB/composer.lock b/phpBB/composer.lock index f3187749f5..1d8e6b5f8d 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,24 +1,69 @@ { - "hash": "e4f5efe460878599e6fed6bb13584cfd", + "hash": "7024226b03c2abdfa95c76b11c1ec74d", "packages": [ { "package": "symfony/config", - "version": "v2.0.16" + "version": "v2.1.0-BETA4" }, { "package": "symfony/dependency-injection", - "version": "v2.0.16" + "version": "v2.1.0-BETA4" }, { "package": "symfony/event-dispatcher", - "version": "v2.0.16" + "version": "v2.1.0-BETA4" }, { "package": "symfony/yaml", - "version": "v2.0.16" + "version": "v2.1.0-BETA4" + } + ], + "packages-dev": [ + { + "package": "fabpot/goutte", + "version": "dev-master", + "alias-pretty-version": "1.0.x-dev", + "alias-version": "1.0.9999999.9999999-dev" + }, + { + "package": "fabpot/goutte", + "version": "dev-master", + "source-reference": "df14259688c7d6f1d366aa073a589695d2b9f451", + "commit-date": "1343194442" + }, + { + "package": "guzzle/common", + "version": "v2.8.1" + }, + { + "package": "guzzle/http", + "version": "v2.8.1" + }, + { + "package": "guzzle/parser", + "version": "v2.8.1" + }, + { + "package": "symfony/browser-kit", + "version": "v2.1.0-BETA4" + }, + { + "package": "symfony/css-selector", + "version": "v2.1.0-BETA4" + }, + { + "package": "symfony/dom-crawler", + "version": "v2.1.0-BETA4" + }, + { + "package": "symfony/finder", + "version": "v2.1.0-BETA4" + }, + { + "package": "symfony/process", + "version": "v2.1.0-BETA4" } ], - "packages-dev": null, "aliases": [ ], From 8a264228d01215fe1020bf946fc95c804ba95450 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 26 Jul 2012 15:56:55 +0200 Subject: [PATCH 21/63] [feature/dic] Add trailing newline to htaccess PHPBB3-10739 --- phpBB/config/.htaccess | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/config/.htaccess b/phpBB/config/.htaccess index aa5afc1640..4128d345ab 100644 --- a/phpBB/config/.htaccess +++ b/phpBB/config/.htaccess @@ -1,4 +1,4 @@ Order Allow,Deny Deny from All - \ No newline at end of file + From 5cdcaaa5318c05a04c544eeb25ced571737c2ce3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 26 Jul 2012 16:15:56 +0200 Subject: [PATCH 22/63] [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(-) 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; } From 5a548fa3442b0f63e1c2ff892b93335487cd616c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 26 Jul 2012 16:37:59 +0200 Subject: [PATCH 23/63] [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(-) 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; + } } From a9c10a480ce10ebecd9f83e4c362729872f08678 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 26 Jul 2012 16:58:18 +0200 Subject: [PATCH 24/63] [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(-) 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, ); From ed34451d5b84f2e34004f2ddbceb6b0ca5cae025 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 26 Jul 2012 17:01:55 +0200 Subject: [PATCH 25/63] [feature/dic] Adjust installer script to work with partially configured container PHPBB3-10739 --- phpBB/install/index.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 1ba0798abc..3c1d60f554 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -90,20 +90,14 @@ $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader->load('services.yml'); -$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); -$processor->process($phpbb_container); +$phpbb_container->setParameter('core.root_path', $phpbb_root_path); +$phpbb_container->setParameter('core.php_ext', $phpEx); -$phpbb_container->setAlias('cache.driver.install', 'cache.driver'); +$phpbb_container->setAlias('cache.driver', 'cache.driver.install'); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); -$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); -foreach ($ids as $id) { - $processor = $phpbb_container->get($id); - $processor->process($phpbb_container); -} - // set up caching $cache = $phpbb_container->get('cache'); From 53f518ecc7acae1c7f1160bcafee618ef7caba2e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 29 Jul 2012 17:30:06 +0200 Subject: [PATCH 26/63] [feature/dic] Remove duplicate event-dispatcher dependency PHPBB3-10739 --- phpBB/composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/composer.json b/phpBB/composer.json index 2f4987afd8..5e88144bc4 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -4,7 +4,6 @@ "symfony/config": "2.1.*", "symfony/dependency-injection": "2.1.*", "symfony/event-dispatcher": "2.1.*", - "symfony/event-dispatcher": "2.1.*", "symfony/yaml": "2.1.*" }, "require-dev": { From 6613884a60cdf399cd8a3a908bc44247c646bb1b Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 11:37:27 -0400 Subject: [PATCH 27/63] [feature/add_events] Added core.posting_refresh event PHPBB3-9550 --- phpBB/posting.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/phpBB/posting.php b/phpBB/posting.php index a17578e343..77b3c8c861 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -39,6 +39,19 @@ $delete = (isset($_POST['delete'])) ? true : false; $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview) ? true : false; + +/** +* This event allows you to alter the $refresh boolean variable. +* +* If $refresh is true the posting form retains previously submitted form data +* +* @event core.posting_refresh +* @var bool refresh Whether or not to retain previously submitted data +* @since 3.1-A1 +*/ +$vars = array('refresh'); +extract($phpbb_dispatcher->trigger_event('core.posting_refresh', compact($vars))); + $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); $error = $post_data = array(); From fbdc956a1cc2352e3392a392e54a2125c297b78e Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 11:52:06 -0400 Subject: [PATCH 28/63] [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(-) 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); From abc0ee753d4799270a20bfe756e1b7f9c302394d Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 11:57:43 -0400 Subject: [PATCH 29/63] [feature/add_events] Return the correct variable PHPBB3-9550 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 808af65819d447d35a8129c98fcc2feecb03e25e Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 12:01:08 -0400 Subject: [PATCH 30/63] [feature/add_events] Globalize the event dispatcher object PHPBB3-9550 --- phpBB/includes/functions.php | 1 + 1 file changed, 1 insertion(+) 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))) { From e80e3809b9c1a2139817aa180aae87576570acaa Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 12:21:44 -0400 Subject: [PATCH 31/63] [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(-) 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; } /** From 0ba755f1bdc6329be1e58f6392b67e125abfbff5 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 20:45:09 -0400 Subject: [PATCH 32/63] [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(-) 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 From efe9b1010ac7fc38dec0e5182c1902830685f5e3 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 21:22:29 -0400 Subject: [PATCH 33/63] [feature/add_events] Fix append_sid() test PHPBB3-9550 --- tests/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1017e0c72f..89268ddbab 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -22,6 +22,7 @@ $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path $phpbb_class_loader_ext->register(); $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php"); $phpbb_class_loader->register(); +$phpbb_dispatcher = new phpbb_event_dispatcher(); require_once 'test_framework/phpbb_test_case_helpers.php'; require_once 'test_framework/phpbb_test_case.php'; From 008cf967ab176958126582b58941bd7649732315 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:18:53 -0400 Subject: [PATCH 34/63] [feature/add_events] Re-fix broken test PHPBB3-9550 --- tests/bootstrap.php | 1 - tests/session/append_sid_test.php | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 89268ddbab..1017e0c72f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -22,7 +22,6 @@ $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path $phpbb_class_loader_ext->register(); $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php"); $phpbb_class_loader->register(); -$phpbb_dispatcher = new phpbb_event_dispatcher(); require_once 'test_framework/phpbb_test_case_helpers.php'; require_once 'test_framework/phpbb_test_case.php'; diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php index 88f6f0718e..34f6dea8ca 100644 --- a/tests/session/append_sid_test.php +++ b/tests/session/append_sid_test.php @@ -45,6 +45,9 @@ class phpbb_session_append_sid_test extends phpbb_test_case */ public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description) { + global $phpbb_dispatcher; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); } } From 6c6b179dd4b239030891fcc3b72472fbf4f78bc9 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:25:52 -0400 Subject: [PATCH 35/63] [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(-) 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)) From c0cd1fcb4f42e373dad6317ec85fe33474079de2 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:27:28 -0400 Subject: [PATCH 36/63] [feature/add_events] Change alter -> modify in event name PHPBB3-9550 --- phpBB/includes/functions_content.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } From 05755e1b3798d7fdb95bee462890ff94ae76533a Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:31:18 -0400 Subject: [PATCH 37/63] [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(-) 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; From a02bfcc83a3c9a107bc2b840d07409a93628bbdc Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:50:38 -0400 Subject: [PATCH 38/63] [feature/add_events] core.posting_refresh -> core.modify_posting_paramters The event now lets extensions modify the posting paramters, not just refresh PHPBB3-9550 --- phpBB/posting.php | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/phpBB/posting.php b/phpBB/posting.php index 77b3c8c861..33f0bae353 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -39,24 +39,37 @@ $delete = (isset($_POST['delete'])) ? true : false; $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview) ? true : false; - -/** -* This event allows you to alter the $refresh boolean variable. -* -* If $refresh is true the posting form retains previously submitted form data -* -* @event core.posting_refresh -* @var bool refresh Whether or not to retain previously submitted data -* @since 3.1-A1 -*/ -$vars = array('refresh'); -extract($phpbb_dispatcher->trigger_event('core.posting_refresh', compact($vars))); - $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); $error = $post_data = array(); $current_time = time(); +/** +* This event allows you to alter the above parameters, such as submit and mode +* +* Note: $refresh must be true to retain previously submitted form data. +* +* @event core.modify_posting_parameters +* @var bool submit Whether or not the form has been submitted +* @var bool preview Whether or not the post is being previewed +* @var bool save Whether or not a draft is being saved +* @var bool load Whether or not a draft is being loaded +* @var bool delete Whether or not the post is being deleted +* @var bool cancel Whether or not to cancel the form (returns to +* viewtopic or viewforum depending on if the user +* is posting a new topic or editing a post) +* @var bool refresh Whether or not to retain previously submitted data +* @var string mode What action to take if the form has been sumitted +* post|reply|quote|edit|delete|bump|smilies|popup +* @var array error Any error strings; a non-empty array aborts +* form submission. +* NOTE: Should be actual language strings, NOT +* language keys. +* @since 3.1-A1 +*/ +$vars = array('submit', 'preview', 'save', 'load', 'delete', 'cancel', 'refresh', 'mode', 'error'); +extract($phpbb_dispatcher->trigger_event('core.modify_posting_parameters', compact($vars))); + // Was cancel pressed? If so then redirect to the appropriate page if ($cancel || ($current_time - $lastclick < 2 && $submit)) { From 92761e1f2b59bbe817579a1cdddd508b9817cdee Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:59:44 -0400 Subject: [PATCH 39/63] [ticket/10873] Change language for notice about undelivered, deleted PM. See the ticket for my reasoning. PHPBB3-10873 --- phpBB/language/en/ucp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 94d9a5171e..a2c1ad7a3e 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -258,7 +258,7 @@ $lang = array_merge($lang, array( 'MESSAGE_COLOURS' => 'Message colours', 'MESSAGE_DELETED' => 'Message successfully deleted.', 'MESSAGE_HISTORY' => 'Message history', - 'MESSAGE_REMOVED_FROM_OUTBOX' => 'This message has been removed by its author before it was delivered.', + 'MESSAGE_REMOVED_FROM_OUTBOX' => 'This message was deleted by its author.', 'MESSAGE_SENT_ON' => 'on', 'MESSAGE_STORED' => 'This message has been sent successfully.', 'MESSAGE_TO' => 'To', From 1e29f064e87dcab1a3bb65c63d254bde03d6422d Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 12:51:41 -0400 Subject: [PATCH 40/63] [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(+) 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; } From 0358db2184885dfec6c9b73573ee457cfccdd644 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 16:42:30 -0400 Subject: [PATCH 41/63] [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(-) 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, From 4f6f0c08979d420a47f5cc4bcab2709d27853222 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 17:04:16 -0400 Subject: [PATCH 42/63] [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(+) 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); From 46597be1a372f1215ffc18cfd645c1e977b44d84 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 08:37:33 -0400 Subject: [PATCH 43/63] [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(+) 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'])) { From 575980cba981c2522cc7d3e66e64b9c8fbc36511 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 09:37:47 -0400 Subject: [PATCH 44/63] [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(-) 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 From e67b010846389b649aa46729fc4180f2a177e24d Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 10:41:59 -0400 Subject: [PATCH 45/63] [feature/add_events] Put globals on one line PHPBB3-9550 --- phpBB/includes/functions_content.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 From 7ee3eb16ac1a4f11003c72b77352ad7fda53050d Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 23 Aug 2012 12:49:09 -0400 Subject: [PATCH 46/63] [feature/add_events] Add more parameters to core.modify_posting_parameters PHPBB3-9550 --- phpBB/posting.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phpBB/posting.php b/phpBB/posting.php index 33f0bae353..f37d6128de 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -50,6 +50,11 @@ $current_time = time(); * Note: $refresh must be true to retain previously submitted form data. * * @event core.modify_posting_parameters +* @var int post_id ID of the post +* @var int topic_id ID of the topic +* @var int forum_id ID of the forum +* @var int draft_id ID of the draft +* @var int lastclick Timestamp of when the form was last loaded * @var bool submit Whether or not the form has been submitted * @var bool preview Whether or not the post is being previewed * @var bool save Whether or not a draft is being saved @@ -67,7 +72,7 @@ $current_time = time(); * language keys. * @since 3.1-A1 */ -$vars = array('submit', 'preview', 'save', 'load', 'delete', 'cancel', 'refresh', 'mode', 'error'); +$vars = array('post_id', 'topic_id', 'forum_id', 'draft_id', 'lastclick', 'submit', 'preview', 'save', 'load', 'delete', 'cancel', 'refresh', 'mode', 'error'); extract($phpbb_dispatcher->trigger_event('core.modify_posting_parameters', compact($vars))); // Was cancel pressed? If so then redirect to the appropriate page From 7e44ca4d49a53b81ee1365282ae5f86cd32e7e4a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 16:39:38 +0200 Subject: [PATCH 47/63] [feature/dic] Re-order services alphabetically PHPBB3-10739 --- phpBB/config/services.yml | 122 +++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 61497cbcc1..a4e96a3797 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -3,6 +3,20 @@ imports: - { resource: cron_tasks.yml } services: + auth: + class: phpbb_auth + + cache: + class: phpbb_cache_service + arguments: + - @cache.driver + + cache.driver: + class: %cache.driver.class% + + cache.driver.install: + class: phpbb_cache_driver_file + class_loader: class: phpbb_class_loader arguments: @@ -23,34 +37,6 @@ services: - [register, []] - [set_cache, [@cache.driver]] - cache: - class: phpbb_cache_service - arguments: - - @cache.driver - - cache.driver: - class: %cache.driver.class% - - cache.driver.install: - class: phpbb_cache_driver_file - - dispatcher: - class: phpbb_event_dispatcher - - request: - class: phpbb_request - - user: - class: phpbb_user - - auth: - class: phpbb_auth - - dbal.conn: - class: %dbal.driver.class% - calls: - - [sql_connect, [%dbal.dbhost%, %dbal.dbuser%, %dbal.dbpasswd%, %dbal.dbname%, %dbal.dbport%, false, %dbal.new_link%]] - config: class: phpbb_config_db arguments: @@ -58,6 +44,41 @@ services: - @cache.driver - %tables.config% + cron.task_provider: + class: phpbb_cron_task_provider + arguments: + - @container + + cron.manager: + class: phpbb_cron_manager + arguments: + - @cron.task_provider + - %core.root_path% + - %core.php_ext% + + cron.lock_db: + class: phpbb_lock_db + arguments: + - cron_lock + - @config + - @dbal.conn + + dispatcher: + class: phpbb_event_dispatcher + + dbal.conn: + class: %dbal.driver.class% + calls: + - [sql_connect, [%dbal.dbhost%, %dbal.dbuser%, %dbal.dbpasswd%, %dbal.dbname%, %dbal.dbport%, false, %dbal.new_link%]] + + event.subscriber_loader: + class: phpbb_event_extension_subscriber_loader + arguments: + - @dispatcher + - @ext.manager + calls: + - [load, []] + ext.manager: class: phpbb_extension_manager arguments: @@ -67,6 +88,16 @@ services: - .%core.php_ext% - @cache.driver + processor.config: + class: phpbb_di_processor_ext + arguments: + - @ext.manager + tags: + - { name: container.processor } + + request: + class: phpbb_request + style.resource_locator: class: phpbb_style_resource_locator @@ -100,36 +131,5 @@ services: - @style.path_provider_ext - @template - event.subscriber_loader: - class: phpbb_event_extension_subscriber_loader - arguments: - - @dispatcher - - @ext.manager - calls: - - [load, []] - - cron.task_provider: - class: phpbb_cron_task_provider - arguments: - - @container - - cron.manager: - class: phpbb_cron_manager - arguments: - - @cron.task_provider - - %core.root_path% - - %core.php_ext% - - cron.lock_db: - class: phpbb_lock_db - arguments: - - cron_lock - - @config - - @dbal.conn - - processor.config: - class: phpbb_di_processor_ext - arguments: - - @ext.manager - tags: - - { name: container.processor } + user: + class: phpbb_user From 4feb9aa8d7bda303b62acec924008f75042eb757 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 16:43:41 +0200 Subject: [PATCH 48/63] [feature/dic] Coding style: Braces PHPBB3-10739 --- phpBB/common.php | 3 ++- phpBB/download/file.php | 3 ++- phpBB/includes/cron/task/provider.php | 3 ++- phpBB/includes/di/processor/config.php | 3 ++- phpBB/includes/di/processor/ext.php | 6 ++++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index f958f06ce0..02dad17cf0 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -102,7 +102,8 @@ $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); $ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); -foreach ($ids as $id) { +foreach ($ids as $id) +{ $processor = $phpbb_container->get($id); $processor->process($phpbb_container); } diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 656f1f38d6..8f84d92d07 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -62,7 +62,8 @@ if (isset($_GET['avatar'])) $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); $ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); - foreach ($ids as $id) { + foreach ($ids as $id) + { $processor = $phpbb_container->get($id); $processor->process($phpbb_container); } 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'); } From 4f0f63ae8feb8efc70954e64bdca1f81ae98b212 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 16:51:19 +0200 Subject: [PATCH 49/63] [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(-) 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. From fd9fd71a88fad2b33d75722587dbfc0bd100ae50 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 16:54:30 +0200 Subject: [PATCH 50/63] [feature/dic] Add docblock for cron_manager::wrap_task() PHPBB3-10739 --- phpBB/includes/cron/manager.php | 6 ++++++ 1 file changed, 6 insertions(+) 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); From e103b2f0cc8c8317ce4cb2ca8c4e0e42fca283a2 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 17:04:42 +0200 Subject: [PATCH 51/63] [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(-) 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) From a8425e1f5046c07ad0baaf1cf1acb372d3dc0802 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 17:08:03 +0200 Subject: [PATCH 52/63] [feature/dic] Fix re-ordering of services PHPBB3-10739 --- phpBB/config/services.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index a4e96a3797..84de37c28c 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -98,6 +98,17 @@ services: request: class: phpbb_request + style: + class: phpbb_style + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @user + - @style.resource_locator + - @style.path_provider_ext + - @template + style.resource_locator: class: phpbb_style_resource_locator @@ -120,16 +131,5 @@ services: - @style.resource_locator - @style.path_provider_ext - style: - class: phpbb_style - arguments: - - %core.root_path% - - %core.php_ext% - - @config - - @user - - @style.resource_locator - - @style.path_provider_ext - - @template - user: class: phpbb_user From 919b13460dad9562f877970b8679abdc7b78b07c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 17:08:38 +0200 Subject: [PATCH 53/63] [feature/dic] Update composer.lock to symfony/* RC1 PHPBB3-10739 --- phpBB/composer.lock | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 1d8e6b5f8d..6b0d3584d1 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,21 +1,21 @@ { - "hash": "7024226b03c2abdfa95c76b11c1ec74d", + "hash": "1632798bc1d5298a4f5bd3087c972a9f", "packages": [ { "package": "symfony/config", - "version": "v2.1.0-BETA4" + "version": "v2.1.0-RC1" }, { "package": "symfony/dependency-injection", - "version": "v2.1.0-BETA4" + "version": "v2.1.0-RC1" }, { "package": "symfony/event-dispatcher", - "version": "v2.1.0-BETA4" + "version": "v2.1.0-RC1" }, { "package": "symfony/yaml", - "version": "v2.1.0-BETA4" + "version": "v2.1.0-RC1" } ], "packages-dev": [ @@ -28,40 +28,40 @@ { "package": "fabpot/goutte", "version": "dev-master", - "source-reference": "df14259688c7d6f1d366aa073a589695d2b9f451", - "commit-date": "1343194442" + "source-reference": "6d26279344736f6983a969e46afef082ebf30a67", + "commit-date": "1345141401" }, { "package": "guzzle/common", - "version": "v2.8.1" + "version": "v2.8.4" }, { "package": "guzzle/http", - "version": "v2.8.1" + "version": "v2.8.4" }, { "package": "guzzle/parser", - "version": "v2.8.1" + "version": "v2.8.4" }, { "package": "symfony/browser-kit", - "version": "v2.1.0-BETA4" + "version": "v2.1.0-RC1" }, { "package": "symfony/css-selector", - "version": "v2.1.0-BETA4" + "version": "v2.1.0-RC1" }, { "package": "symfony/dom-crawler", - "version": "v2.1.0-BETA4" + "version": "v2.1.0-RC1" }, { "package": "symfony/finder", - "version": "v2.1.0-BETA4" + "version": "v2.1.0-RC1" }, { "package": "symfony/process", - "version": "v2.1.0-BETA4" + "version": "v2.1.0-RC1" } ], "aliases": [ From c6e522afb6060a9294defe31eafc0130ee3aff15 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 25 Aug 2012 17:16:20 +0200 Subject: [PATCH 54/63] [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(+) 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) From ca62b1ffb0c1f37877fbb59beef7cd38c012b827 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 25 Aug 2012 21:41:04 -0400 Subject: [PATCH 55/63] [feature/add_events] Added note in modify_posting_parameters The template assignment methods do not work until $user->setup() has been run. This event is called before it, so extensions requiring template methods must put such calls in a later event. PHPBB3-9550 --- phpBB/posting.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/posting.php b/phpBB/posting.php index f37d6128de..ff959bb4b7 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -49,6 +49,10 @@ $current_time = time(); * * Note: $refresh must be true to retain previously submitted form data. * +* Note: The template class will not work properly until $user->setup() is +* called, and it has not been called yet. Extensions requiring template +* assignments should use an event that comes later in this file. +* * @event core.modify_posting_parameters * @var int post_id ID of the post * @var int topic_id ID of the topic From 02644c02b9d6bed5e4a8e20323bdafb2ca9749b4 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 26 Aug 2012 15:09:50 -0400 Subject: [PATCH 56/63] [feature/add_events] Added core.posting_modify_template_vars Can be used to set template variables and such, as the template assignment methods are not available to the modify_posting_paramters event. PHPBB3-9550 --- phpBB/posting.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/posting.php b/phpBB/posting.php index ff959bb4b7..81ef31f96c 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1452,6 +1452,14 @@ $template->assign_vars(array( 'S_HIDDEN_FIELDS' => $s_hidden_fields) ); +/** +* This event allows you to modify template variables for the posting screen +* +* @event core.posting_modify_template_vars +* @since 3.1-A1 +*/ +$phpbb_dispatcher->trigger_event('core.posting_modify_template_vars'); + // Build custom bbcodes array display_custom_bbcodes(); From 7cffebbd4997f8a41a871f8ea6fe12dc0abc08c8 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 19 Aug 2012 17:24:38 -0400 Subject: [PATCH 57/63] [task/functional] Added posting tests (reply and new topic) PHPBB-10758 --- tests/functional/posting_test.php | 110 ++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tests/functional/posting_test.php diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php new file mode 100644 index 0000000000..8d722361e0 --- /dev/null +++ b/tests/functional/posting_test.php @@ -0,0 +1,110 @@ +login(); + $this->add_lang('posting'); + + $crawler = $this->request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); + $this->assertContains($this->lang('POST_TOPIC'), $crawler->filter('html')->text()); + + $hidden_fields = array(); + $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }); + + $test_message = 'This is a test topic posted by the testing framework.'; + $form_data = array( + 'subject' => 'Test Topic 1', + 'message' => $test_message, + 'post' => true, + 'f' => 2, + 'mode' => 'post', + 'sid' => $this->sid, + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + // The add_form_key()/check_form_key() safeguards present a challenge because they require + // the timestamp created in add_form_key() to be sent as-is to check_form_key() but in check_form_key() + // it won't allow the current time to be the same as the timestamp it requires. + // As such, automated scripts like this one have to somehow bypass this without being able to change + // the timestamp. The only way I can think to do so is using sleep() + sleep(1); + + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = $this->client->request('POST', 'posting.php', $form_data); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); + $this->assertContains($test_message, $crawler->filter('html')->text()); + } + + public function test_post_reply() + { + $this->login(); + $this->add_lang('posting'); + + $crawler = $this->request('GET', 'posting.php?mode=reply&t=2&f=2&sid=' . $this->sid); + $this->assertContains($this->lang('POST_REPLY'), $crawler->filter('html')->text()); + + $hidden_fields = array(); + $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }); + + $test_message = 'This is a test post posted by the testing framework.'; + $form_data = array( + 'subject' => 'Re: Test Topic 1', + 'message' => $test_message, + 'post' => true, + 't' => 2, + 'f' => 2, + 'mode' => 'reply', + 'sid' => $this->sid, + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // For reasoning behind the following two commands, see the test_post_new_topic() test + $form_data['lastclick'] = 0; + sleep(1); + + // Submit the post + $crawler = $this->client->request('POST', 'posting.php', $form_data); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); + $this->assertContains($test_message, $crawler->filter('html')->text()); + } +} From 7dfe26dd781e7bd0438041058e2a1d95176e7836 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 1 Sep 2012 10:35:46 -0400 Subject: [PATCH 58/63] [task/functional] Allow tests to bypass certain restrictions with DEBUG_TEST PHPBB3-10758 --- phpBB/includes/functions.php | 2 +- phpBB/includes/functions_install.php | 5 ++++- tests/functional/posting_test.php | 10 +--------- 3 files changed, 6 insertions(+), 11 deletions(-) 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 { diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 8d722361e0..f54a3591b2 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -47,13 +47,6 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // is not at least 2 seconds before submission, cancel the form $form_data['lastclick'] = 0; - // The add_form_key()/check_form_key() safeguards present a challenge because they require - // the timestamp created in add_form_key() to be sent as-is to check_form_key() but in check_form_key() - // it won't allow the current time to be the same as the timestamp it requires. - // As such, automated scripts like this one have to somehow bypass this without being able to change - // the timestamp. The only way I can think to do so is using sleep() - sleep(1); - // I use a request because the form submission method does not allow you to send data that is not // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) // Instead, I send it as a request with the submit button "post" set to true. @@ -96,9 +89,8 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case } } - // For reasoning behind the following two commands, see the test_post_new_topic() test + // For reasoning behind the following command, see the test_post_new_topic() test $form_data['lastclick'] = 0; - sleep(1); // Submit the post $crawler = $this->client->request('POST', 'posting.php', $form_data); From 4dd1bbc5879ae5fcae04341a9152e0366ed68bdd Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 1 Sep 2012 10:53:01 -0400 Subject: [PATCH 59/63] [task/functional] Fixed DEBUG_TEST related issues PHPBB3-10758 --- phpBB/includes/functions_install.php | 6 +++++- tests/test_framework/phpbb_functional_test_case.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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; } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 2423299b7c..d35913e415 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -140,7 +140,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->do_request('create_table', $data); $this->do_request('config_file', $data); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true)); + file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true)); $this->do_request('final', $data); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); From ed052290a70ae3a42f9e7c59f3dca95aba0c0ac7 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 17:40:19 +0200 Subject: [PATCH 60/63] [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 diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php old mode 100755 new mode 100644 From 8741bcdaf5bb815a228188b4dfe4e3beebcca3b3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 17:51:27 +0200 Subject: [PATCH 61/63] [ticket/11083] Mark memory cache driver as abstract PHPBB3-11083 --- phpBB/includes/cache/driver/memory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 7ed7b19a1f1c3732b561ec3c8a4a39f115b5e6ac Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 19:12:57 +0200 Subject: [PATCH 62/63] [feature/dic] Remove unneeded newline PHPBB3-10739 --- phpBB/common.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/common.php b/phpBB/common.php index 6ca495a7e3..281eb88c4d 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -86,7 +86,6 @@ require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/db/' . ltrim($dbms, 'dbal_') . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); - // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); From 282a80077d4630ba59043fffe59e8a7ce8619ecb Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 19:17:01 +0200 Subject: [PATCH 63/63] [feature/dic] Spaces to tabs, add useless docblocks Fully documents the constructors of the processors and the cron tasks. PHPBB3-10739 --- .../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 ++ .../includes/cron/task/core/tidy_database.php | 7 ++ phpBB/includes/cron/task/core/tidy_search.php | 10 +++ .../includes/cron/task/core/tidy_sessions.php | 6 ++ .../includes/cron/task/core/tidy_warnings.php | 7 ++ phpBB/includes/di/processor/config.php | 82 +++++++++++-------- phpBB/includes/di/processor/ext.php | 47 +++++++---- phpBB/includes/di/processor/interface.php | 9 +- 11 files changed, 143 insertions(+), 54 deletions(-) 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; + 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; - } + /** + * 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; + } - public function process(ContainerBuilder $container) - { - require $this->config_file; + /** + * @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.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->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); - } + $container->set('container', $container); + } - protected function fix_acm_type($acm_type) - { - if (preg_match('#^[a-z]+$#', $acm_type)) - { - return 'phpbb_cache_driver_'.$acm_type; - } + protected function fix_acm_type($acm_type) + { + if (preg_match('#^[a-z]+$#', $acm_type)) + { + return 'phpbb_cache_driver_'.$acm_type; + } - return $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); }