1 | <?php |
||
15 | trait RegistryTrait |
||
16 | { |
||
17 | /** |
||
18 | * Determines what attribute field in the corresponding model table should be used to find the identifier key. |
||
19 | * |
||
20 | * @return string The name attribute field defaults to `name`. |
||
21 | */ |
||
22 | public static function getNameAttribute() |
||
26 | |||
27 | /** |
||
28 | * Determines what attribute field in the corresponding model table should be used to store the identifier key and retrieve its data. |
||
29 | * |
||
30 | * @return string The value attribute field defaults to `value`. |
||
31 | */ |
||
32 | public static function getValueAttribute() |
||
36 | |||
37 | private static $_data; |
||
38 | |||
39 | /** |
||
40 | * Loads all config data into an array. |
||
41 | * |
||
42 | * @return array |
||
43 | */ |
||
44 | protected static function getData() |
||
55 | |||
56 | /** |
||
57 | * Check whether a config value exists or not. |
||
58 | * |
||
59 | * If a value exists but is empty, has will return false. |
||
60 | * |
||
61 | * @param string $name The key to lookup. If not found false is returned. |
||
62 | * @return boolean Whether the key exists or not. |
||
63 | */ |
||
64 | public static function has($name) |
||
68 | |||
69 | /** |
||
70 | * Get the value of a config value. |
||
71 | * |
||
72 | * Returns the value from the registry for the given $name, if not found the defaultValue is returned. |
||
73 | * |
||
74 | * @param string $name The key to lookup. |
||
75 | * @param mixed $defaultValue The default value to return if the key does not exist. |
||
76 | * @return mixed |
||
77 | */ |
||
78 | public static function get($name, $defaultValue = null) |
||
86 | |||
87 | /** |
||
88 | * Store or Update an existing/new config value. |
||
89 | * |
||
90 | * If the config value is not found, a new record will be created. |
||
91 | * |
||
92 | * @param string $name They config key |
||
93 | * @param string $value They config value. When working with array data, encode the data first with Json::encode. |
||
94 | * @return boolean Whether saving was successfull or not. |
||
95 | */ |
||
96 | public static function set($name, $value) |
||
111 | |||
112 | /** |
||
113 | * Remove an existing config value. |
||
114 | * |
||
115 | * If the value is not found in the config, false is returned. |
||
116 | * |
||
117 | * @param string $name The key to remove. |
||
118 | * @return bool If element was found and deleting was successfull true is returned, otherwise false. |
||
119 | */ |
||
120 | public static function remove($name) |
||
130 | } |
||
131 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: