* @license PHP License * @package WB * @subpackage content */ WBClass::load( 'WBLog' ); /** * User * * * * @version 0.1.0 * @package WB * @subpackage content */ abstract class WBUser_Storage extends WBStdClass { /** * id of loaded user, if any * @var string */ protected $id = null; /** * user data of loaded user * @var array */ protected $data = array(); /** * user's group list * @var array */ protected $group = array(); /** * logger * @var WBLog */ protected $log; /** * constructor * * */ public function __construct() { $this->log = WBLog::start(__CLASS__); } /** * find user * * Allow to find user by id, nickname or email address * * @see isAuthenticated() * @param array anything find user * @return string|null either the user id on success, or null */ abstract public function find($data); /** * Unload current user data * * * @see login() * @return bool - always true */ public function clear() { if (!$this->id) { return true; } $log = array( 'action' => 'clear', 'id' => $this->id ); // log out $this->id = null; $this->data = null; $this->group = null; $this->log->notice($log); return true; } /** * load user and automatically log in * * This is like the "su" command * * @param string $id user's id * @return true on success, false otherwise */ abstract public function load($id); /** * Populate object with preloaded user data * * @param string $id * @param array $data * @param array $group */ public function populate($id, $data, $group) { $this->id = $id; $this->data = $data; $this->group = $group; } /** * fetch user id, if loaded * * @return string */ public function getId() { return $this->id; } /** * receive current user's data * * Get user's primary data or null if not found * * @param string $id optional user id * @return array|null */ public function get($id = null) { if ($id && !$this->load($id)) { return null; } return $this->data; } /** * get group list * * Get groups user is member of * * @param $id * @return array */ public function getGroup($id = null) { if ($id && !$this->load($id)) { return null; } if (is_array($this->group)) { $this->loadGroup(); } return $this->group; } /** * load group data * */ protected function loadGroup() { $this->group = array(); } /** * update user data * * store changed user data in session and table * * @param array $data * @return string $id on success, null otherwise */ abstract public function set($data, $new = false); /** * save group membership * * @param array $groupIds */ abstract public function setGroups($groupIds); } ?>