|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Framgia\Jwt\Storage; |
|
4
|
|
|
|
|
5
|
|
|
use Framgia\Jwt\Contracts\Storage; |
|
6
|
|
|
use Illuminate\Contracts\Cache\Repository; |
|
7
|
|
|
|
|
8
|
|
|
class CacheStorage implements Storage |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var \Illuminate\Contracts\Cache\Repository|\Illuminate\Contracts\Cache\Store |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $cache; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $tag; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param \Illuminate\Cache\CacheManager $cache |
|
22
|
|
|
* @param string $tag |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(Repository $cache, $tag = 'jwt') |
|
25
|
|
|
{ |
|
26
|
|
|
$this->cache = $cache; |
|
27
|
|
|
$this->tag = $tag; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Add a new item into storage. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $key |
|
34
|
|
|
* @param mixed $value |
|
35
|
|
|
* @param int $minutes |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
|
|
public function add($key, $value, $minutes) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->cache()->put($key, $value, $minutes); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $key |
|
45
|
|
|
* @param mixed $value |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function forever($key, $value) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->cache()->forever($key, $value); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Check whether a key exists in storage. |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $key |
|
57
|
|
|
* @return bool |
|
58
|
|
|
*/ |
|
59
|
|
|
public function has($key) |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->cache()->has($key); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Remove an item from storage. |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $key |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
|
|
public function destroy($key) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->cache()->forget($key); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Remove all items associated with the tag. |
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
|
|
public function flush() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->cache()->flush(); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Return the cache instance with tags attached. |
|
87
|
|
|
* |
|
88
|
|
|
* @return \Illuminate\Contracts\Cache\Repository|\Illuminate\Contracts\Cache\Store |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function cache() |
|
91
|
|
|
{ |
|
92
|
|
|
if (! method_exists($this->cache, 'tags')) { |
|
93
|
|
|
return $this->cache; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $this->cache->tags($this->tag); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: