aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2011-08-21 02:57:01 -0400
committerNils Adermann <naderman@naderman.de>2011-09-29 15:42:46 +0200
commit5d5030a48be3d65df85d78e26690085c0889c6e3 (patch)
treea4b0f3dd7f551a5e37503698ee2ac0e52c177300 /phpBB
parent96209e022477d97b581b79cabace4caddd19501b (diff)
downloadforums-5d5030a48be3d65df85d78e26690085c0889c6e3.tar
forums-5d5030a48be3d65df85d78e26690085c0889c6e3.tar.gz
forums-5d5030a48be3d65df85d78e26690085c0889c6e3.tar.bz2
forums-5d5030a48be3d65df85d78e26690085c0889c6e3.tar.xz
forums-5d5030a48be3d65df85d78e26690085c0889c6e3.zip
[feature/extension-manager] Remove cron's dependency on the extension manager.
Instead a separate cron provider supplies the manager with tasks from the extension finder. PHPBB3-10323
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/common.php2
-rw-r--r--phpBB/cron.php2
-rw-r--r--phpBB/includes/cron/manager.php48
-rw-r--r--phpBB/includes/cron/provider.php92
4 files changed, 98 insertions, 46 deletions
diff --git a/phpBB/common.php b/phpBB/common.php
index 61817972f9..3cc9e57e46 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -144,5 +144,5 @@ foreach ($cache->obtain_hooks() as $hook)
if (!$config['use_system_cron'])
{
- $cron = new phpbb_cron_manager($phpbb_extension_manager, $cache->get_driver());
+ $cron = new phpbb_cron_manager(new phpbb_cron_provider($phpbb_extension_manager), $cache->get_driver());
}
diff --git a/phpBB/cron.php b/phpBB/cron.php
index cc5964218a..6633a6c3fd 100644
--- a/phpBB/cron.php
+++ b/phpBB/cron.php
@@ -62,7 +62,7 @@ function do_cron($cron_lock, $run_tasks)
if ($config['use_system_cron'])
{
- $cron = new phpbb_cron_manager($phpbb_root_path . 'includes/cron/task', $phpEx, $cache->get_driver());
+ $cron = new phpbb_cron_manager(new phpbb_cron_provider($phpbb_extension_manager), $cache->get_driver());
}
else
{
diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php
index ae48e233e0..a0bf018b33 100644
--- a/phpBB/includes/cron/manager.php
+++ b/phpBB/includes/cron/manager.php
@@ -33,64 +33,24 @@ class phpbb_cron_manager
protected $tasks = array();
/**
- * An extension manager to search for cron tasks in extensions.
- * @var phpbb_extension_manager
- */
- protected $extension_manager;
-
- /**
* Constructor. Loads all available tasks.
*
- * Tasks will be looked up in the core task directory located in
- * includes/cron/task/core/ and in extensions. Task classes will be
- * autoloaded and must be named according to autoloading naming conventions.
- *
- * Tasks in extensions must 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.
- *
- * @param phpbb_extension_manager $extension_manager phpBB extension manager
+ * @param array|Traversable $task_names Provides an iterable set of task names
*/
- public function __construct(phpbb_extension_manager $extension_manager)
+ public function __construct($task_names)
{
- $this->extension_manager = $extension_manager;
-
- $task_names = $this->find_cron_task_names();
$this->load_tasks($task_names);
}
/**
- * 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.
- *
- * @return array List of task names
- */
- public function find_cron_task_names()
- {
- $finder = $this->extension_manager->get_finder();
-
- return $finder
- ->suffix('_task')
- ->directory('/cron')
- ->default_path('includes/cron/task/core/')
- ->default_suffix('')
- ->default_directory('')
- ->get_classes();
- }
-
- /**
* Loads tasks given by name, wraps them
* and puts them into $this->tasks.
*
- * @param array $task_names Array of strings
+ * @param array|Traversable $task_names Array of strings
*
* @return void
*/
- public function load_tasks(array $task_names)
+ public function load_tasks($task_names)
{
foreach ($task_names as $task_name)
{
diff --git a/phpBB/includes/cron/provider.php b/phpBB/includes/cron/provider.php
new file mode 100644
index 0000000000..9936da3f55
--- /dev/null
+++ b/phpBB/includes/cron/provider.php
@@ -0,0 +1,92 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Provides cron manager with tasks
+*
+* Finds installed cron tasks and makes them available to the cron manager.
+*
+* @package phpBB3
+*/
+class phpbb_cron_provider implements \IteratorAggregate
+{
+ /**
+ * Array holding all found task class names.
+ *
+ * @var array
+ */
+ protected $task_names = array();
+
+ /**
+ * An extension manager to search for cron tasks in extensions.
+ * @var phpbb_extension_manager
+ */
+ protected $extension_manager;
+
+ /**
+ * Constructor. Loads all available tasks.
+ *
+ * Tasks will be looked up in the core task directory located in
+ * includes/cron/task/core/ and in extensions. Task classes will be
+ * autoloaded and must be named according to autoloading naming conventions.
+ *
+ * Tasks in extensions must 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.
+ *
+ * @param phpbb_extension_manager $extension_manager phpBB extension manager
+ */
+ public function __construct(phpbb_extension_manager $extension_manager)
+ {
+ $this->extension_manager = $extension_manager;
+
+ $this->task_names = $this->find_cron_task_names();
+ }
+
+ /**
+ * 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.
+ *
+ * @return array List of task names
+ */
+ public function find_cron_task_names()
+ {
+ $finder = $this->extension_manager->get_finder();
+
+ return $finder
+ ->suffix('_task')
+ ->directory('/cron')
+ ->default_path('includes/cron/task/core/')
+ ->default_suffix('')
+ ->default_directory('')
+ ->get_classes();
+ }
+
+ /**
+ * Retrieve an iterator over all task names
+ *
+ * @return ArrayIterator An iterator for the array of task names
+ */
+ public function getIterator()
+ {
+ return new ArrayIterator($this->task_names);
+ }
+}