1 | <?php |
||
16 | class Item extends AbstractItem |
||
17 | { |
||
18 | /** |
||
19 | * The time the object expires at |
||
20 | * |
||
21 | * @var \DateTime |
||
22 | * @since __DEPLOY_VERSION__ |
||
23 | */ |
||
24 | private $expiration; |
||
25 | |||
26 | /** |
||
27 | * The key for the cache item. |
||
28 | * |
||
29 | * @var string |
||
30 | * @since 1.0 |
||
31 | */ |
||
32 | private $key; |
||
33 | |||
34 | /** |
||
35 | * The value of the cache item. |
||
36 | * |
||
37 | * @var mixed |
||
38 | * @since 1.0 |
||
39 | */ |
||
40 | private $value; |
||
41 | |||
42 | /** |
||
43 | * Whether the cache item has been hit. |
||
44 | * |
||
45 | * @var boolean |
||
46 | * @since 1.0 |
||
47 | */ |
||
48 | private $hit = false; |
||
49 | |||
50 | /** |
||
51 | * Class constructor. |
||
52 | * |
||
53 | * @param string $key The key for the cache item. |
||
54 | * @param \DateTime|integer|null $ttl The expiry time for the cache item in seconds or as a datetime object |
||
55 | * |
||
56 | * @since 1.0 |
||
57 | */ |
||
58 | 1 | public function __construct($key, $ttl = null) |
|
59 | { |
||
60 | 1 | $this->key = $key; |
|
61 | |||
62 | 1 | if (is_int($ttl)) |
|
63 | 1 | { |
|
64 | $this->expiresAfter($ttl); |
||
65 | } |
||
66 | 1 | elseif ($ttl instanceof \DateTime) |
|
67 | { |
||
68 | $this->expiresAt($ttl); |
||
|
|||
69 | } |
||
70 | else |
||
71 | { |
||
72 | 1 | $this->expiresAfter(900); |
|
73 | } |
||
74 | 1 | } |
|
75 | |||
76 | /** |
||
77 | * Confirms if the cache item exists in the cache. |
||
78 | * |
||
79 | * Note: This method MAY avoid retrieving the cached value for performance |
||
80 | * reasons, which could result in a race condition between exists() and get(). |
||
81 | * To avoid that potential race condition use isHit() instead. |
||
82 | * |
||
83 | * @return boolean |
||
84 | * |
||
85 | * @since __DEPLOY_VERSION__ |
||
86 | */ |
||
87 | public function exists() |
||
91 | |||
92 | /** |
||
93 | * Returns the key for the current cache item. |
||
94 | * |
||
95 | * @return string The key string for this cache item. |
||
96 | * |
||
97 | * @since 1.0 |
||
98 | */ |
||
99 | 1 | public function getKey() |
|
103 | |||
104 | /** |
||
105 | * Retrieves the value of the item from the cache associated with this object's key. |
||
106 | * |
||
107 | * @return mixed The value corresponding to this cache item's key, or null if not found. |
||
108 | * |
||
109 | * @since 1.0 |
||
110 | */ |
||
111 | 1 | public function get() |
|
115 | |||
116 | /** |
||
117 | * Sets the value represented by this cache item. |
||
118 | * |
||
119 | * If the value is set, we are assuming that there was a valid hit on the cache for the given key. |
||
120 | * |
||
121 | * @param mixed $value The serializable value to be stored. |
||
122 | * |
||
123 | * @return $this |
||
124 | * |
||
125 | * @since 1.0 |
||
126 | */ |
||
127 | 1 | public function set($value) |
|
134 | |||
135 | /** |
||
136 | * Confirms if the cache item lookup resulted in a cache hit. |
||
137 | * |
||
138 | * @return boolean |
||
139 | * |
||
140 | * @since 1.0 |
||
141 | */ |
||
142 | 1 | public function isHit() |
|
146 | |||
147 | /** |
||
148 | * Sets the expiration time for this cache item. |
||
149 | * |
||
150 | * @param \DateTimeInterface $expiration The point in time after which the item MUST be considered expired. |
||
151 | * If null is passed explicitly, a default value MAY be used. If none is |
||
152 | * set, the value should be stored permanently or for as long as the |
||
153 | * implementation allows. |
||
154 | * |
||
155 | * @return $this |
||
156 | * |
||
157 | * @since __DEPLOY_VERSION__ |
||
158 | */ |
||
159 | public function expiresAt($expiration) |
||
165 | |||
166 | /** |
||
167 | * Sets the expiration time for this cache item. |
||
168 | * |
||
169 | * @param int|\DateInterval $time The period of time from the present after which the item MUST be considered |
||
170 | * expired. An integer parameter is understood to be the time in seconds until |
||
171 | * expiration. |
||
172 | * |
||
173 | * @return $this |
||
174 | * |
||
175 | * @since __DEPLOY_VERSION__ |
||
176 | */ |
||
177 | 1 | public function expiresAfter($time) |
|
195 | |||
196 | /** |
||
197 | * Returns the expiration time of a not-yet-expired cache item. |
||
198 | * |
||
199 | * If this cache item is a Cache Miss, this method MAY return the time at which the item expired or the current time if that is not available. |
||
200 | * |
||
201 | * @return \DateTime The timestamp at which this cache item will expire. |
||
202 | * |
||
203 | * @since __DEPLOY_VERSION__ |
||
204 | */ |
||
205 | public function getExpiration() |
||
209 | } |
||
210 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: