1 | <?php |
||
12 | class Settings { |
||
13 | /** |
||
14 | * @var array Main storage for key-values in this collection. |
||
15 | */ |
||
16 | private $settings = array(); |
||
17 | |||
18 | /** |
||
19 | * Create with new. |
||
20 | * |
||
21 | * @api |
||
22 | * @since 2.0 |
||
23 | * |
||
24 | * @param array $settings Initial settings. Default: none. |
||
25 | * @return \GV\Settings |
||
26 | */ |
||
27 | 153 | public function __construct( $settings = array() ) { |
|
32 | |||
33 | /** |
||
34 | * Mass update values from the allowed ones. |
||
35 | * |
||
36 | * @api |
||
37 | * @since 2.0 |
||
38 | * |
||
39 | * @param array $settings An array of settings to update. |
||
40 | * @return \GV\Settings self chain. |
||
41 | */ |
||
42 | 154 | public function update( $settings ) { |
|
48 | |||
49 | /** |
||
50 | * Set a setting. |
||
51 | * |
||
52 | * @param mixed $key The key the value should be added under. |
||
53 | * @param mixed $value The value to be added to the key. |
||
54 | * |
||
55 | * @api |
||
56 | * @since 2.0 |
||
57 | * @return void |
||
58 | */ |
||
59 | 154 | public function set( $key, $value ) { |
|
62 | |||
63 | /** |
||
64 | * Set an setting. |
||
65 | * |
||
66 | * @param mixed $key The key in this setting to retrieve. |
||
67 | * @param mixed $default A default in case the key is not set. |
||
68 | * |
||
69 | * @api |
||
70 | * @since 2.0 |
||
71 | * @return mixed|null |
||
72 | */ |
||
73 | 106 | public function get( $key, $default = null ) { |
|
76 | |||
77 | /** |
||
78 | * Returns all the objects in this collection as an an array. |
||
79 | * |
||
80 | * @api |
||
81 | * @since 2.0 |
||
82 | * @return array The objects in this collection. |
||
83 | */ |
||
84 | 7 | public function all() { |
|
87 | } |
||
88 |
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.