cache[$token])) { $this->cache[$token] = OauthAccessToken::findOne($token); } return $this->cache[$token]; } /** * @inheritdoc */ public function get($token) { $model = $this->getTokenModel($token); if ($model === null) { return null; } return (new AccessTokenEntity($this->server))->hydrate([ 'id' => $model->access_token, 'expireTime' => $model->expire_time, 'sessionId' => $model->session_id, ]); } /** * @inheritdoc */ public function getScopes(OriginalAccessTokenEntity $token) { $entities = []; foreach($this->getTokenModel($token->getId())->getScopes() as $scope) { $entities[] = (new ScopeEntity($this->server))->hydrate(['id' => $scope]); } return $entities; } /** * @inheritdoc */ public function create($token, $expireTime, $sessionId) { $model = new OauthAccessToken([ 'access_token' => $token, 'expire_time' => $expireTime, 'session_id' => $sessionId, ]); if (!$model->save()) { throw new Exception('Cannot save ' . OauthAccessToken::class . ' model.'); } } /** * @inheritdoc */ public function associateScope(OriginalAccessTokenEntity $token, ScopeEntity $scope) { $this->getTokenModel($token->getId())->getScopes()->add($scope->getId()); } /** * @inheritdoc */ public function delete(OriginalAccessTokenEntity $token) { $this->getTokenModel($token->getId())->delete(); } }