|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of jwt-auth |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Sean Tymon <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Tymon\JWTAuth\Providers\Storage; |
|
13
|
|
|
|
|
14
|
|
|
use Tymon\JWTAuth\Contracts\Providers\Storage; |
|
15
|
|
|
use Illuminate\Contracts\Cache\Repository as CacheContract; |
|
16
|
|
|
|
|
17
|
|
|
class Illuminate implements Storage |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Illuminate\Contracts\Cache\Repository |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $cache; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $tag = 'tymon.jwt'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var boolean |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $supportsTags; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param \Illuminate\Contracts\Cache\Repository $cache |
|
36
|
|
|
*/ |
|
37
|
20 |
|
public function __construct(CacheContract $cache) |
|
38
|
|
|
{ |
|
39
|
20 |
|
$this->cache = $cache; |
|
40
|
20 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Add a new item into storage |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $key |
|
46
|
|
|
* @param mixed $value |
|
47
|
|
|
* @param int $minutes |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
4 |
|
public function add($key, $value, $minutes) |
|
52
|
|
|
{ |
|
53
|
4 |
|
$this->cache()->put($key, $value, $minutes); |
|
54
|
4 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Add a new item into storage forever |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $key |
|
60
|
|
|
* @param mixed $value |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
4 |
|
public function forever($key, $value) |
|
65
|
|
|
{ |
|
66
|
4 |
|
$this->cache()->forever($key, $value); |
|
67
|
4 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get an item from storage |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $key |
|
73
|
|
|
* |
|
74
|
|
|
* @return mixed |
|
75
|
|
|
*/ |
|
76
|
4 |
|
public function get($key) |
|
77
|
|
|
{ |
|
78
|
4 |
|
return $this->cache()->get($key); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Remove an item from storage |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $key |
|
85
|
|
|
* |
|
86
|
|
|
* @return boolean |
|
87
|
|
|
*/ |
|
88
|
4 |
|
public function destroy($key) |
|
89
|
|
|
{ |
|
90
|
4 |
|
return $this->cache()->forget($key); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Remove all items associated with the tag |
|
95
|
|
|
* |
|
96
|
|
|
* @return void |
|
97
|
|
|
*/ |
|
98
|
4 |
|
public function flush() |
|
99
|
|
|
{ |
|
100
|
4 |
|
$this->cache()->flush(); |
|
101
|
4 |
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Return the cache instance with tags attached |
|
105
|
|
|
* |
|
106
|
|
|
* @return \Illuminate\Contracts\Cache\Repository |
|
107
|
|
|
*/ |
|
108
|
20 |
|
protected function cache() |
|
109
|
|
|
{ |
|
110
|
20 |
|
if (is_null($this->supportsTags)) { |
|
111
|
10 |
|
$this->determineTagSupport(); |
|
112
|
10 |
|
} |
|
113
|
|
|
|
|
114
|
20 |
|
if ($this->supportsTags) { |
|
115
|
10 |
|
return $this->cache->tags($this->tag); |
|
116
|
|
|
} else { |
|
117
|
10 |
|
return $this->cache; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Detect as best we can whether tags are supported with this repository & store, |
|
123
|
|
|
* and save our result on the $supportsTags flag. |
|
124
|
|
|
* |
|
125
|
|
|
* @return void |
|
126
|
|
|
*/ |
|
127
|
10 |
|
protected function determineTagSupport() |
|
128
|
|
|
{ |
|
129
|
10 |
|
if (method_exists($this->cache, 'tags')) { // Laravel >= 5.1.28 |
|
130
|
|
|
try { |
|
131
|
|
|
// Attempt the repository tags command, which throws exceptions when unsupported |
|
132
|
|
|
$this->cache->tags($this->tag); |
|
|
|
|
|
|
133
|
|
|
$this->supportsTags = true; |
|
134
|
|
|
} catch (\BadMethodCallException $ex) { |
|
135
|
|
|
$this->supportsTags = false; |
|
136
|
|
|
} |
|
137
|
|
|
} else { |
|
138
|
10 |
|
if (method_exists($this->cache, 'getStore')) { // Laravel <= 5.1.27 |
|
139
|
|
|
// Check for the tags function directly on the store |
|
140
|
|
|
$this->supportsTags = method_exists($this->cache->getStore(), 'tags'); |
|
|
|
|
|
|
141
|
|
|
} else { |
|
142
|
|
|
// Must be using custom cache repository without getStore(), and all bets are off, |
|
143
|
|
|
// or we are mocking the cache contract (in testing), which will not create a getStore method |
|
144
|
10 |
|
$this->supportsTags = false; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
10 |
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.