1 | <?php |
||
44 | class FS_Key_Value_Storage implements ArrayAccess, Iterator, Countable { |
||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $_id; |
||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $_slug; |
||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $_data; |
||
57 | |||
58 | /** |
||
59 | * @var FS_Plugin_Manager[] |
||
60 | */ |
||
61 | private static $_instances = array(); |
||
62 | /** |
||
63 | * @var FS_Logger |
||
64 | */ |
||
65 | protected $_logger; |
||
66 | |||
67 | /** |
||
68 | * @param string $id |
||
69 | * @param string $slug |
||
70 | * |
||
71 | * @return FS_Key_Value_Storage |
||
72 | */ |
||
73 | static function instance( $id, $slug ) { |
||
81 | |||
82 | protected function __construct( $id, $slug ) { |
||
89 | |||
90 | protected function get_option_manager() { |
||
93 | |||
94 | protected function get_all_data() { |
||
97 | |||
98 | /** |
||
99 | * Load plugin data from local DB. |
||
100 | * |
||
101 | * @author Vova Feldman (@svovaf) |
||
102 | * @since 1.0.7 |
||
103 | */ |
||
104 | function load() { |
||
110 | |||
111 | /** |
||
112 | * @author Vova Feldman (@svovaf) |
||
113 | * @since 1.0.7 |
||
114 | * |
||
115 | * @param string $key |
||
116 | * @param mixed $value |
||
117 | * @param bool $flush |
||
118 | */ |
||
119 | function store( $key, $value, $flush = true ) { |
||
138 | |||
139 | /** |
||
140 | * @author Vova Feldman (@svovaf) |
||
141 | * @since 1.0.7 |
||
142 | * |
||
143 | * @param bool $store |
||
144 | * @param string[] $exceptions Set of keys to keep and not clear. |
||
145 | */ |
||
146 | function clear_all( $store = true, $exceptions = array() ) { |
||
163 | |||
164 | /** |
||
165 | * Delete key-value storage. |
||
166 | * |
||
167 | * @author Vova Feldman (@svovaf) |
||
168 | * @since 1.0.9 |
||
169 | */ |
||
170 | function delete() { |
||
178 | |||
179 | /** |
||
180 | * @author Vova Feldman (@svovaf) |
||
181 | * @since 1.0.7 |
||
182 | * |
||
183 | * @param string $key |
||
184 | * @param bool $store |
||
185 | */ |
||
186 | function remove( $key, $store = true ) { |
||
200 | |||
201 | /** |
||
202 | * @author Vova Feldman (@svovaf) |
||
203 | * @since 1.0.7 |
||
204 | * |
||
205 | * @param string $key |
||
206 | * @param mixed $default |
||
207 | * |
||
208 | * @return bool|\FS_Plugin |
||
209 | */ |
||
210 | function get( $key, $default = false ) { |
||
215 | |||
216 | |||
217 | /* ArrayAccess + Magic Access (better for refactoring) |
||
218 | -----------------------------------------------------------------------------------*/ |
||
219 | function __set( $k, $v ) { |
||
222 | |||
223 | function __isset( $k ) { |
||
226 | |||
227 | function __unset( $k ) { |
||
230 | |||
231 | function __get( $k ) { |
||
234 | |||
235 | function offsetSet( $k, $v ) { |
||
242 | |||
243 | function offsetExists( $k ) { |
||
246 | |||
247 | function offsetUnset( $k ) { |
||
250 | |||
251 | function offsetGet( $k ) { |
||
254 | |||
255 | /** |
||
256 | * (PHP 5 >= 5.0.0)<br/> |
||
257 | * Return the current element |
||
258 | * |
||
259 | * @link http://php.net/manual/en/iterator.current.php |
||
260 | * @return mixed Can return any type. |
||
261 | */ |
||
262 | public function current() { |
||
265 | |||
266 | /** |
||
267 | * (PHP 5 >= 5.0.0)<br/> |
||
268 | * Move forward to next element |
||
269 | * |
||
270 | * @link http://php.net/manual/en/iterator.next.php |
||
271 | * @return void Any returned value is ignored. |
||
272 | */ |
||
273 | public function next() { |
||
276 | |||
277 | /** |
||
278 | * (PHP 5 >= 5.0.0)<br/> |
||
279 | * Return the key of the current element |
||
280 | * |
||
281 | * @link http://php.net/manual/en/iterator.key.php |
||
282 | * @return mixed scalar on success, or null on failure. |
||
283 | */ |
||
284 | public function key() { |
||
287 | |||
288 | /** |
||
289 | * (PHP 5 >= 5.0.0)<br/> |
||
290 | * Checks if current position is valid |
||
291 | * |
||
292 | * @link http://php.net/manual/en/iterator.valid.php |
||
293 | * @return boolean The return value will be casted to boolean and then evaluated. |
||
294 | * Returns true on success or false on failure. |
||
295 | */ |
||
296 | public function valid() { |
||
301 | |||
302 | /** |
||
303 | * (PHP 5 >= 5.0.0)<br/> |
||
304 | * Rewind the Iterator to the first element |
||
305 | * |
||
306 | * @link http://php.net/manual/en/iterator.rewind.php |
||
307 | * @return void Any returned value is ignored. |
||
308 | */ |
||
309 | public function rewind() { |
||
312 | |||
313 | /** |
||
314 | * (PHP 5 >= 5.1.0)<br/> |
||
315 | * Count elements of an object |
||
316 | * |
||
317 | * @link http://php.net/manual/en/countable.count.php |
||
318 | * @return int The custom count as an integer. |
||
319 | * </p> |
||
320 | * <p> |
||
321 | * The return value is cast to an integer. |
||
322 | */ |
||
323 | public function count() { |
||
326 | } |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.