Skip to content

Commit 0a8de27

Browse files
authored
Merge pull request #5 from JimChenWYU/master
Support Laravel 6
2 parents 9c25bfa + fb8cd29 commit 0a8de27

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

.github/workflows/ci.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
on: [push, pull_request]
3+
4+
jobs:
5+
php_cs_fixer:
6+
name: PHP-CS-Fxier
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
php_version:
12+
- 7.4
13+
perfer:
14+
- stable
15+
container:
16+
image: nauxliu/php-ci-image:${{ matrix.php_version }}
17+
steps:
18+
- uses: actions/checkout@master
19+
- name: Install Dependencies
20+
run: composer install --prefer-dist --no-interaction --no-suggest
21+
- name: Run PHP-CS-Fxier
22+
run: composer check-style
23+
24+
phpunit:
25+
name: phpunit
26+
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
php_version:
31+
- 7.2
32+
- 7.3
33+
- 7.4
34+
perfer:
35+
- stable
36+
container:
37+
image: nauxliu/php-ci-image:${{ matrix.php_version }}
38+
steps:
39+
- uses: actions/checkout@master
40+
- name: Install Dependencies
41+
run: composer install --prefer-dist --no-interaction --no-suggest
42+
- name: Run PHPUnit
43+
run: ./vendor/bin/phpunit
44+
45+
L6_test:
46+
name: L6_test
47+
runs-on: ubuntu-latest
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
php_version:
52+
- 7.4
53+
perfer:
54+
- stable
55+
container:
56+
image: nauxliu/php-ci-image:${{ matrix.php_version }}
57+
steps:
58+
- uses: actions/checkout@master
59+
- name: Install laravel/framework:^6.0
60+
run: composer require "laravel/framework:^6.0"
61+
- name: Install Dependencies
62+
run: composer install --prefer-dist --no-interaction --no-suggest
63+
- name: Laravel Version
64+
run: cat vendor/laravel/framework/src/Illuminate/Foundation/Application.php | grep "const VERSION"
65+
- name: Run PHPUnit
66+
run: composer test

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
}
1010
],
1111
"require": {
12-
"laravel/framework": "^7.14|^8.0",
12+
"laravel/framework": "^6.20|^7.14|^8.0",
1313
"laravel/passport": "^9.2|^10.0"
1414
},
1515
"require-dev": {
1616
"brainmaestro/composer-git-hooks": "^2.7",
1717
"friendsofphp/php-cs-fixer": "^2.15",
18-
"orchestra/testbench": "^5.3",
18+
"orchestra/testbench": "^4.16|^5.3",
1919
"mockery/mockery": "^1.0",
20-
"phpunit/phpunit": "^9.0"
20+
"phpunit/phpunit": "^8.0|^9.0"
2121
},
2222
"autoload": {
2323
"psr-4": {

src/CacheTokenRepository.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@ class CacheTokenRepository extends TokenRepository
2525
*/
2626
protected $cacheTags;
2727

28+
/**
29+
* @var string
30+
*/
31+
protected $cacheStore;
32+
2833
/**
2934
* @param string $cacheKey
3035
* @param int $expiresInSeconds
3136
* @param array $tags
3237
*/
33-
public function __construct(string $cacheKey = null, int $expiresInSeconds = null, array $tags = [])
38+
public function __construct(string $cacheKey = null, int $expiresInSeconds = null, array $tags = [], ?string $store = null)
3439
{
3540
$this->cacheKey = $cacheKey ?? 'passport_token_';
3641
$this->expiresInSeconds = $expiresInSeconds ?? 5 * 60;
3742
$this->cacheTags = $tags;
43+
$this->cacheStore = $store ?? \config('cache.default');
3844
}
3945

4046
/**
@@ -46,7 +52,7 @@ public function __construct(string $cacheKey = null, int $expiresInSeconds = nul
4652
*/
4753
public function find($id)
4854
{
49-
return Cache::remember($this->cacheKey . $id, \now()->addSeconds($this->expiresInSeconds), function () use ($id) {
55+
return Cache::store($this->cacheStore)->remember($this->cacheKey . $id, \now()->addSeconds($this->expiresInSeconds), function () use ($id) {
5056
return Passport::token()->where('id', $id)->first();
5157
});
5258
}
@@ -61,7 +67,7 @@ public function find($id)
6167
*/
6268
public function findForUser($id, $userId)
6369
{
64-
return Cache::remember($this->cacheKey . $id, \now()->addSeconds($this->expiresInSeconds), function () use ($id, $userId) {
70+
return Cache::store($this->cacheStore)->remember($this->cacheKey . $id, \now()->addSeconds($this->expiresInSeconds), function () use ($id, $userId) {
6571
return Passport::token()->where('id', $id)->where('user_id', $userId)->first();
6672
});
6773
}
@@ -75,7 +81,7 @@ public function findForUser($id, $userId)
7581
*/
7682
public function forUser($userId): Collection
7783
{
78-
return Cache::remember($this->cacheKey . $userId, \now()->addSeconds($this->expiresInSeconds), function () use ($userId) {
84+
return Cache::store($this->cacheStore)->remember($this->cacheKey . $userId, \now()->addSeconds($this->expiresInSeconds), function () use ($userId) {
7985
return Passport::token()->where('user_id', $userId)->get();
8086
});
8187
}
@@ -90,7 +96,7 @@ public function forUser($userId): Collection
9096
*/
9197
public function getValidToken($user, $client)
9298
{
93-
return Cache::remember($this->cacheKey . $user->getKey(), \now()->addSeconds($this->expiresInSeconds), function () use ($client, $user) {
99+
return Cache::store($this->cacheStore)->remember($this->cacheKey . $user->getKey(), \now()->addSeconds($this->expiresInSeconds), function () use ($client, $user) {
94100
return $client->tokens()
95101
->whereUserId($user->getKey())
96102
->where('revoked', 0)

src/CacheTokenServiceProvider.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public function register()
1313
return new CacheTokenRepository(
1414
\config('passport.cache.prefix'),
1515
\config('passport.cache.expires_in'),
16-
\config('passport.cache.tags', [])
16+
\config('passport.cache.tags', []),
17+
\config('passport.cache.store', \config('cache.default'))
1718
);
1819
});
1920
}

0 commit comments

Comments
 (0)