Renamed entities (added Entity to the end of class name)

This commit is contained in:
Alex Bilbie 2014-05-02 15:12:00 +01:00
parent e5315dc016
commit bdd2bc322c
7 changed files with 77 additions and 77 deletions

View File

@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
/** /**
* Abstract token class * Abstract token class
*/ */
abstract class AbstractToken abstract class AbstractTokenEntity
{ {
/** /**
* Access token ID * Access token ID
@ -30,7 +30,7 @@ abstract class AbstractToken
/** /**
* Associated session * Associated session
* @var \League\OAuth2\Server\Session * @var \League\OAuth2\Server\SessionEntity
*/ */
protected $session; protected $session;
@ -48,7 +48,7 @@ abstract class AbstractToken
/** /**
* Authorization or resource server * Authorization or resource server
* @var \League\OAuth2\Server\Authorization|\League\OAuth2\Server\Resource * @var \League\OAuth2\Server\AbstractServer
*/ */
protected $server; protected $server;
@ -65,29 +65,15 @@ abstract class AbstractToken
/** /**
* Set session * Set session
* @param \League\OAuth2\Server\Session $session * @param \League\OAuth2\Server\SessionEntity $session
* @return self * @return self
*/ */
public function setSession(Session $session) public function setSession(SessionEntity $session)
{ {
$this->session = $session; $this->session = $session;
return $this; return $this;
} }
/**
* Get session
* @return \League\OAuth2\Server\Session
*/
public function getSession()
{
if ($this->session instanceof Session) {
return $this->session;
}
$this->session = $this->server->getStorage('session')->getByAccessToken($this->token);
return $this->session;
}
/** /**
* Set the expire time of the token * Set the expire time of the token
* @param integer $expireTime Unix time stamp * @param integer $expireTime Unix time stamp
@ -130,10 +116,10 @@ abstract class AbstractToken
/** /**
* Associate a scope * Associate a scope
* @param \League\OAuth2\Server\Entity\Scope $scope * @param \League\OAuth2\Server\Entity\ScopeEntity $scope
* @return self * @return self
*/ */
public function associateScope(Scope $scope) public function associateScope(ScopeEntity $scope)
{ {
if (!isset($this->scopes[$scope->getId()])) { if (!isset($this->scopes[$scope->getId()])) {
$this->scopes[$scope->getId()] = $scope; $this->scopes[$scope->getId()] = $scope;
@ -142,35 +128,6 @@ abstract class AbstractToken
return $this; return $this;
} }
/**
* Check if access token has an associated scope
* @param string $scope Scope to check
* @return bool
*/
public function hasScope($scope)
{
if ($this->scopes === null) {
$this->getScopes();
}
return isset($this->scopes[$scope]);
}
/**
* Return all scopes associated with the session
* @return array Array of \League\OAuth2\Server\Entity\Scope
*/
public function getScopes()
{
if ($this->scopes === null) {
$this->scopes = $this->formatScopes(
$this->server->getStorage('access_token')->getScopes($this)
);
}
return $this->scopes;
}
/** /**
* Format the local scopes array * Format the local scopes array
* @param array $unformatted Array of \League\OAuth2\Server\Entity\Scope * @param array $unformatted Array of \League\OAuth2\Server\Entity\Scope
@ -180,7 +137,7 @@ abstract class AbstractToken
{ {
$scopes = []; $scopes = [];
foreach ($unformatted as $scope) { foreach ($unformatted as $scope) {
if ($scope instanceof Scope) { if ($scope instanceof ScopeEntity) {
$scopes[$scope->getId()] = $scope; $scopes[$scope->getId()] = $scope;
} }
} }

View File

@ -20,8 +20,51 @@ use Symfony\Component\HttpFoundation\ParameterBag;
/** /**
* Access token entity class * Access token entity class
*/ */
class AccessToken extends AbstractToken class AccessTokenEntity extends AbstractTokenEntity
{ {
/**
* Get session
* @return \League\OAuth2\Server\SessionEntity
*/
public function getSession()
{
if ($this->session instanceof SessionEntity) {
return $this->session;
}
$this->session = $this->server->getStorage('session')->getByAccessToken($this);
return $this->session;
}
/**
* Check if access token has an associated scope
* @param string $scope Scope to check
* @return bool
*/
public function hasScope($scope)
{
if ($this->scopes === null) {
$this->getScopes();
}
return isset($this->scopes[$scope]);
}
/**
* Return all scopes associated with the session
* @return array Array of \League\OAuth2\Server\Entity\Scope
*/
public function getScopes()
{
if ($this->scopes === null) {
$this->scopes = $this->formatScopes(
$this->server->getStorage('access_token')->getScopes($this)
);
}
return $this->scopes;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
/** /**
* Access token entity class * Access token entity class
*/ */
class AuthCode extends AbstractToken class AuthCodeEntity extends AbstractTokenEntity
{ {
/** /**
* Redirect URI * Redirect URI
@ -49,7 +49,7 @@ class AuthCode extends AbstractToken
} }
/** /**
* [generateRedirectUri description] * Generate a redirect URI
* @param string $state The state parameter if set by the client * @param string $state The state parameter if set by the client
* @param string $queryDelimeter The query delimiter ('?' for auth code grant, '#' for implicit grant) * @param string $queryDelimeter The query delimiter ('?' for auth code grant, '#' for implicit grant)
* @return string * @return string
@ -69,11 +69,11 @@ class AuthCode extends AbstractToken
*/ */
public function getSession() public function getSession()
{ {
if ($this->session instanceof Session) { if ($this->session instanceof SessionEntity) {
return $this->session; return $this->session;
} }
$this->session = $this->server->getStorage('session')->getByAuthCode($this->token); $this->session = $this->server->getStorage('session')->getByAuthCode($this);
return $this->session; return $this->session;
} }

View File

@ -17,7 +17,7 @@ use League\OAuth2\Server\AbstractServer;
/** /**
* Client entity class * Client entity class
*/ */
class Client class ClientEntity
{ {
/** /**
* Client identifier * Client identifier

View File

@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
/** /**
* Refresh token entity class * Refresh token entity class
*/ */
class RefreshToken extends AbstractToken class RefreshTokenEntity extends AbstractTokenEntity
{ {
/** /**
* Access token associated to refresh token * Access token associated to refresh token
@ -30,10 +30,10 @@ class RefreshToken extends AbstractToken
/** /**
* Associate an access token * Associate an access token
* @param \League\OAuth2\Server\Entity\AccessToken $accessToken * @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
* @return self * @return self
*/ */
public function setAccessToken(AccessToken $accessToken) public function setAccessToken(AccessTokenEntity $accessToken)
{ {
$this->accessToken = $accessToken; $this->accessToken = $accessToken;
return $this; return $this;
@ -45,7 +45,7 @@ class RefreshToken extends AbstractToken
*/ */
public function getAccessToken() public function getAccessToken()
{ {
if (! $this->accessToken instanceof AccessToken) { if (! $this->accessToken instanceof AccessTokenEntity) {
$this->accessToken = $this->server->getStorage('access_token')->getByRefreshToken($this); $this->accessToken = $this->server->getStorage('access_token')->getByRefreshToken($this);
} }
return $this->accessToken; return $this->accessToken;

View File

@ -17,7 +17,7 @@ use League\OAuth2\Server\AbstractServer;
/** /**
* Scope entity class * Scope entity class
*/ */
class Scope class ScopeEntity
{ {
/** /**
* Scope identifier * Scope identifier
@ -33,7 +33,7 @@ class Scope
/** /**
* Authorization or resource server * Authorization or resource server
* @var \League\OAuth2\Server\Authorization|\League\OAuth2\Server\Resource * @var \League\OAuth2\Server\AbstractServer
*/ */
protected $server; protected $server;

View File

@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
/** /**
* Session entity grant * Session entity grant
*/ */
class Session class SessionEntity
{ {
/** /**
* Session identifier * Session identifier
@ -48,19 +48,19 @@ class Session
/** /**
* Auth code * Auth code
* @var \League\OAuth2\Server\Entity\AuthCode * @var \League\OAuth2\Server\Entity\AuthCodeEntity
*/ */
protected $authCode; protected $authCode;
/** /**
* Access token * Access token
* @var \League\OAuth2\Server\Entity\AccessToken * @var \League\OAuth2\Server\Entity\AccessTokenEntity
*/ */
protected $accessToken; protected $accessToken;
/** /**
* Refresh token * Refresh token
* @var \League\OAuth2\Server\Entity\RefreshToken * @var \League\OAuth2\Server\Entity\RefreshTokenEntity
*/ */
protected $refreshToken; protected $refreshToken;
@ -109,10 +109,10 @@ class Session
/** /**
* Associate a scope * Associate a scope
* @param \League\OAuth2\Server\Entity\Scope $scope * @param \League\OAuth2\Server\Entity\ScopeEntity $scope
* @return self * @return self
*/ */
public function associateScope(Scope $scope) public function associateScope(ScopeEntity $scope)
{ {
if (!isset($this->scopes[$scope->getId()])) { if (!isset($this->scopes[$scope->getId()])) {
$this->scopes[$scope->getId()] = $scope; $this->scopes[$scope->getId()] = $scope;
@ -158,7 +158,7 @@ class Session
$scopes = []; $scopes = [];
if (is_array($unformated)) { if (is_array($unformated)) {
foreach ($unformated as $scope) { foreach ($unformated as $scope) {
if ($scope instanceof Scope) { if ($scope instanceof ScopeEntity) {
$scopes[$scope->getId()] = $scope; $scopes[$scope->getId()] = $scope;
} }
} }
@ -168,10 +168,10 @@ class Session
/** /**
* Associate an access token with the session * Associate an access token with the session
* @param \League\OAuth2\Server\Entity\AccessToken $accessToken * @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
* @return self * @return self
*/ */
public function associateAccessToken(AccessToken $accessToken) public function associateAccessToken(AccessTokenEntity $accessToken)
{ {
$this->accessToken = $accessToken; $this->accessToken = $accessToken;
return $this; return $this;
@ -179,10 +179,10 @@ class Session
/** /**
* Associate a refresh token with the session * Associate a refresh token with the session
* @param \League\OAuth2\Server\Entity\RefreshToken $refreshToken * @param \League\OAuth2\Server\Entity\RefreshTokenEntity $refreshToken
* @return self * @return self
*/ */
public function associateRefreshToken(RefreshToken $refreshToken) public function associateRefreshToken(RefreshTokenEntity $refreshToken)
{ {
$this->refreshToken = $refreshToken; $this->refreshToken = $refreshToken;
return $this; return $this;
@ -190,10 +190,10 @@ class Session
/** /**
* Associate a client with the session * Associate a client with the session
* @param League\OAuth2\Server\Entity\Client $client The client * @param League\OAuth2\Server\Entity\ClientEntity $client The client
* @return self * @return self
*/ */
public function associateClient(Client $client) public function associateClient(ClientEntity $client)
{ {
$this->client = $client; $this->client = $client;
return $this; return $this;
@ -205,7 +205,7 @@ class Session
*/ */
public function getClient() public function getClient()
{ {
if ($this->client instanceof Client) { if ($this->client instanceof ClientEntity) {
return $this->client; return $this->client;
} }