1 | <?php |
||
9 | class ElggFileCache extends \ElggCache { |
||
10 | /** |
||
11 | * Set the Elgg cache. |
||
12 | * |
||
13 | * @param string $cache_path The cache path. |
||
14 | * @param int $max_age Maximum age in seconds, 0 if no limit. |
||
15 | * @param int $max_size Maximum size of cache in seconds, 0 if no limit. |
||
16 | * |
||
17 | * @throws ConfigurationException |
||
18 | */ |
||
19 | public function __construct($cache_path, $max_age = 0, $max_size = 0) { |
||
28 | |||
29 | // @codingStandardsIgnoreStart |
||
30 | /** |
||
31 | * Create and return a handle to a file. |
||
32 | * |
||
33 | * @deprecated 1.8 Use \ElggFileCache::createFile() |
||
34 | * |
||
35 | * @param string $filename Filename to save as |
||
36 | * @param string $rw Write mode |
||
37 | * |
||
38 | * @return mixed |
||
39 | */ |
||
40 | protected function create_file($filename, $rw = "rb") { |
||
45 | // @codingStandardsIgnoreEnd |
||
46 | |||
47 | /** |
||
48 | * Create and return a handle to a file. |
||
49 | * |
||
50 | * @param string $filename Filename to save as |
||
51 | * @param string $rw Write mode |
||
52 | * |
||
53 | * @return mixed |
||
54 | */ |
||
55 | protected function createFile($filename, $rw = "rb") { |
||
76 | |||
77 | // @codingStandardsIgnoreStart |
||
78 | /** |
||
79 | * Create a sanitised filename for the file. |
||
80 | * |
||
81 | * @deprecated 1.8 Use \ElggFileCache::sanitizeFilename() |
||
82 | * |
||
83 | * @param string $filename The filename |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | protected function sanitise_filename($filename) { |
||
92 | // @codingStandardsIgnoreEnd |
||
93 | |||
94 | /** |
||
95 | * Create a sanitised filename for the file. |
||
96 | * |
||
97 | * @param string $filename The filename |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | protected function sanitizeFilename($filename) { |
||
106 | |||
107 | /** |
||
108 | * Save a key |
||
109 | * |
||
110 | * @param string $key Name |
||
111 | * @param string $data Value |
||
112 | * |
||
113 | * @return boolean |
||
114 | */ |
||
115 | public function save($key, $data) { |
||
126 | |||
127 | /** |
||
128 | * Load a key |
||
129 | * |
||
130 | * @param string $key Name |
||
131 | * @param int $offset Offset |
||
132 | * @param int $limit Limit |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | public function load($key, $offset = 0, $limit = null) { |
||
152 | |||
153 | /** |
||
154 | * Invalidate a given key. |
||
155 | * |
||
156 | * @param string $key Name |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | public function delete($key) { |
||
168 | |||
169 | /** |
||
170 | * Delete all files in the directory of this file cache |
||
171 | * |
||
172 | * @return void |
||
173 | */ |
||
174 | public function clear() { |
||
190 | |||
191 | /** |
||
192 | * Preform cleanup and invalidates cache upon object destruction |
||
193 | * |
||
194 | * @throws IOException |
||
195 | */ |
||
196 | public function __destruct() { |
||
230 | } |
||
231 |
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.