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 | * @since 1.3.0 |
||
44 | */ |
||
45 | protected static function getData() |
||
56 | |||
57 | /** |
||
58 | * Clear data array. |
||
59 | * |
||
60 | * @since 1.3.0 |
||
61 | */ |
||
62 | protected static function clearData() |
||
66 | |||
67 | /** |
||
68 | * Check whether a config value exists or not. |
||
69 | * |
||
70 | * If a value exists but is empty, has will return false. |
||
71 | * |
||
72 | * @param string $name The key to lookup. If not found false is returned. |
||
73 | * @return boolean Whether the key exists or not. |
||
74 | */ |
||
75 | public static function has($name) |
||
79 | |||
80 | /** |
||
81 | * Get the value of a config value. |
||
82 | * |
||
83 | * Returns the value from the registry for the given $name, if not found the defaultValue is returned. |
||
84 | * |
||
85 | * @param string $name The key to lookup. |
||
86 | * @param mixed $defaultValue The default value to return if the key does not exist. |
||
87 | * @return mixed |
||
88 | */ |
||
89 | public static function get($name, $defaultValue = null) |
||
97 | |||
98 | /** |
||
99 | * Store or Update an existing/new config value. |
||
100 | * |
||
101 | * If the config value is not found, a new record will be created. |
||
102 | * |
||
103 | * @param string $name They config key |
||
104 | * @param string $value They config value. When working with array data, encode the data first with Json::encode. |
||
105 | * @return boolean Whether saving was successfull or not. |
||
106 | */ |
||
107 | public static function set($name, $value) |
||
122 | |||
123 | /** |
||
124 | * Remove an existing config value. |
||
125 | * |
||
126 | * If the value is not found in the config, false is returned. |
||
127 | * |
||
128 | * @param string $name The key to remove. |
||
129 | * @return bool If element was found and deleting was successfull true is returned, otherwise false. |
||
130 | */ |
||
131 | public static function remove($name) |
||
142 | } |
||
143 |
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: