Skip to content

Commit

Permalink
[feature/extension-manager] Extract extension provider functionality …
Browse files Browse the repository at this point in the history
…from cron

PHPBB3-10323
  • Loading branch information
naderman committed Sep 29, 2011
1 parent 7d16007 commit 6c6a7d7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 49 deletions.
50 changes: 4 additions & 46 deletions phpBB/includes/cron/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,20 @@
*
* @package phpBB3
*/
class phpbb_cron_provider implements IteratorAggregate
class phpbb_cron_provider extends phpbb_extension_provider
{
/**
* 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.
* suffix. Additionally all PHP files in includes/cron/task/core/ are
* tasks.
*
* @return array List of task names
*/
public function find_cron_task_names()
public function find()
{
$finder = $this->extension_manager->get_finder();

Expand All @@ -79,14 +47,4 @@ public function find_cron_task_names()
->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);
}
}
65 changes: 65 additions & 0 deletions phpBB/includes/extension/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
*
* @package extension
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}

/**
* Provides a set of items found in extensions
*
* @package extension
*/
abstract class phpbb_extension_provider implements IteratorAggregate
{
/**
* Array holding all found items
* @var array
*/
protected $items = array();

/**
* An extension manager to search for items in extensions
* @var phpbb_extension_manager
*/
protected $extension_manager;

/**
* Constructor. Loads all available items.
*
* @param phpbb_extension_manager $extension_manager phpBB extension manager
*/
public function __construct(phpbb_extension_manager $extension_manager)
{
$this->extension_manager = $extension_manager;

$this->items = $this->find();
}

/**
* Finds template paths using the extension manager.
*
* @return array List of task names
*/
abstract function find();

/**
* Retrieve an iterator over all items
*
* @return ArrayIterator An iterator for the array of template paths
*/
public function getIterator()
{
return new ArrayIterator($this->items);
}
}
4 changes: 1 addition & 3 deletions tests/cron/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public function setUp()

public function test_manager_finds_shipped_tasks()
{
$task_iterator = $this->provider->find_cron_task_names();

$tasks = array();
foreach ($task_iterator as $task)
foreach ($this->provider as $task)
{
$tasks[] = $task;
}
Expand Down

0 comments on commit 6c6a7d7

Please sign in to comment.