1 | <?php |
||
11 | class RedisCache implements CacheInterface |
||
12 | { |
||
13 | const PSR16_RESERVED_CHARACTERS = ['{','}','(',')','/','@',':']; |
||
14 | |||
15 | private $handler; |
||
16 | |||
17 | |||
18 | /** |
||
19 | * Connect to Redis service |
||
20 | * |
||
21 | * @param Redis $handler Configuration values that has dbIndex name and host's IP address |
||
22 | * |
||
23 | */ |
||
24 | 8 | public function __construct(Redis $handler) |
|
31 | |||
32 | 1 | public function getConnection() |
|
36 | |||
37 | /** |
||
38 | * {@inheritDoc} |
||
39 | */ |
||
40 | 1 | public function get($key, $default = null) |
|
45 | |||
46 | /** |
||
47 | * {@inheritDoc} |
||
48 | */ |
||
49 | 5 | public function set($key, $value, $ttl = null) |
|
61 | |||
62 | /** |
||
63 | * {@inheritDoc} |
||
64 | */ |
||
65 | 2 | public function delete($key) |
|
69 | /** |
||
70 | * {@inheritDoc} |
||
71 | */ |
||
72 | 8 | public function clear() |
|
76 | /** |
||
77 | * {@inheritDoc} |
||
78 | */ |
||
79 | 1 | public function getMultiple($keys, $default = null) |
|
87 | /** |
||
88 | * {@inheritDoc} |
||
89 | */ |
||
90 | 1 | public function setMultiple($values, $ttl = null) |
|
109 | /** |
||
110 | * {@inheritDoc} |
||
111 | */ |
||
112 | 1 | public function deleteMultiple($keys) |
|
123 | /** |
||
124 | * Increment a value atomically in the cache by its step value, which defaults to 1 |
||
125 | * |
||
126 | * @param string $key The cache item key |
||
127 | * @param integer $step The value to increment by, defaulting to 1 |
||
128 | * |
||
129 | * @return int|bool The new value on success and false on failure |
||
130 | */ |
||
131 | 1 | public function increment($key, $step = 1) |
|
135 | /** |
||
136 | * Decrement a value atomically in the cache by its step value, which defaults to 1 |
||
137 | * |
||
138 | * @param string $key The cache item key |
||
139 | * @param integer $step The value to decrement by, defaulting to 1 |
||
140 | * |
||
141 | * @return int|bool The new value on success and false on failure |
||
142 | */ |
||
143 | 1 | public function decrement($key, $step = 1) |
|
147 | |||
148 | |||
149 | |||
150 | |||
151 | /** |
||
152 | * {@inheritDoc} |
||
153 | */ |
||
154 | 1 | public function has($key) |
|
159 | |||
160 | 5 | private function checkKeysValidity($key) |
|
173 | } |
||
174 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.