1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[feature/dic] Rewrite cron system to use DIC

PHPBB3-10739
This commit is contained in:
Igor Wiedler
2012-04-09 00:22:55 +02:00
parent 9165a045c5
commit 2e76620c88
16 changed files with 257 additions and 165 deletions

View File

@@ -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;
}
}