Skip to content

Commit

Permalink
Fix indentation. Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Reynis committed Jun 5, 2019
1 parent 7a78d5f commit 8f8c199
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,48 @@ $authStrategy = new JsonAuthStrategy(
To avoid requesting a token everytime php runs, you can pass to `JwtManager` an implementation of `TokenPersistenceInterface`.
By default `NullTokenPersistence` will be used.

### Simpe cache adapter (PSR-16)

If you have any [PSR-16 compatible cache](https://www.php-fig.org/psr/psr-16/), you can use it as a persistence handler:

```php
<?php

use Eljam\GuzzleJwt\Persistence\SimpleCacheTokenPersistence;
use Psr\SimpleCache\CacheInterface;

/**
* @var CacheInterface
*/
$psr16cache;

$authStrategy = new SimpleCacheTokenPersistence($psr16cache);
```

Optionnally you can specify the TTL and cache key used:

```php
<?php

use Eljam\GuzzleJwt\Persistence\SimpleCacheTokenPersistence;
use Psr\SimpleCache\CacheInterface;

/**
* @var CacheInterface
*/
$psr16cache;

$ttl = 1800;
$cacheKey = 'myUniqueKey';

$authStrategy = new SimpleCacheTokenPersistence($psr16cache, $ttl, $cacheKey);
```


### Custom persistence

You may create you own persistence handler by implementing the `TokenPersistenceInterface`:

```php
namespace App\Jwt\Persistence;

Expand Down
9 changes: 5 additions & 4 deletions Tests/Persistence/TokenPersistenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public function testSimpleCacheTokenPersistence()

$this->assertTrue($tokenPersistence->hasToken());
$this->assertEquals($tokenPersistence->restoreToken()->getToken(), $token->getToken());

$tokenPersistence->deleteToken();

$this->assertFalse($tokenPersistence->hasToken());

$tokenPersistence->deleteToken();

$this->assertFalse($tokenPersistence->hasToken());
$this->assertNull($tokenPersistence->restoreToken());
}
}

0 comments on commit 8f8c199

Please sign in to comment.