@@ -10,7 +10,7 @@ |
||
10 | 10 | * @return Number the event which this module handles |
11 | 11 | */ |
12 | 12 | public function getEvents() { |
13 | - return OBJECT_DELETE | OBJECT_SAVE; |
|
13 | + return OBJECT_DELETE|OBJECT_SAVE; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
@@ -4,111 +4,111 @@ |
||
4 | 4 | |
5 | 5 | interface CacheInterface |
6 | 6 | { |
7 | - /** |
|
8 | - * Fetches a value from the cache. |
|
9 | - * |
|
10 | - * @param string $key The unique key of this item in the cache. |
|
11 | - * @param mixed $default Default value to return if the key does not exist. |
|
12 | - * |
|
13 | - * @return mixed The value of the item from the cache, or $default in case of cache miss. |
|
14 | - * |
|
15 | - * @throws \Psr\SimpleCache\InvalidArgumentException |
|
16 | - * MUST be thrown if the $key string is not a legal value. |
|
17 | - */ |
|
18 | - public function get($key, $default = null); |
|
7 | + /** |
|
8 | + * Fetches a value from the cache. |
|
9 | + * |
|
10 | + * @param string $key The unique key of this item in the cache. |
|
11 | + * @param mixed $default Default value to return if the key does not exist. |
|
12 | + * |
|
13 | + * @return mixed The value of the item from the cache, or $default in case of cache miss. |
|
14 | + * |
|
15 | + * @throws \Psr\SimpleCache\InvalidArgumentException |
|
16 | + * MUST be thrown if the $key string is not a legal value. |
|
17 | + */ |
|
18 | + public function get($key, $default = null); |
|
19 | 19 | |
20 | - /** |
|
21 | - * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
|
22 | - * |
|
23 | - * @param string $key The key of the item to store. |
|
24 | - * @param mixed $value The value of the item to store, must be serializable. |
|
25 | - * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
|
26 | - * the driver supports TTL then the library may set a default value |
|
27 | - * for it or let the driver take care of that. |
|
28 | - * |
|
29 | - * @return bool True on success and false on failure. |
|
30 | - * |
|
31 | - * @throws \Psr\SimpleCache\InvalidArgumentException |
|
32 | - * MUST be thrown if the $key string is not a legal value. |
|
33 | - */ |
|
34 | - public function set($key, $value, $ttl = null); |
|
20 | + /** |
|
21 | + * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
|
22 | + * |
|
23 | + * @param string $key The key of the item to store. |
|
24 | + * @param mixed $value The value of the item to store, must be serializable. |
|
25 | + * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
|
26 | + * the driver supports TTL then the library may set a default value |
|
27 | + * for it or let the driver take care of that. |
|
28 | + * |
|
29 | + * @return bool True on success and false on failure. |
|
30 | + * |
|
31 | + * @throws \Psr\SimpleCache\InvalidArgumentException |
|
32 | + * MUST be thrown if the $key string is not a legal value. |
|
33 | + */ |
|
34 | + public function set($key, $value, $ttl = null); |
|
35 | 35 | |
36 | - /** |
|
37 | - * Delete an item from the cache by its unique key. |
|
38 | - * |
|
39 | - * @param string $key The unique cache key of the item to delete. |
|
40 | - * |
|
41 | - * @return bool True if the item was successfully removed. False if there was an error. |
|
42 | - * |
|
43 | - * @throws \Psr\SimpleCache\InvalidArgumentException |
|
44 | - * MUST be thrown if the $key string is not a legal value. |
|
45 | - */ |
|
46 | - public function delete($key); |
|
36 | + /** |
|
37 | + * Delete an item from the cache by its unique key. |
|
38 | + * |
|
39 | + * @param string $key The unique cache key of the item to delete. |
|
40 | + * |
|
41 | + * @return bool True if the item was successfully removed. False if there was an error. |
|
42 | + * |
|
43 | + * @throws \Psr\SimpleCache\InvalidArgumentException |
|
44 | + * MUST be thrown if the $key string is not a legal value. |
|
45 | + */ |
|
46 | + public function delete($key); |
|
47 | 47 | |
48 | - /** |
|
49 | - * Wipes clean the entire cache's keys. |
|
50 | - * |
|
51 | - * @return bool True on success and false on failure. |
|
52 | - */ |
|
53 | - public function clear(); |
|
48 | + /** |
|
49 | + * Wipes clean the entire cache's keys. |
|
50 | + * |
|
51 | + * @return bool True on success and false on failure. |
|
52 | + */ |
|
53 | + public function clear(); |
|
54 | 54 | |
55 | - /** |
|
56 | - * Obtains multiple cache items by their unique keys. |
|
57 | - * |
|
58 | - * @param iterable $keys A list of keys that can obtained in a single operation. |
|
59 | - * @param mixed $default Default value to return for keys that do not exist. |
|
60 | - * |
|
61 | - * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value. |
|
62 | - * |
|
63 | - * @throws \Psr\SimpleCache\InvalidArgumentException |
|
64 | - * MUST be thrown if $keys is neither an array nor a Traversable, |
|
65 | - * or if any of the $keys are not a legal value. |
|
66 | - */ |
|
67 | - public function getMultiple($keys, $default = null); |
|
55 | + /** |
|
56 | + * Obtains multiple cache items by their unique keys. |
|
57 | + * |
|
58 | + * @param iterable $keys A list of keys that can obtained in a single operation. |
|
59 | + * @param mixed $default Default value to return for keys that do not exist. |
|
60 | + * |
|
61 | + * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value. |
|
62 | + * |
|
63 | + * @throws \Psr\SimpleCache\InvalidArgumentException |
|
64 | + * MUST be thrown if $keys is neither an array nor a Traversable, |
|
65 | + * or if any of the $keys are not a legal value. |
|
66 | + */ |
|
67 | + public function getMultiple($keys, $default = null); |
|
68 | 68 | |
69 | - /** |
|
70 | - * Persists a set of key => value pairs in the cache, with an optional TTL. |
|
71 | - * |
|
72 | - * @param iterable $values A list of key => value pairs for a multiple-set operation. |
|
73 | - * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
|
74 | - * the driver supports TTL then the library may set a default value |
|
75 | - * for it or let the driver take care of that. |
|
76 | - * |
|
77 | - * @return bool True on success and false on failure. |
|
78 | - * |
|
79 | - * @throws \Psr\SimpleCache\InvalidArgumentException |
|
80 | - * MUST be thrown if $values is neither an array nor a Traversable, |
|
81 | - * or if any of the $values are not a legal value. |
|
82 | - */ |
|
83 | - public function setMultiple($values, $ttl = null); |
|
69 | + /** |
|
70 | + * Persists a set of key => value pairs in the cache, with an optional TTL. |
|
71 | + * |
|
72 | + * @param iterable $values A list of key => value pairs for a multiple-set operation. |
|
73 | + * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
|
74 | + * the driver supports TTL then the library may set a default value |
|
75 | + * for it or let the driver take care of that. |
|
76 | + * |
|
77 | + * @return bool True on success and false on failure. |
|
78 | + * |
|
79 | + * @throws \Psr\SimpleCache\InvalidArgumentException |
|
80 | + * MUST be thrown if $values is neither an array nor a Traversable, |
|
81 | + * or if any of the $values are not a legal value. |
|
82 | + */ |
|
83 | + public function setMultiple($values, $ttl = null); |
|
84 | 84 | |
85 | - /** |
|
86 | - * Deletes multiple cache items in a single operation. |
|
87 | - * |
|
88 | - * @param iterable $keys A list of string-based keys to be deleted. |
|
89 | - * |
|
90 | - * @return bool True if the items were successfully removed. False if there was an error. |
|
91 | - * |
|
92 | - * @throws \Psr\SimpleCache\InvalidArgumentException |
|
93 | - * MUST be thrown if $keys is neither an array nor a Traversable, |
|
94 | - * or if any of the $keys are not a legal value. |
|
95 | - */ |
|
96 | - public function deleteMultiple($keys); |
|
85 | + /** |
|
86 | + * Deletes multiple cache items in a single operation. |
|
87 | + * |
|
88 | + * @param iterable $keys A list of string-based keys to be deleted. |
|
89 | + * |
|
90 | + * @return bool True if the items were successfully removed. False if there was an error. |
|
91 | + * |
|
92 | + * @throws \Psr\SimpleCache\InvalidArgumentException |
|
93 | + * MUST be thrown if $keys is neither an array nor a Traversable, |
|
94 | + * or if any of the $keys are not a legal value. |
|
95 | + */ |
|
96 | + public function deleteMultiple($keys); |
|
97 | 97 | |
98 | - /** |
|
99 | - * Determines whether an item is present in the cache. |
|
100 | - * |
|
101 | - * NOTE: It is recommended that has() is only to be used for cache warming type purposes |
|
102 | - * and not to be used within your live applications operations for get/set, as this method |
|
103 | - * is subject to a race condition where your has() will return true and immediately after, |
|
104 | - * another script can remove it making the state of your app out of date. |
|
105 | - * |
|
106 | - * @param string $key The cache item key. |
|
107 | - * |
|
108 | - * @return bool |
|
109 | - * |
|
110 | - * @throws \Psr\SimpleCache\InvalidArgumentException |
|
111 | - * MUST be thrown if the $key string is not a legal value. |
|
112 | - */ |
|
113 | - public function has($key); |
|
98 | + /** |
|
99 | + * Determines whether an item is present in the cache. |
|
100 | + * |
|
101 | + * NOTE: It is recommended that has() is only to be used for cache warming type purposes |
|
102 | + * and not to be used within your live applications operations for get/set, as this method |
|
103 | + * is subject to a race condition where your has() will return true and immediately after, |
|
104 | + * another script can remove it making the state of your app out of date. |
|
105 | + * |
|
106 | + * @param string $key The cache item key. |
|
107 | + * |
|
108 | + * @return bool |
|
109 | + * |
|
110 | + * @throws \Psr\SimpleCache\InvalidArgumentException |
|
111 | + * MUST be thrown if the $key string is not a legal value. |
|
112 | + */ |
|
113 | + public function has($key); |
|
114 | 114 | } |
@@ -14,126 +14,125 @@ |
||
14 | 14 | */ |
15 | 15 | interface CacheItemPoolInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * Returns a Cache Item representing the specified key. |
|
19 | - * |
|
20 | - * This method must always return a CacheItemInterface object, even in case of |
|
21 | - * a cache miss. It MUST NOT return null. |
|
22 | - * |
|
23 | - * @param string $key |
|
24 | - * The key for which to return the corresponding Cache Item. |
|
25 | - * |
|
26 | - * @throws InvalidArgumentException |
|
27 | - * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
|
28 | - * MUST be thrown. |
|
29 | - * |
|
30 | - * @return CacheItemInterface |
|
31 | - * The corresponding Cache Item. |
|
32 | - */ |
|
33 | - public function getItem($key); |
|
17 | + /** |
|
18 | + * Returns a Cache Item representing the specified key. |
|
19 | + * |
|
20 | + * This method must always return a CacheItemInterface object, even in case of |
|
21 | + * a cache miss. It MUST NOT return null. |
|
22 | + * |
|
23 | + * @param string $key |
|
24 | + * The key for which to return the corresponding Cache Item. |
|
25 | + * |
|
26 | + * @throws InvalidArgumentException |
|
27 | + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
|
28 | + * MUST be thrown. |
|
29 | + * |
|
30 | + * @return CacheItemInterface |
|
31 | + * The corresponding Cache Item. |
|
32 | + */ |
|
33 | + public function getItem($key); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Returns a traversable set of cache items. |
|
37 | - * |
|
38 | - * @param array $keys |
|
39 | - * An indexed array of keys of items to retrieve. |
|
40 | - * |
|
41 | - * @throws InvalidArgumentException |
|
42 | - * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException |
|
43 | - * MUST be thrown. |
|
44 | - * |
|
45 | - * @return array|\Traversable |
|
46 | - * A traversable collection of Cache Items keyed by the cache keys of |
|
47 | - * each item. A Cache item will be returned for each key, even if that |
|
48 | - * key is not found. However, if no keys are specified then an empty |
|
49 | - * traversable MUST be returned instead. |
|
50 | - */ |
|
51 | - public function getItems(array $keys = array()); |
|
35 | + /** |
|
36 | + * Returns a traversable set of cache items. |
|
37 | + * |
|
38 | + * @param array $keys |
|
39 | + * An indexed array of keys of items to retrieve. |
|
40 | + * |
|
41 | + * @throws InvalidArgumentException |
|
42 | + * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException |
|
43 | + * MUST be thrown. |
|
44 | + * |
|
45 | + * @return array|\Traversable |
|
46 | + * A traversable collection of Cache Items keyed by the cache keys of |
|
47 | + * each item. A Cache item will be returned for each key, even if that |
|
48 | + * key is not found. However, if no keys are specified then an empty |
|
49 | + * traversable MUST be returned instead. |
|
50 | + */ |
|
51 | + public function getItems(array $keys = array()); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Confirms if the cache contains specified cache item. |
|
55 | - * |
|
56 | - * Note: This method MAY avoid retrieving the cached value for performance reasons. |
|
57 | - * This could result in a race condition with CacheItemInterface::get(). To avoid |
|
58 | - * such situation use CacheItemInterface::isHit() instead. |
|
59 | - * |
|
60 | - * @param string $key |
|
61 | - * The key for which to check existence. |
|
62 | - * |
|
63 | - * @throws InvalidArgumentException |
|
64 | - * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
|
65 | - * MUST be thrown. |
|
66 | - * |
|
67 | - * @return bool |
|
68 | - * True if item exists in the cache, false otherwise. |
|
69 | - */ |
|
70 | - public function hasItem($key); |
|
53 | + /** |
|
54 | + * Confirms if the cache contains specified cache item. |
|
55 | + * |
|
56 | + * Note: This method MAY avoid retrieving the cached value for performance reasons. |
|
57 | + * This could result in a race condition with CacheItemInterface::get(). To avoid |
|
58 | + * such situation use CacheItemInterface::isHit() instead. |
|
59 | + * |
|
60 | + * @param string $key |
|
61 | + * The key for which to check existence. |
|
62 | + * |
|
63 | + * @throws InvalidArgumentException |
|
64 | + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
|
65 | + * MUST be thrown. |
|
66 | + * |
|
67 | + * @return bool |
|
68 | + * True if item exists in the cache, false otherwise. |
|
69 | + */ |
|
70 | + public function hasItem($key); |
|
71 | 71 | |
72 | - /** |
|
73 | - * Deletes all items in the pool. |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - * True if the pool was successfully cleared. False if there was an error. |
|
77 | - */ |
|
78 | - public function clear(); |
|
72 | + /** |
|
73 | + * Deletes all items in the pool. |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + * True if the pool was successfully cleared. False if there was an error. |
|
77 | + */ |
|
78 | + public function clear(); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Removes the item from the pool. |
|
82 | - * |
|
83 | - * @param string $key |
|
84 | - * The key for which to delete |
|
85 | - * |
|
86 | - * @throws InvalidArgumentException |
|
87 | - * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
|
88 | - * MUST be thrown. |
|
89 | - * |
|
90 | - * @return bool |
|
91 | - * True if the item was successfully removed. False if there was an error. |
|
92 | - */ |
|
93 | - public function deleteItem($key); |
|
80 | + /** |
|
81 | + * Removes the item from the pool. |
|
82 | + * |
|
83 | + * @param string $key |
|
84 | + * The key for which to delete |
|
85 | + * |
|
86 | + * @throws InvalidArgumentException |
|
87 | + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
|
88 | + * MUST be thrown. |
|
89 | + * |
|
90 | + * @return bool |
|
91 | + * True if the item was successfully removed. False if there was an error. |
|
92 | + */ |
|
93 | + public function deleteItem($key); |
|
94 | 94 | |
95 | - /** |
|
96 | - * Removes multiple items from the pool. |
|
97 | - * |
|
98 | - * @param array $keys |
|
99 | - * An array of keys that should be removed from the pool. |
|
95 | + /** |
|
96 | + * Removes multiple items from the pool. |
|
97 | + * |
|
98 | + * @param array $keys |
|
99 | + * An array of keys that should be removed from the pool. |
|
100 | + * @throws InvalidArgumentException |
|
101 | + * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException |
|
102 | + * MUST be thrown. |
|
103 | + * |
|
104 | + * @return bool |
|
105 | + * True if the items were successfully removed. False if there was an error. |
|
106 | + */ |
|
107 | + public function deleteItems(array $keys); |
|
100 | 108 | |
101 | - * @throws InvalidArgumentException |
|
102 | - * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException |
|
103 | - * MUST be thrown. |
|
104 | - * |
|
105 | - * @return bool |
|
106 | - * True if the items were successfully removed. False if there was an error. |
|
107 | - */ |
|
108 | - public function deleteItems(array $keys); |
|
109 | + /** |
|
110 | + * Persists a cache item immediately. |
|
111 | + * |
|
112 | + * @param CacheItemInterface $item |
|
113 | + * The cache item to save. |
|
114 | + * |
|
115 | + * @return bool |
|
116 | + * True if the item was successfully persisted. False if there was an error. |
|
117 | + */ |
|
118 | + public function save(CacheItemInterface $item); |
|
109 | 119 | |
110 | - /** |
|
111 | - * Persists a cache item immediately. |
|
112 | - * |
|
113 | - * @param CacheItemInterface $item |
|
114 | - * The cache item to save. |
|
115 | - * |
|
116 | - * @return bool |
|
117 | - * True if the item was successfully persisted. False if there was an error. |
|
118 | - */ |
|
119 | - public function save(CacheItemInterface $item); |
|
120 | + /** |
|
121 | + * Sets a cache item to be persisted later. |
|
122 | + * |
|
123 | + * @param CacheItemInterface $item |
|
124 | + * The cache item to save. |
|
125 | + * |
|
126 | + * @return bool |
|
127 | + * False if the item could not be queued or if a commit was attempted and failed. True otherwise. |
|
128 | + */ |
|
129 | + public function saveDeferred(CacheItemInterface $item); |
|
120 | 130 | |
121 | - /** |
|
122 | - * Sets a cache item to be persisted later. |
|
123 | - * |
|
124 | - * @param CacheItemInterface $item |
|
125 | - * The cache item to save. |
|
126 | - * |
|
127 | - * @return bool |
|
128 | - * False if the item could not be queued or if a commit was attempted and failed. True otherwise. |
|
129 | - */ |
|
130 | - public function saveDeferred(CacheItemInterface $item); |
|
131 | - |
|
132 | - /** |
|
133 | - * Persists any deferred cache items. |
|
134 | - * |
|
135 | - * @return bool |
|
136 | - * True if all not-yet-saved items were successfully saved or there were none. False otherwise. |
|
137 | - */ |
|
138 | - public function commit(); |
|
131 | + /** |
|
132 | + * Persists any deferred cache items. |
|
133 | + * |
|
134 | + * @return bool |
|
135 | + * True if all not-yet-saved items were successfully saved or there were none. False otherwise. |
|
136 | + */ |
|
137 | + public function commit(); |
|
139 | 138 | } |
@@ -24,83 +24,83 @@ |
||
24 | 24 | */ |
25 | 25 | interface CacheItemInterface |
26 | 26 | { |
27 | - /** |
|
28 | - * Returns the key for the current cache item. |
|
29 | - * |
|
30 | - * The key is loaded by the Implementing Library, but should be available to |
|
31 | - * the higher level callers when needed. |
|
32 | - * |
|
33 | - * @return string |
|
34 | - * The key string for this cache item. |
|
35 | - */ |
|
36 | - public function getKey(); |
|
27 | + /** |
|
28 | + * Returns the key for the current cache item. |
|
29 | + * |
|
30 | + * The key is loaded by the Implementing Library, but should be available to |
|
31 | + * the higher level callers when needed. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + * The key string for this cache item. |
|
35 | + */ |
|
36 | + public function getKey(); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Retrieves the value of the item from the cache associated with this object's key. |
|
40 | - * |
|
41 | - * The value returned must be identical to the value originally stored by set(). |
|
42 | - * |
|
43 | - * If isHit() returns false, this method MUST return null. Note that null |
|
44 | - * is a legitimate cached value, so the isHit() method SHOULD be used to |
|
45 | - * differentiate between "null value was found" and "no value was found." |
|
46 | - * |
|
47 | - * @return mixed |
|
48 | - * The value corresponding to this cache item's key, or null if not found. |
|
49 | - */ |
|
50 | - public function get(); |
|
38 | + /** |
|
39 | + * Retrieves the value of the item from the cache associated with this object's key. |
|
40 | + * |
|
41 | + * The value returned must be identical to the value originally stored by set(). |
|
42 | + * |
|
43 | + * If isHit() returns false, this method MUST return null. Note that null |
|
44 | + * is a legitimate cached value, so the isHit() method SHOULD be used to |
|
45 | + * differentiate between "null value was found" and "no value was found." |
|
46 | + * |
|
47 | + * @return mixed |
|
48 | + * The value corresponding to this cache item's key, or null if not found. |
|
49 | + */ |
|
50 | + public function get(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * Confirms if the cache item lookup resulted in a cache hit. |
|
54 | - * |
|
55 | - * Note: This method MUST NOT have a race condition between calling isHit() |
|
56 | - * and calling get(). |
|
57 | - * |
|
58 | - * @return bool |
|
59 | - * True if the request resulted in a cache hit. False otherwise. |
|
60 | - */ |
|
61 | - public function isHit(); |
|
52 | + /** |
|
53 | + * Confirms if the cache item lookup resulted in a cache hit. |
|
54 | + * |
|
55 | + * Note: This method MUST NOT have a race condition between calling isHit() |
|
56 | + * and calling get(). |
|
57 | + * |
|
58 | + * @return bool |
|
59 | + * True if the request resulted in a cache hit. False otherwise. |
|
60 | + */ |
|
61 | + public function isHit(); |
|
62 | 62 | |
63 | - /** |
|
64 | - * Sets the value represented by this cache item. |
|
65 | - * |
|
66 | - * The $value argument may be any item that can be serialized by PHP, |
|
67 | - * although the method of serialization is left up to the Implementing |
|
68 | - * Library. |
|
69 | - * |
|
70 | - * @param mixed $value |
|
71 | - * The serializable value to be stored. |
|
72 | - * |
|
73 | - * @return static |
|
74 | - * The invoked object. |
|
75 | - */ |
|
76 | - public function set($value); |
|
63 | + /** |
|
64 | + * Sets the value represented by this cache item. |
|
65 | + * |
|
66 | + * The $value argument may be any item that can be serialized by PHP, |
|
67 | + * although the method of serialization is left up to the Implementing |
|
68 | + * Library. |
|
69 | + * |
|
70 | + * @param mixed $value |
|
71 | + * The serializable value to be stored. |
|
72 | + * |
|
73 | + * @return static |
|
74 | + * The invoked object. |
|
75 | + */ |
|
76 | + public function set($value); |
|
77 | 77 | |
78 | - /** |
|
79 | - * Sets the expiration time for this cache item. |
|
80 | - * |
|
81 | - * @param \DateTimeInterface $expiration |
|
82 | - * The point in time after which the item MUST be considered expired. |
|
83 | - * If null is passed explicitly, a default value MAY be used. If none is set, |
|
84 | - * the value should be stored permanently or for as long as the |
|
85 | - * implementation allows. |
|
86 | - * |
|
87 | - * @return static |
|
88 | - * The called object. |
|
89 | - */ |
|
90 | - public function expiresAt($expiration); |
|
78 | + /** |
|
79 | + * Sets the expiration time for this cache item. |
|
80 | + * |
|
81 | + * @param \DateTimeInterface $expiration |
|
82 | + * The point in time after which the item MUST be considered expired. |
|
83 | + * If null is passed explicitly, a default value MAY be used. If none is set, |
|
84 | + * the value should be stored permanently or for as long as the |
|
85 | + * implementation allows. |
|
86 | + * |
|
87 | + * @return static |
|
88 | + * The called object. |
|
89 | + */ |
|
90 | + public function expiresAt($expiration); |
|
91 | 91 | |
92 | - /** |
|
93 | - * Sets the expiration time for this cache item. |
|
94 | - * |
|
95 | - * @param int|\DateInterval $time |
|
96 | - * The period of time from the present after which the item MUST be considered |
|
97 | - * expired. An integer parameter is understood to be the time in seconds until |
|
98 | - * expiration. If null is passed explicitly, a default value MAY be used. |
|
99 | - * If none is set, the value should be stored permanently or for as long as the |
|
100 | - * implementation allows. |
|
101 | - * |
|
102 | - * @return static |
|
103 | - * The called object. |
|
104 | - */ |
|
105 | - public function expiresAfter($time); |
|
92 | + /** |
|
93 | + * Sets the expiration time for this cache item. |
|
94 | + * |
|
95 | + * @param int|\DateInterval $time |
|
96 | + * The period of time from the present after which the item MUST be considered |
|
97 | + * expired. An integer parameter is understood to be the time in seconds until |
|
98 | + * expiration. If null is passed explicitly, a default value MAY be used. |
|
99 | + * If none is set, the value should be stored permanently or for as long as the |
|
100 | + * implementation allows. |
|
101 | + * |
|
102 | + * @return static |
|
103 | + * The called object. |
|
104 | + */ |
|
105 | + public function expiresAfter($time); |
|
106 | 106 | } |
@@ -22,99 +22,99 @@ |
||
22 | 22 | */ |
23 | 23 | class DriverIO |
24 | 24 | { |
25 | - /** |
|
26 | - * @var int |
|
27 | - */ |
|
28 | - protected $writeHit = 0; |
|
25 | + /** |
|
26 | + * @var int |
|
27 | + */ |
|
28 | + protected $writeHit = 0; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var int |
|
32 | - */ |
|
33 | - protected $readHit = 0; |
|
30 | + /** |
|
31 | + * @var int |
|
32 | + */ |
|
33 | + protected $readHit = 0; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $readMiss = 0; |
|
35 | + /** |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $readMiss = 0; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return int |
|
42 | - */ |
|
43 | - public function getWriteHit(): int |
|
44 | - { |
|
45 | - return $this->writeHit; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @return int |
|
42 | + */ |
|
43 | + public function getWriteHit(): int |
|
44 | + { |
|
45 | + return $this->writeHit; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param int $writeHit |
|
50 | - * @return DriverIO |
|
51 | - */ |
|
52 | - public function setWriteHit(int $writeHit): DriverIO |
|
53 | - { |
|
54 | - $this->writeHit = $writeHit; |
|
55 | - return $this; |
|
56 | - } |
|
48 | + /** |
|
49 | + * @param int $writeHit |
|
50 | + * @return DriverIO |
|
51 | + */ |
|
52 | + public function setWriteHit(int $writeHit): DriverIO |
|
53 | + { |
|
54 | + $this->writeHit = $writeHit; |
|
55 | + return $this; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return DriverIO |
|
60 | - */ |
|
61 | - public function incWriteHit(): DriverIO |
|
62 | - { |
|
63 | - $this->writeHit++; |
|
64 | - return $this; |
|
65 | - } |
|
58 | + /** |
|
59 | + * @return DriverIO |
|
60 | + */ |
|
61 | + public function incWriteHit(): DriverIO |
|
62 | + { |
|
63 | + $this->writeHit++; |
|
64 | + return $this; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return int |
|
69 | - */ |
|
70 | - public function getReadHit(): int |
|
71 | - { |
|
72 | - return $this->readHit; |
|
73 | - } |
|
67 | + /** |
|
68 | + * @return int |
|
69 | + */ |
|
70 | + public function getReadHit(): int |
|
71 | + { |
|
72 | + return $this->readHit; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param int $readHit |
|
77 | - * @return DriverIO |
|
78 | - */ |
|
79 | - public function setReadHit(int $readHit): DriverIO |
|
80 | - { |
|
81 | - $this->readHit = $readHit; |
|
82 | - return $this; |
|
83 | - } |
|
75 | + /** |
|
76 | + * @param int $readHit |
|
77 | + * @return DriverIO |
|
78 | + */ |
|
79 | + public function setReadHit(int $readHit): DriverIO |
|
80 | + { |
|
81 | + $this->readHit = $readHit; |
|
82 | + return $this; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return DriverIO |
|
87 | - */ |
|
88 | - public function incReadHit(): DriverIO |
|
89 | - { |
|
90 | - $this->readHit++; |
|
91 | - return $this; |
|
92 | - } |
|
85 | + /** |
|
86 | + * @return DriverIO |
|
87 | + */ |
|
88 | + public function incReadHit(): DriverIO |
|
89 | + { |
|
90 | + $this->readHit++; |
|
91 | + return $this; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return int |
|
96 | - */ |
|
97 | - public function getReadMiss(): int |
|
98 | - { |
|
99 | - return $this->readMiss; |
|
100 | - } |
|
94 | + /** |
|
95 | + * @return int |
|
96 | + */ |
|
97 | + public function getReadMiss(): int |
|
98 | + { |
|
99 | + return $this->readMiss; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @param int $readMiss |
|
104 | - * @return DriverIO |
|
105 | - */ |
|
106 | - public function setReadMiss(int $readMiss): DriverIO |
|
107 | - { |
|
108 | - $this->readMiss = $readMiss; |
|
109 | - return $this; |
|
110 | - } |
|
102 | + /** |
|
103 | + * @param int $readMiss |
|
104 | + * @return DriverIO |
|
105 | + */ |
|
106 | + public function setReadMiss(int $readMiss): DriverIO |
|
107 | + { |
|
108 | + $this->readMiss = $readMiss; |
|
109 | + return $this; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @return DriverIO |
|
114 | - */ |
|
115 | - public function incReadMiss(): DriverIO |
|
116 | - { |
|
117 | - $this->readMiss++; |
|
118 | - return $this; |
|
119 | - } |
|
112 | + /** |
|
113 | + * @return DriverIO |
|
114 | + */ |
|
115 | + public function incReadMiss(): DriverIO |
|
116 | + { |
|
117 | + $this->readMiss++; |
|
118 | + return $this; |
|
119 | + } |
|
120 | 120 | } |
121 | 121 | \ No newline at end of file |
@@ -22,112 +22,112 @@ |
||
22 | 22 | */ |
23 | 23 | class DriverStatistic |
24 | 24 | { |
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $info = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var int |
|
32 | - */ |
|
33 | - protected $size = 0; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $data = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var mixed |
|
42 | - */ |
|
43 | - protected $rawData; |
|
44 | - |
|
45 | - /** |
|
46 | - * @return string Return info or false if no information available |
|
47 | - */ |
|
48 | - public function getInfo(): string |
|
49 | - { |
|
50 | - return $this->info; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string $info |
|
55 | - * @return $this |
|
56 | - */ |
|
57 | - public function setInfo(string $info): self |
|
58 | - { |
|
59 | - $this->info = $info; |
|
60 | - |
|
61 | - return $this; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return int Return size in octet or false if no information available |
|
66 | - */ |
|
67 | - public function getSize(): int |
|
68 | - { |
|
69 | - return $this->size; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param int $size |
|
74 | - * @return $this |
|
75 | - */ |
|
76 | - public function setSize(int $size) |
|
77 | - { |
|
78 | - $this->size = $size; |
|
79 | - |
|
80 | - return $this; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return mixed |
|
85 | - */ |
|
86 | - public function getData() |
|
87 | - { |
|
88 | - return $this->data; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param mixed $data |
|
93 | - * @return $this |
|
94 | - */ |
|
95 | - public function setData($data): self |
|
96 | - { |
|
97 | - $this->data = ($data ?: ''); |
|
98 | - |
|
99 | - return $this; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return mixed |
|
104 | - */ |
|
105 | - public function getRawData() |
|
106 | - { |
|
107 | - return $this->rawData; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param mixed $raw |
|
112 | - * @return $this |
|
113 | - */ |
|
114 | - public function setRawData($raw): self |
|
115 | - { |
|
116 | - $this->rawData = $raw; |
|
117 | - |
|
118 | - return $this; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - public function getPublicDesc(): array |
|
125 | - { |
|
126 | - return [ |
|
127 | - 'Info' => 'Cache Information', |
|
128 | - 'Size' => 'Cache Size', |
|
129 | - 'Data' => 'Cache items keys', |
|
130 | - 'RawData' => 'Cache raw data', |
|
131 | - ]; |
|
132 | - } |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $info = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var int |
|
32 | + */ |
|
33 | + protected $size = 0; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $data = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var mixed |
|
42 | + */ |
|
43 | + protected $rawData; |
|
44 | + |
|
45 | + /** |
|
46 | + * @return string Return info or false if no information available |
|
47 | + */ |
|
48 | + public function getInfo(): string |
|
49 | + { |
|
50 | + return $this->info; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string $info |
|
55 | + * @return $this |
|
56 | + */ |
|
57 | + public function setInfo(string $info): self |
|
58 | + { |
|
59 | + $this->info = $info; |
|
60 | + |
|
61 | + return $this; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return int Return size in octet or false if no information available |
|
66 | + */ |
|
67 | + public function getSize(): int |
|
68 | + { |
|
69 | + return $this->size; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param int $size |
|
74 | + * @return $this |
|
75 | + */ |
|
76 | + public function setSize(int $size) |
|
77 | + { |
|
78 | + $this->size = $size; |
|
79 | + |
|
80 | + return $this; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return mixed |
|
85 | + */ |
|
86 | + public function getData() |
|
87 | + { |
|
88 | + return $this->data; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param mixed $data |
|
93 | + * @return $this |
|
94 | + */ |
|
95 | + public function setData($data): self |
|
96 | + { |
|
97 | + $this->data = ($data ?: ''); |
|
98 | + |
|
99 | + return $this; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return mixed |
|
104 | + */ |
|
105 | + public function getRawData() |
|
106 | + { |
|
107 | + return $this->rawData; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param mixed $raw |
|
112 | + * @return $this |
|
113 | + */ |
|
114 | + public function setRawData($raw): self |
|
115 | + { |
|
116 | + $this->rawData = $raw; |
|
117 | + |
|
118 | + return $this; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + public function getPublicDesc(): array |
|
125 | + { |
|
126 | + return [ |
|
127 | + 'Info' => 'Cache Information', |
|
128 | + 'Size' => 'Cache Size', |
|
129 | + 'Data' => 'Cache items keys', |
|
130 | + 'RawData' => 'Cache raw data', |
|
131 | + ]; |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | \ No newline at end of file |
@@ -73,8 +73,7 @@ discard block |
||
73 | 73 | * @param int $size |
74 | 74 | * @return $this |
75 | 75 | */ |
76 | - public function setSize(int $size) |
|
77 | - { |
|
76 | + public function setSize(int $size) { |
|
78 | 77 | $this->size = $size; |
79 | 78 | |
80 | 79 | return $this; |
@@ -83,8 +82,7 @@ discard block |
||
83 | 82 | /** |
84 | 83 | * @return mixed |
85 | 84 | */ |
86 | - public function getData() |
|
87 | - { |
|
85 | + public function getData() { |
|
88 | 86 | return $this->data; |
89 | 87 | } |
90 | 88 | |
@@ -102,8 +100,7 @@ discard block |
||
102 | 100 | /** |
103 | 101 | * @return mixed |
104 | 102 | */ |
105 | - public function getRawData() |
|
106 | - { |
|
103 | + public function getRawData() { |
|
107 | 104 | return $this->rawData; |
108 | 105 | } |
109 | 106 |
@@ -24,40 +24,40 @@ |
||
24 | 24 | */ |
25 | 25 | class ItemBatch |
26 | 26 | { |
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $itemKey; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var DateTimeInterface |
|
34 | - */ |
|
35 | - protected $itemDate; |
|
36 | - |
|
37 | - /** |
|
38 | - * ItemBatch constructor. |
|
39 | - * @param string $itemKey |
|
40 | - * @param DateTimeInterface $itemDate |
|
41 | - */ |
|
42 | - public function __construct(string $itemKey, DateTimeInterface $itemDate) |
|
43 | - { |
|
44 | - $this->itemKey = $itemKey; |
|
45 | - $this->itemDate = $itemDate; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function getItemKey(): string |
|
52 | - { |
|
53 | - return $this->itemKey; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @return DateTimeInterface |
|
58 | - */ |
|
59 | - public function getItemDate(): DateTimeInterface |
|
60 | - { |
|
61 | - return $this->itemDate; |
|
62 | - } |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $itemKey; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var DateTimeInterface |
|
34 | + */ |
|
35 | + protected $itemDate; |
|
36 | + |
|
37 | + /** |
|
38 | + * ItemBatch constructor. |
|
39 | + * @param string $itemKey |
|
40 | + * @param DateTimeInterface $itemDate |
|
41 | + */ |
|
42 | + public function __construct(string $itemKey, DateTimeInterface $itemDate) |
|
43 | + { |
|
44 | + $this->itemKey = $itemKey; |
|
45 | + $this->itemDate = $itemDate; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function getItemKey(): string |
|
52 | + { |
|
53 | + return $this->itemKey; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @return DateTimeInterface |
|
58 | + */ |
|
59 | + public function getItemDate(): DateTimeInterface |
|
60 | + { |
|
61 | + return $this->itemDate; |
|
62 | + } |
|
63 | 63 | } |
64 | 64 | \ No newline at end of file |
@@ -39,8 +39,7 @@ |
||
39 | 39 | * @param string $itemKey |
40 | 40 | * @param DateTimeInterface $itemDate |
41 | 41 | */ |
42 | - public function __construct(string $itemKey, DateTimeInterface $itemDate) |
|
43 | - { |
|
42 | + public function __construct(string $itemKey, DateTimeInterface $itemDate) { |
|
44 | 43 | $this->itemKey = $itemKey; |
45 | 44 | $this->itemDate = $itemDate; |
46 | 45 | } |
@@ -47,100 +47,100 @@ |
||
47 | 47 | */ |
48 | 48 | class EventManager implements EventManagerInterface |
49 | 49 | { |
50 | - public const ON_EVERY_EVENT = '__every'; |
|
50 | + public const ON_EVERY_EVENT = '__every'; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var $this |
|
54 | - */ |
|
55 | - protected static $instance; |
|
52 | + /** |
|
53 | + * @var $this |
|
54 | + */ |
|
55 | + protected static $instance; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $events = [ |
|
61 | - self::ON_EVERY_EVENT => [] |
|
62 | - ]; |
|
57 | + /** |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $events = [ |
|
61 | + self::ON_EVERY_EVENT => [] |
|
62 | + ]; |
|
63 | 63 | |
64 | - /** |
|
65 | - * EventManager constructor. |
|
66 | - */ |
|
67 | - final protected function __construct() |
|
68 | - { |
|
69 | - // The constructor should not be instantiated externally |
|
70 | - } |
|
64 | + /** |
|
65 | + * EventManager constructor. |
|
66 | + */ |
|
67 | + final protected function __construct() |
|
68 | + { |
|
69 | + // The constructor should not be instantiated externally |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return EventManagerInterface |
|
74 | - */ |
|
75 | - public static function getInstance(): EventManagerInterface |
|
76 | - { |
|
77 | - return (self::$instance ?: self::$instance = new self); |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return EventManagerInterface |
|
74 | + */ |
|
75 | + public static function getInstance(): EventManagerInterface |
|
76 | + { |
|
77 | + return (self::$instance ?: self::$instance = new self); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string $eventName |
|
82 | - * @param array ...$args |
|
83 | - */ |
|
84 | - public function dispatch(string $eventName, ...$args): void |
|
85 | - { |
|
86 | - /** |
|
87 | - * Replace array_key_exists by isset |
|
88 | - * due to performance issue on huge |
|
89 | - * loop dispatching operations |
|
90 | - */ |
|
91 | - if (isset($this->events[$eventName]) && $eventName !== self::ON_EVERY_EVENT) { |
|
92 | - foreach ($this->events[$eventName] as $event) { |
|
93 | - $event(... $args); |
|
94 | - } |
|
95 | - } |
|
96 | - foreach ($this->events[self::ON_EVERY_EVENT] as $event) { |
|
97 | - $event($eventName, ...$args); |
|
98 | - } |
|
99 | - } |
|
80 | + /** |
|
81 | + * @param string $eventName |
|
82 | + * @param array ...$args |
|
83 | + */ |
|
84 | + public function dispatch(string $eventName, ...$args): void |
|
85 | + { |
|
86 | + /** |
|
87 | + * Replace array_key_exists by isset |
|
88 | + * due to performance issue on huge |
|
89 | + * loop dispatching operations |
|
90 | + */ |
|
91 | + if (isset($this->events[$eventName]) && $eventName !== self::ON_EVERY_EVENT) { |
|
92 | + foreach ($this->events[$eventName] as $event) { |
|
93 | + $event(... $args); |
|
94 | + } |
|
95 | + } |
|
96 | + foreach ($this->events[self::ON_EVERY_EVENT] as $event) { |
|
97 | + $event($eventName, ...$args); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param string $name |
|
103 | - * @param array $arguments |
|
104 | - * @throws PhpfastcacheInvalidArgumentException |
|
105 | - * @throws BadMethodCallException |
|
106 | - */ |
|
107 | - public function __call(string $name, array $arguments): void |
|
108 | - { |
|
109 | - if (\strpos($name, 'on') === 0) { |
|
110 | - $name = \substr($name, 2); |
|
111 | - if (\is_callable($arguments[0])) { |
|
112 | - if (isset($arguments[1]) && \is_string($arguments[0])) { |
|
113 | - $this->events[$name][$arguments[1]] = $arguments[0]; |
|
114 | - } else { |
|
115 | - $this->events[$name][] = $arguments[0]; |
|
116 | - } |
|
117 | - } else { |
|
118 | - throw new PhpfastcacheInvalidArgumentException(\sprintf('Expected Callable, got "%s"', \gettype($arguments[0]))); |
|
119 | - } |
|
120 | - } else { |
|
121 | - throw new BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
|
122 | - } |
|
123 | - } |
|
101 | + /** |
|
102 | + * @param string $name |
|
103 | + * @param array $arguments |
|
104 | + * @throws PhpfastcacheInvalidArgumentException |
|
105 | + * @throws BadMethodCallException |
|
106 | + */ |
|
107 | + public function __call(string $name, array $arguments): void |
|
108 | + { |
|
109 | + if (\strpos($name, 'on') === 0) { |
|
110 | + $name = \substr($name, 2); |
|
111 | + if (\is_callable($arguments[0])) { |
|
112 | + if (isset($arguments[1]) && \is_string($arguments[0])) { |
|
113 | + $this->events[$name][$arguments[1]] = $arguments[0]; |
|
114 | + } else { |
|
115 | + $this->events[$name][] = $arguments[0]; |
|
116 | + } |
|
117 | + } else { |
|
118 | + throw new PhpfastcacheInvalidArgumentException(\sprintf('Expected Callable, got "%s"', \gettype($arguments[0]))); |
|
119 | + } |
|
120 | + } else { |
|
121 | + throw new BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
|
122 | + } |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param callable $callback |
|
127 | - * @param string $callbackName |
|
128 | - */ |
|
129 | - public function onEveryEvents(callable $callback, string $callbackName): void |
|
130 | - { |
|
131 | - $this->events[self::ON_EVERY_EVENT][$callbackName] = $callback; |
|
132 | - } |
|
125 | + /** |
|
126 | + * @param callable $callback |
|
127 | + * @param string $callbackName |
|
128 | + */ |
|
129 | + public function onEveryEvents(callable $callback, string $callbackName): void |
|
130 | + { |
|
131 | + $this->events[self::ON_EVERY_EVENT][$callbackName] = $callback; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @param string $eventName |
|
136 | - * @param string $callbackName |
|
137 | - * @return bool |
|
138 | - */ |
|
139 | - public function unbindEventCallback(string $eventName, string $callbackName): bool |
|
140 | - { |
|
141 | - $return = isset($this->events[$eventName][$callbackName]); |
|
142 | - unset($this->events[$eventName][$callbackName]); |
|
134 | + /** |
|
135 | + * @param string $eventName |
|
136 | + * @param string $callbackName |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | + public function unbindEventCallback(string $eventName, string $callbackName): bool |
|
140 | + { |
|
141 | + $return = isset($this->events[$eventName][$callbackName]); |
|
142 | + unset($this->events[$eventName][$callbackName]); |
|
143 | 143 | |
144 | - return $return; |
|
145 | - } |
|
144 | + return $return; |
|
145 | + } |
|
146 | 146 | } |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * EventManager constructor. |
66 | 66 | */ |
67 | - final protected function __construct() |
|
68 | - { |
|
67 | + final protected function __construct() { |
|
69 | 68 | // The constructor should not be instantiated externally |
70 | 69 | } |
71 | 70 | |
@@ -111,13 +110,16 @@ discard block |
||
111 | 110 | if (\is_callable($arguments[0])) { |
112 | 111 | if (isset($arguments[1]) && \is_string($arguments[0])) { |
113 | 112 | $this->events[$name][$arguments[1]] = $arguments[0]; |
114 | - } else { |
|
113 | + } |
|
114 | + else { |
|
115 | 115 | $this->events[$name][] = $arguments[0]; |
116 | 116 | } |
117 | - } else { |
|
117 | + } |
|
118 | + else { |
|
118 | 119 | throw new PhpfastcacheInvalidArgumentException(\sprintf('Expected Callable, got "%s"', \gettype($arguments[0]))); |
119 | 120 | } |
120 | - } else { |
|
121 | + } |
|
122 | + else { |
|
121 | 123 | throw new BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
122 | 124 | } |
123 | 125 | } |
@@ -25,39 +25,39 @@ |
||
25 | 25 | */ |
26 | 26 | class CacheConditionalHelper |
27 | 27 | { |
28 | - /** |
|
29 | - * @var CacheItemPoolInterface |
|
30 | - */ |
|
31 | - protected $cacheInstance; |
|
32 | - |
|
33 | - /** |
|
34 | - * CachePromise constructor. |
|
35 | - * @param CacheItemPoolInterface $cacheInstance |
|
36 | - */ |
|
37 | - public function __construct(CacheItemPoolInterface $cacheInstance) |
|
38 | - { |
|
39 | - $this->cacheInstance = $cacheInstance; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $cacheKey |
|
44 | - * @param callable $callback |
|
45 | - * @param int|DateInterval $expiresAfter |
|
46 | - * @return mixed |
|
47 | - */ |
|
48 | - public function get(string $cacheKey, callable $callback, $expiresAfter = null) |
|
49 | - { |
|
50 | - $cacheItem = $this->cacheInstance->getItem($cacheKey); |
|
51 | - |
|
52 | - if (!$cacheItem->isHit()) { |
|
53 | - /** Parameter $cacheItem will be available as of 8.0.6 */ |
|
54 | - $cacheItem->set($callback($cacheItem)); |
|
55 | - if ($expiresAfter) { |
|
56 | - $cacheItem->expiresAfter($expiresAfter); |
|
57 | - } |
|
58 | - $this->cacheInstance->save($cacheItem); |
|
59 | - } |
|
60 | - |
|
61 | - return $cacheItem->get(); |
|
62 | - } |
|
28 | + /** |
|
29 | + * @var CacheItemPoolInterface |
|
30 | + */ |
|
31 | + protected $cacheInstance; |
|
32 | + |
|
33 | + /** |
|
34 | + * CachePromise constructor. |
|
35 | + * @param CacheItemPoolInterface $cacheInstance |
|
36 | + */ |
|
37 | + public function __construct(CacheItemPoolInterface $cacheInstance) |
|
38 | + { |
|
39 | + $this->cacheInstance = $cacheInstance; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $cacheKey |
|
44 | + * @param callable $callback |
|
45 | + * @param int|DateInterval $expiresAfter |
|
46 | + * @return mixed |
|
47 | + */ |
|
48 | + public function get(string $cacheKey, callable $callback, $expiresAfter = null) |
|
49 | + { |
|
50 | + $cacheItem = $this->cacheInstance->getItem($cacheKey); |
|
51 | + |
|
52 | + if (!$cacheItem->isHit()) { |
|
53 | + /** Parameter $cacheItem will be available as of 8.0.6 */ |
|
54 | + $cacheItem->set($callback($cacheItem)); |
|
55 | + if ($expiresAfter) { |
|
56 | + $cacheItem->expiresAfter($expiresAfter); |
|
57 | + } |
|
58 | + $this->cacheInstance->save($cacheItem); |
|
59 | + } |
|
60 | + |
|
61 | + return $cacheItem->get(); |
|
62 | + } |
|
63 | 63 | } |
@@ -34,8 +34,7 @@ discard block |
||
34 | 34 | * CachePromise constructor. |
35 | 35 | * @param CacheItemPoolInterface $cacheInstance |
36 | 36 | */ |
37 | - public function __construct(CacheItemPoolInterface $cacheInstance) |
|
38 | - { |
|
37 | + public function __construct(CacheItemPoolInterface $cacheInstance) { |
|
39 | 38 | $this->cacheInstance = $cacheInstance; |
40 | 39 | } |
41 | 40 | |
@@ -45,8 +44,7 @@ discard block |
||
45 | 44 | * @param int|DateInterval $expiresAfter |
46 | 45 | * @return mixed |
47 | 46 | */ |
48 | - public function get(string $cacheKey, callable $callback, $expiresAfter = null) |
|
49 | - { |
|
47 | + public function get(string $cacheKey, callable $callback, $expiresAfter = null) { |
|
50 | 48 | $cacheItem = $this->cacheInstance->getItem($cacheKey); |
51 | 49 | |
52 | 50 | if (!$cacheItem->isHit()) { |