From 4dfe65b2e45d965e6e6b6994cb8a9532c305d039 Mon Sep 17 00:00:00 2001 From: JimChen Date: Mon, 15 Mar 2021 20:24:20 +0800 Subject: [PATCH 1/7] Support Laravel 6 --- .github/workflows/ci.yml | 64 ++++++++++++++++++++++++++++++++++++++++ composer.json | 4 +-- 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f11e35d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: CI +on: [push, pull_request] + +jobs: + php_cs_fixer: + name: PHP-CS-Fxier + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php_version: + - 7.4 + perfer: + - stable + container: + image: nauxliu/php-ci-image:${{ matrix.php_version }} + steps: + - uses: actions/checkout@master + - name: Install Dependencies + run: composer install --prefer-dist --no-interaction --no-suggest + - name: Run PHP-CS-Fxier + run: composer check-style + + phpunit: + name: PHP-${{ matrix.php_version }}-${{ matrix.perfer }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php_version: + - 7.2 + - 7.3 + - 7.4 + perfer: + - stable + container: + image: nauxliu/php-ci-image:${{ matrix.php_version }} + steps: + - uses: actions/checkout@master + - name: Install Dependencies + run: composer install --prefer-dist --no-interaction --no-suggest + - name: Run PHPUnit + run: ./vendor/bin/phpunit + + L6_test: + name: PHP-${{ matrix.php_version }}-${{ matrix.perfer }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php_version: + - 7.4 + perfer: + - stable + container: + image: nauxliu/php-ci-image:${{ matrix.php_version }} + steps: + - uses: actions/checkout@master + - name: Install laravel/framework:^6.0 + run: composer require "laravel/framework:^6.0" + - name: Install Dependencies + run: composer install --prefer-dist --no-interaction --no-suggest + - name: Run PHPUnit + run: composer test diff --git a/composer.json b/composer.json index 189a435..52e6134 100644 --- a/composer.json +++ b/composer.json @@ -9,13 +9,13 @@ } ], "require": { - "laravel/framework": "^7.14|^8.0", + "laravel/framework": "^6.20|^7.14|^8.0", "laravel/passport": "^9.2|^10.0" }, "require-dev": { "brainmaestro/composer-git-hooks": "^2.7", "friendsofphp/php-cs-fixer": "^2.15", - "orchestra/testbench": "^5.3", + "orchestra/testbench": "^4.16|^5.3", "mockery/mockery": "^1.0", "phpunit/phpunit": "^9.0" }, From 455de6e744e59076b954b2cd3c3fe85a3ce3317c Mon Sep 17 00:00:00 2001 From: JimChen Date: Mon, 15 Mar 2021 20:30:36 +0800 Subject: [PATCH 2/7] Fixed ci --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 52e6134..e4929a8 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "friendsofphp/php-cs-fixer": "^2.15", "orchestra/testbench": "^4.16|^5.3", "mockery/mockery": "^1.0", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^8.0|^9.0" }, "autoload": { "psr-4": { From c4cfbf0d3f48cac23aad789cde1d18eb868e546b Mon Sep 17 00:00:00 2001 From: JimChen Date: Mon, 15 Mar 2021 20:31:59 +0800 Subject: [PATCH 3/7] Update ci job name --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f11e35d..84c74d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: run: composer check-style phpunit: - name: PHP-${{ matrix.php_version }}-${{ matrix.perfer }} + name: phpunit runs-on: ubuntu-latest strategy: fail-fast: false @@ -43,7 +43,7 @@ jobs: run: ./vendor/bin/phpunit L6_test: - name: PHP-${{ matrix.php_version }}-${{ matrix.perfer }} + name: L6_test runs-on: ubuntu-latest strategy: fail-fast: false From 600836844818ba4865a22d2a2c7477e6d0380cdc Mon Sep 17 00:00:00 2001 From: JimChen Date: Mon, 15 Mar 2021 20:38:38 +0800 Subject: [PATCH 4/7] Update ci job --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84c74d1..302632b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,5 +60,7 @@ jobs: run: composer require "laravel/framework:^6.0" - name: Install Dependencies run: composer install --prefer-dist --no-interaction --no-suggest + - name: Laravel Version + run: php artisan list | grep "Laravel Framework" - name: Run PHPUnit run: composer test From e6c9d28298519829416826064a910ad99d6d28a7 Mon Sep 17 00:00:00 2001 From: JimChen Date: Mon, 15 Mar 2021 20:43:10 +0800 Subject: [PATCH 5/7] Update ci job --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 302632b..687ccf8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,6 +61,6 @@ jobs: - name: Install Dependencies run: composer install --prefer-dist --no-interaction --no-suggest - name: Laravel Version - run: php artisan list | grep "Laravel Framework" + run: cat vendor/laravel/framework/src/Illuminate/Foundation/Application.php | grep "const VERSION" - name: Run PHPUnit run: composer test From 424449e857aaf0210eaad29f9aee85106160e332 Mon Sep 17 00:00:00 2001 From: JimChen Date: Thu, 18 Mar 2021 09:46:53 +0800 Subject: [PATCH 6/7] =?UTF-8?q?update:=20=E6=8F=90=E4=BE=9BCache=20Store?= =?UTF-8?q?=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CacheTokenRepository.php | 16 +++++++++++----- src/CacheTokenServiceProvider.php | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/CacheTokenRepository.php b/src/CacheTokenRepository.php index f357323..f0c20f0 100644 --- a/src/CacheTokenRepository.php +++ b/src/CacheTokenRepository.php @@ -25,16 +25,22 @@ class CacheTokenRepository extends TokenRepository */ protected $cacheTags; + /** + * @var string + */ + protected $cacheStore; + /** * @param string $cacheKey * @param int $expiresInSeconds * @param array $tags */ - public function __construct(string $cacheKey = null, int $expiresInSeconds = null, array $tags = []) + public function __construct(string $cacheKey = null, int $expiresInSeconds = null, array $tags = [], string $store = 'file') { $this->cacheKey = $cacheKey ?? 'passport_token_'; $this->expiresInSeconds = $expiresInSeconds ?? 5 * 60; $this->cacheTags = $tags; + $this->cacheStore = $store; } /** @@ -46,7 +52,7 @@ public function __construct(string $cacheKey = null, int $expiresInSeconds = nul */ public function find($id) { - return Cache::remember($this->cacheKey . $id, \now()->addSeconds($this->expiresInSeconds), function () use ($id) { + return Cache::store($this->cacheStore)->remember($this->cacheKey . $id, \now()->addSeconds($this->expiresInSeconds), function () use ($id) { return Passport::token()->where('id', $id)->first(); }); } @@ -61,7 +67,7 @@ public function find($id) */ public function findForUser($id, $userId) { - return Cache::remember($this->cacheKey . $id, \now()->addSeconds($this->expiresInSeconds), function () use ($id, $userId) { + return Cache::store($this->cacheStore)->remember($this->cacheKey . $id, \now()->addSeconds($this->expiresInSeconds), function () use ($id, $userId) { return Passport::token()->where('id', $id)->where('user_id', $userId)->first(); }); } @@ -75,7 +81,7 @@ public function findForUser($id, $userId) */ public function forUser($userId): Collection { - return Cache::remember($this->cacheKey . $userId, \now()->addSeconds($this->expiresInSeconds), function () use ($userId) { + return Cache::store($this->cacheStore)->remember($this->cacheKey . $userId, \now()->addSeconds($this->expiresInSeconds), function () use ($userId) { return Passport::token()->where('user_id', $userId)->get(); }); } @@ -90,7 +96,7 @@ public function forUser($userId): Collection */ public function getValidToken($user, $client) { - return Cache::remember($this->cacheKey . $user->getKey(), \now()->addSeconds($this->expiresInSeconds), function () use ($client, $user) { + return Cache::store($this->cacheStore)->remember($this->cacheKey . $user->getKey(), \now()->addSeconds($this->expiresInSeconds), function () use ($client, $user) { return $client->tokens() ->whereUserId($user->getKey()) ->where('revoked', 0) diff --git a/src/CacheTokenServiceProvider.php b/src/CacheTokenServiceProvider.php index 1534b95..e226e35 100644 --- a/src/CacheTokenServiceProvider.php +++ b/src/CacheTokenServiceProvider.php @@ -13,7 +13,8 @@ public function register() return new CacheTokenRepository( \config('passport.cache.prefix'), \config('passport.cache.expires_in'), - \config('passport.cache.tags', []) + \config('passport.cache.tags', []), + \config('passport.cache.store', \config('cache.default')) ); }); } From fb8cd29bae6088fa1f9be610fb6f38e324954882 Mon Sep 17 00:00:00 2001 From: JimChen Date: Thu, 18 Mar 2021 09:49:40 +0800 Subject: [PATCH 7/7] =?UTF-8?q?update:=20=E5=85=BC=E5=AE=B9=E5=8D=87?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CacheTokenRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CacheTokenRepository.php b/src/CacheTokenRepository.php index f0c20f0..cfeb4a5 100644 --- a/src/CacheTokenRepository.php +++ b/src/CacheTokenRepository.php @@ -35,12 +35,12 @@ class CacheTokenRepository extends TokenRepository * @param int $expiresInSeconds * @param array $tags */ - public function __construct(string $cacheKey = null, int $expiresInSeconds = null, array $tags = [], string $store = 'file') + public function __construct(string $cacheKey = null, int $expiresInSeconds = null, array $tags = [], ?string $store = null) { $this->cacheKey = $cacheKey ?? 'passport_token_'; $this->expiresInSeconds = $expiresInSeconds ?? 5 * 60; $this->cacheTags = $tags; - $this->cacheStore = $store; + $this->cacheStore = $store ?? \config('cache.default'); } /**