Skip to content

Commit

Permalink
Make this class have a default implementation.
Browse files Browse the repository at this point in the history
Passing a callback that returns a user's backup data allows for on-demand fetching of user data too.
  • Loading branch information
yunosh committed May 5, 2017
1 parent cd4bc97 commit c6a89a3
Showing 1 changed file with 50 additions and 6 deletions.
56 changes: 50 additions & 6 deletions framework/Backup/lib/Horde/Backup/Users.php
Expand Up @@ -13,6 +13,8 @@

namespace Horde\Backup;

use Iterator;

/**
* An application's list of users with backup data.
*
Expand All @@ -25,31 +27,73 @@
* @license http://www.horde.org/licenses/bsd BSD
* @package Backup
*/
abstract class Users implements Iterator
class Users implements Iterator
{
/**
* The user list.
*
* @var Iterator
*/
protected $_users;

/**
* User creation callback.
*
* @var callback
*/
protected $_getUser;

/**
* Constructor.
*
* @param Iterator $users A user list.
* @param callable $getUser Callback to create a \Horde\Backup\User
* instance.
*/
public function __construct(Iterator $users, callable $getUser)
{
$this->_users = $users;
$this->_getUser = $getUser;
}

/**
* A single user's backup data.
*
* @return \Horde\Backup\User
*/
abstract public function current();
public function current()
{
return call_user_func($this->_getUser, $this->key());
}

/**
* A user name.
*
* @return string
*/
abstract public function key();
public function key()
{
return $this->_users->current();
}

/**
*/
abstract public function next();
public function next()
{
$this->_users->next();
}

/**
*/
abstract public function rewind();
public function rewind()
{
$this->_users->rewind();
}

/**
*/
abstract public function valid();
public function valid()
{
return $this->_users->valid();
}
}

0 comments on commit c6a89a3

Please sign in to comment.