aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/common.php56
-rw-r--r--phpBB/composer.json12
-rw-r--r--phpBB/composer.lock45
-rw-r--r--phpBB/config/.htaccess4
-rw-r--r--phpBB/config/cron_tasks.yml72
-rw-r--r--phpBB/config/parameters.yml12
-rw-r--r--phpBB/config/services.yml127
-rw-r--r--phpBB/cron.php4
-rw-r--r--phpBB/download/file.php39
-rw-r--r--phpBB/includes/cache/factory.php42
-rw-r--r--phpBB/includes/cron/manager.php43
-rw-r--r--phpBB/includes/cron/task/base.php22
-rw-r--r--phpBB/includes/cron/task/core/prune_all_forums.php25
-rw-r--r--phpBB/includes/cron/task/core/prune_forum.php44
-rw-r--r--phpBB/includes/cron/task/core/queue.php18
-rw-r--r--phpBB/includes/cron/task/core/tidy_cache.php17
-rw-r--r--phpBB/includes/cron/task/core/tidy_database.php15
-rw-r--r--phpBB/includes/cron/task/core/tidy_search.php24
-rw-r--r--phpBB/includes/cron/task/core/tidy_sessions.php14
-rw-r--r--phpBB/includes/cron/task/core/tidy_warnings.php18
-rw-r--r--phpBB/includes/cron/task/provider.php42
-rw-r--r--phpBB/includes/cron/task/task.php7
-rw-r--r--phpBB/includes/cron/task/wrapper.php20
-rw-r--r--phpBB/install/index.php25
-rw-r--r--phpBB/viewforum.php8
25 files changed, 480 insertions, 275 deletions
diff --git a/phpBB/common.php b/phpBB/common.php
index 81fe275008..a69b26c006 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);
@@ -85,50 +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');
+$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);
+
// 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();
+$phpbb_class_loader = $phpbb_container->get('class_loader');
+$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext');
// 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 = $phpbb_container->get('cache');
// 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 = $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
-// 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 = $phpbb_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());
-
-// 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_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator);
-$phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template);
+$phpbb_extension_manager = $phpbb_container->get('ext.manager');
+$phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader');
-$phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager);
-$phpbb_subscriber_loader->load();
+$template = $phpbb_container->get('template');
+$phpbb_style = $phpbb_container->get('style');
// Add own hook handler
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
@@ -141,5 +137,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 = $phpbb_container->get('cron.manager');
}
diff --git a/phpBB/composer.json b/phpBB/composer.json
index 5340fb85f2..366aea2ac3 100644
--- a/phpBB/composer.json
+++ b/phpBB/composer.json
@@ -1,8 +1,12 @@
{
- "minimum-stability": "beta",
- "require": {
- "symfony/event-dispatcher": "2.1.*"
- },
+ "minimum-stability": "beta",
+ "require": {
+ "symfony/config": "2.0.*",
+ "symfony/dependency-injection": "2.0.*",
+ "symfony/event-dispatcher": "2.1.*",
+ "symfony/event-dispatcher": "2.0.*",
+ "symfony/yaml": "2.0.*"
+ },
"require-dev": {
"fabpot/goutte": "1.0.x-dev"
}
diff --git a/phpBB/composer.lock b/phpBB/composer.lock
index 99e19554ab..f3187749f5 100644
--- a/phpBB/composer.lock
+++ b/phpBB/composer.lock
@@ -1,49 +1,24 @@
{
- "hash": "b2daff7465c71d924e915e72454ac266",
+ "hash": "e4f5efe460878599e6fed6bb13584cfd",
"packages": [
{
- "package": "symfony/event-dispatcher",
- "version": "v2.1.0-BETA3"
- }
- ],
- "packages-dev": [
- {
- "package": "fabpot/goutte",
- "version": "dev-master",
- "alias-pretty-version": "1.0.x-dev",
- "alias-version": "1.0.9999999.9999999-dev"
+ "package": "symfony/config",
+ "version": "v2.0.16"
},
{
- "package": "fabpot/goutte",
- "version": "dev-master",
- "source-reference": "c2ea8d9a6682d14482e57ede2371001b8a5238d2",
- "commit-date": "1340264258"
+ "package": "symfony/dependency-injection",
+ "version": "v2.0.16"
},
{
- "package": "guzzle/guzzle",
- "version": "v2.6.6"
- },
- {
- "package": "symfony/browser-kit",
- "version": "v2.1.0-BETA3"
- },
- {
- "package": "symfony/css-selector",
- "version": "v2.1.0-BETA3"
- },
- {
- "package": "symfony/dom-crawler",
- "version": "v2.1.0-BETA3"
- },
- {
- "package": "symfony/finder",
- "version": "v2.1.0-BETA3"
+ "package": "symfony/event-dispatcher",
+ "version": "v2.0.16"
},
{
- "package": "symfony/process",
- "version": "v2.1.0-BETA3"
+ "package": "symfony/yaml",
+ "version": "v2.0.16"
}
],
+ "packages-dev": null,
"aliases": [
],
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 @@
+<Files *>
+ Order Allow,Deny
+ Deny from All
+</Files> \ No newline at end of file
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/parameters.yml b/phpBB/config/parameters.yml
new file mode 100644
index 0000000000..3c24382fc4
--- /dev/null
+++ b/phpBB/config/parameters.yml
@@ -0,0 +1,12 @@
+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
new file mode 100644
index 0000000000..0141641aaf
--- /dev/null
+++ b/phpBB/config/services.yml
@@ -0,0 +1,127 @@
+imports:
+ - { resource: cron_tasks.yml }
+
+services:
+ class_loader:
+ class: phpbb_class_loader
+ arguments:
+ - phpbb_
+ - %core.root_path%includes/
+ - .%core.php_ext%
+ calls:
+ - [register, []]
+ - [set_cache, [@cache.driver]]
+
+ class_loader.ext:
+ class: phpbb_class_loader
+ arguments:
+ - phpbb_ext_
+ - %core.root_path%ext/
+ - .%core.php_ext%
+ calls:
+ - [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:
+ - @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_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
+ 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
diff --git a/phpBB/cron.php b/phpBB/cron.php
index 36b771f1b7..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 = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver());
+ $cron = $phpbb_container->get('cron.manager');
}
else
{
@@ -71,7 +71,7 @@ else
output_image();
}
-$cron_lock = new phpbb_lock_db('cron_lock', $config, $db);
+$cron_lock = $phpbb_container->get('cron.lock_db');
if ($cron_lock->acquire())
{
if ($config['use_system_cron'])
diff --git a/phpBB/download/file.php b/phpBB/download/file.php
index c01b0789de..7213e3ac3f 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,24 @@ 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");
- $phpbb_class_loader_ext->register();
- $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx");
- $phpbb_class_loader->register();
+ $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_class_loader = $phpbb_container->get('class_loader');
+ $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext');
// 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 = $phpbb_container->get('cache');
- $phpbb_dispatcher = new phpbb_event_dispatcher();
- $request = new phpbb_request();
- $db = new $sql_db();
+ $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))
@@ -69,18 +72,16 @@ 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 = $phpbb_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 = $phpbb_container->get('ext.manager');
+ $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader');
- $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager);
- $phpbb_subscriber_loader->load();
+ // worst-case default
+ $browser = strtolower($request->header('User-Agent', 'msie 6.0'));
$filename = request_var('avatar', '');
$avatar_group = false;
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 @@
-<?php
-/**
-*
-* @package acm
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* @package acm
-*/
-class phpbb_cache_factory
-{
- private $acm_type;
-
- public function __construct($acm_type)
- {
- $this->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;
- }
-}
diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php
index 7a78a1b054..5ea909eb2c 100644
--- a/phpBB/includes/cron/manager.php
+++ b/phpBB/includes/cron/manager.php
@@ -32,31 +32,34 @@ class phpbb_cron_manager
*/
protected $tasks = array();
+ protected $phpbb_root_path, $phpEx;
+
/**
* 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, $phpbb_root_path, $phpEx)
{
- $this->load_tasks($task_names);
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->phpEx = $phpEx;
+
+ $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;
+ $this->tasks[] = $this->wrap_task($task);
}
}
@@ -121,26 +124,8 @@ 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)
+ public function wrap_task(phpbb_cron_task $task)
{
- $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;
+ 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/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..6adac77eb8 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\TaggedContainerInterface;
+
/**
* Provides cron manager with tasks
*
@@ -22,27 +24,35 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
-class phpbb_cron_task_provider extends phpbb_extension_provider
+class phpbb_cron_task_provider implements IteratorAggregate
{
+ private $container;
+
+ public function __construct(TaggedContainerInterface $container)
+ {
+ $this->container = $container;
+ }
+
/**
- * Finds cron task names using the extension manager.
- *
- * All PHP files in includes/cron/task/core/ are considered tasks. Tasks
- * in extensions have to be located in a directory called cron or a subdir
- * of a directory called cron. The class and filename must end in a _task
- * suffix. Additionally all PHP files in includes/cron/task/core/ are
- * tasks.
+ * Retrieve an iterator over all items
*
- * @return array List of task names
+ * @return ArrayIterator An iterator for the array of cron tasks
*/
- protected function find()
+ public function getIterator()
{
- $finder = $this->extension_manager->get_finder();
+ $definitions = $this->container->findTaggedServiceIds('cron.task');
+
+ $tasks = array();
+ foreach ($definitions as $name => $definition)
+ {
+ $task = $this->container->get($name);
+ if ($task instanceof phpbb_cron_task_base) {
+ $task->set_name($name);
+ }
+
+ $tasks[] = $task;
+ }
- return $finder
- ->extension_suffix('_task')
- ->extension_directory('/cron')
- ->core_path('includes/cron/task/core/')
- ->get_classes();
+ 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
@@ -22,6 +22,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.
*
* @return void
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;
}
/**
@@ -62,16 +66,6 @@ class phpbb_cron_task_wrapper
}
/**
- * 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.
*
* When system cron is not in use, running a cron task is accomplished
@@ -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/install/index.php b/phpBB/install/index.php
index f992b67bb7..88745b8bb9 100644
--- a/phpBB/install/index.php
+++ b/phpBB/install/index.php
@@ -79,19 +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);
-$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();
+$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->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');
// 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 = $phpbb_container->get('cache');
-$phpbb_dispatcher = new phpbb_event_dispatcher();
-$request = new phpbb_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 18d247f0b6..22dc00716a 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -193,8 +193,12 @@ 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);
- if ($task && $task->is_ready())
+ $cron = $phpbb_container->get('cron.manager');
+
+ $task = $cron->find_task('cron.task.core.prune_forum');
+ $task->set_forum_data($forum_data);
+
+ if ($task->is_ready())
{
$url = $task->get_url();
$template->assign_var('RUN_CRON_TASK', '<img src="' . $url . '" width="1" height="1" alt="cron" />');