aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/cron/provider.php
blob: ee0f93a308d59d9aadba95965fcdbae441586183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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);
	}
}