Skip to content

Commit

Permalink
Added support for getting all properties on an authed user
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Mar 13, 2015
1 parent 7fc07ff commit 75dbd79
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Auth/AuthedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public function __construct(
$username = null, $userId = 0, array $properties = []
)
{
$this->_data['userId'] = $userId;
$this->_data['userId'] = $userId;
$this->_data['username'] = $username;
$this->_data['data'] = $properties;
$this->_data['data'] = $properties;
}

protected function _getData($key, $default = null)
Expand Down Expand Up @@ -55,12 +55,30 @@ public function getProperty($key, $default = null)
return isset($data[$key]) ? $data[$key] : $default;
}

/**
* Set a cached property on the authed user
*
* @param $key
* @param $value
*
* @return $this
*/
public function setProperty($key, $value)
{
$this->_data['data'][$key] = $value;
return $this;
}

/**
* Get all cached properties
*
* @return array
*/
public function getProperties()
{
return (array)$this->_data;
}

/**
* @return string Serialized representation of the authed user
*/
Expand All @@ -81,7 +99,7 @@ public function unserialize($data)
$json = json_decode($data);
if(json_last_error() === JSON_ERROR_NONE)
{
$this->_data = (array)$json;
$this->_data = (array)$json;
$this->_data['data'] = ValueAs::arr($this->_data['data'], []);
}
else
Expand Down
7 changes: 7 additions & 0 deletions src/Auth/IAuthedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public function getUsername();
*/
public function getProperty($key, $default = null);

/**
* Get all cached properties
*
* @return array
*/
public function getProperties();

/**
* @return string Serialized representation of the authed user
*/
Expand Down

0 comments on commit 75dbd79

Please sign in to comment.