Skip to content

Commit

Permalink
Merge pull request #5 from JimChenWYU/master
Browse files Browse the repository at this point in the history
Support Laravel 6
  • Loading branch information
overtrue authored Mar 18, 2021
2 parents 9c25bfa + fb8cd29 commit 0a8de27
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 9 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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: phpunit
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: L6_test
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: Laravel Version
run: cat vendor/laravel/framework/src/Illuminate/Foundation/Application.php | grep "const VERSION"
- name: Run PHPUnit
run: composer test
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
}
],
"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"
"phpunit/phpunit": "^8.0|^9.0"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 11 additions & 5 deletions src/CacheTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = null)
{
$this->cacheKey = $cacheKey ?? 'passport_token_';
$this->expiresInSeconds = $expiresInSeconds ?? 5 * 60;
$this->cacheTags = $tags;
$this->cacheStore = $store ?? \config('cache.default');
}

/**
Expand All @@ -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();
});
}
Expand All @@ -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();
});
}
Expand All @@ -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();
});
}
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/CacheTokenServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
);
});
}
Expand Down

0 comments on commit 0a8de27

Please sign in to comment.