From bee283ea22392b61f39a5e9ac505a70b5704acf7 Mon Sep 17 00:00:00 2001 From: qbhy <96qbhy@gmail.com> Date: Thu, 11 Jun 2020 10:09:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=BD=E8=B1=A1AccessToken?= =?UTF-8?q?=E7=B1=BB=E8=8E=B7=E5=8F=96http=E5=AE=9E=E4=BE=8B=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AbstractAccessToken.php | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/AbstractAccessToken.php b/src/AbstractAccessToken.php index c958fbd..7591119 100644 --- a/src/AbstractAccessToken.php +++ b/src/AbstractAccessToken.php @@ -61,6 +61,11 @@ abstract class AbstractAccessToken */ protected $http; + /** + * @var Foundation + */ + protected $app; + /** * Token string. * @@ -69,8 +74,17 @@ abstract class AbstractAccessToken protected $token; /** - * @param mixed $token - * @param int $expires + * AbstractAccessToken constructor. + * @param Foundation $app + */ + public function __construct(Foundation $app) + { + $this->app = $app; + } + + /** + * @param mixed $token + * @param int $expires * @return $this */ public function setToken($token, $expires = 86400) @@ -87,7 +101,7 @@ public function setToken($token, $expires = 86400) /** * Get token from cache. * - * @param bool $forceRefresh + * @param bool $forceRefresh * * @return string */ @@ -128,7 +142,7 @@ abstract public function getTokenFromServer(); abstract public function checkTokenResponse($result); /** - * @param mixed $appId + * @param mixed $appId */ public function setAppId($appId) { @@ -144,7 +158,7 @@ public function getAppId() } /** - * @param string $secret + * @param string $secret */ public function setSecret($secret) { @@ -162,7 +176,7 @@ public function getSecret() /** * Set cache instance. * - * @param \Doctrine\Common\Cache\Cache $cache + * @param \Doctrine\Common\Cache\Cache $cache * * @return AbstractAccessToken */ @@ -204,13 +218,13 @@ public function getCacheKey() */ public function getHttp() { - return $this->http ?: $this->http = new Http(); + return $this->http ?? $this->app->http; } /** * Set the http instance. * - * @param Http $http + * @param Http $http * * @return $this */