1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
/** |
4
|
|
|
* This file is part of GitterBot package. |
5
|
|
|
* |
6
|
|
|
* @author Serafim <[email protected]> |
7
|
|
|
* @date 03.03.2016 15:08 |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
namespace Core\Doctrine; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
use Doctrine\Common\Cache\Cache; |
18
|
|
|
use Illuminate\Cache\CacheManager; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class LaravelDoctrineCache |
22
|
|
|
* @package Core\Doctrine |
23
|
|
|
*/ |
24
|
|
|
class CacheBridge implements Cache |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var \Illuminate\Contracts\Cache\Repository |
28
|
|
|
*/ |
29
|
|
|
protected $driver; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* LaravelDoctrineCache constructor. |
33
|
|
|
* @param CacheManager $cache |
34
|
|
|
*/ |
35
|
|
|
public function __construct(CacheManager $cache) |
36
|
|
|
{ |
37
|
|
|
$this->driver = $cache; |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Fetches an entry from the cache. |
42
|
|
|
* |
43
|
|
|
* @param string $id The id of the cache entry to fetch. |
44
|
|
|
* |
45
|
|
|
* @return mixed The cached data or FALSE, if no cache entry exists for the given id. |
46
|
|
|
*/ |
47
|
|
|
public function fetch($id) |
48
|
|
|
{ |
49
|
|
|
return $this->driver->get($id, false); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Tests if an entry exists in the cache. |
54
|
|
|
* |
55
|
|
|
* @param string $id The cache id of the entry to check for. |
56
|
|
|
* |
57
|
|
|
* @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise. |
58
|
|
|
*/ |
59
|
|
|
public function contains($id) |
60
|
|
|
{ |
61
|
|
|
return $this->driver->has($id); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Puts data into the cache. |
66
|
|
|
* |
67
|
|
|
* @param string $id The cache id. |
68
|
|
|
* @param mixed $data The cache entry/data. |
69
|
|
|
* @param int $lifeTime The cache lifetime. |
70
|
|
|
* If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime). |
71
|
|
|
* |
72
|
|
|
* @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise. |
73
|
|
|
*/ |
74
|
|
|
public function save($id, $data, $lifeTime = 0) |
75
|
|
|
{ |
76
|
|
|
$lifeTime = max(0, $lifeTime); |
77
|
|
|
|
78
|
|
|
return $lifeTime |
79
|
|
|
? $this->driver->add($id, $data, $lifeTime) |
80
|
|
|
: $this->driver->forever($id, $data); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Deletes a cache entry. |
85
|
|
|
* |
86
|
|
|
* @param string $id The cache id. |
87
|
|
|
* |
88
|
|
|
* @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise. |
89
|
|
|
*/ |
90
|
|
|
public function delete($id) |
91
|
|
|
{ |
92
|
|
|
return $this->driver->get($id); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Retrieves cached information from the data store. |
97
|
|
|
* |
98
|
|
|
* The server's statistics array has the following values: |
99
|
|
|
* |
100
|
|
|
* - <b>hits</b> |
101
|
|
|
* Number of keys that have been requested and found present. |
102
|
|
|
* |
103
|
|
|
* - <b>misses</b> |
104
|
|
|
* Number of items that have been requested and not found. |
105
|
|
|
* |
106
|
|
|
* - <b>uptime</b> |
107
|
|
|
* Time that the server is running. |
108
|
|
|
* |
109
|
|
|
* - <b>memory_usage</b> |
110
|
|
|
* Memory used by this server to store items. |
111
|
|
|
* |
112
|
|
|
* - <b>memory_available</b> |
113
|
|
|
* Memory allowed to use for storage. |
114
|
|
|
* |
115
|
|
|
* @since 2.2 |
116
|
|
|
* |
117
|
|
|
* @return array|null An associative array with server's statistics if available, NULL otherwise. |
118
|
|
|
*/ |
119
|
|
|
public function getStats() |
120
|
|
|
{ |
121
|
|
|
return null; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..