1 | <?php |
||
7 | class Config |
||
8 | { |
||
9 | /** |
||
10 | * List of allowed parameters |
||
11 | */ |
||
12 | public const ALLOWED = [ |
||
13 | 'api_key', |
||
14 | 'proxy', |
||
15 | 'base_uri', |
||
16 | 'user_agent', |
||
17 | 'timeout', |
||
18 | 'tries', |
||
19 | 'seconds', |
||
20 | 'debug', |
||
21 | 'track_redirects' |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * List of minimal required parameters |
||
26 | */ |
||
27 | public const REQUIRED = [ |
||
28 | 'user_agent', |
||
29 | 'base_uri', |
||
30 | 'timeout', |
||
31 | 'api_key', |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * List of configured parameters |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | private $_parameters; |
||
40 | |||
41 | /** |
||
42 | * Config constructor. |
||
43 | * |
||
44 | * @param array $parameters List of parameters which can be set on object creation stage |
||
45 | * |
||
46 | * @throws \ErrorException |
||
47 | */ |
||
48 | public function __construct(array $parameters = []) |
||
75 | |||
76 | /** |
||
77 | * Magic setter parameter by name |
||
78 | * |
||
79 | * @param string $name Name of parameter |
||
80 | * @param string|bool|int|null $value Value of parameter |
||
81 | * |
||
82 | * @throws \ErrorException |
||
83 | */ |
||
84 | public function __set(string $name, $value) |
||
88 | |||
89 | /** |
||
90 | * Check if parameter if available |
||
91 | * |
||
92 | * @param string $name Name of parameter |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | public function __isset($name): bool |
||
100 | |||
101 | /** |
||
102 | * Get parameter via magic call |
||
103 | * |
||
104 | * @param string $name Name of parameter |
||
105 | * |
||
106 | * @return bool|int|string|null |
||
107 | * @throws ErrorException |
||
108 | */ |
||
109 | public function __get($name) |
||
113 | |||
114 | /** |
||
115 | * Remove parameter from array |
||
116 | * |
||
117 | * @param string $name Name of parameter |
||
118 | */ |
||
119 | public function __unset($name) |
||
123 | |||
124 | /** |
||
125 | * Set parameter by name |
||
126 | * |
||
127 | * @param string $name Name of parameter |
||
128 | * @param string|bool|int|null $value Value of parameter |
||
129 | * |
||
130 | * @return $this |
||
131 | * @throws ErrorException |
||
132 | */ |
||
133 | public function set(string $name, $value): self |
||
143 | |||
144 | /** |
||
145 | * Get available parameter by name |
||
146 | * |
||
147 | * @param string $name Name of parameter |
||
148 | * |
||
149 | * @return bool|int|string|null |
||
150 | * @throws ErrorException |
||
151 | */ |
||
152 | public function get(string $name) |
||
160 | |||
161 | /** |
||
162 | * Get all available parameters |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | public function all(): array |
||
170 | |||
171 | /** |
||
172 | * Return all ready for Guzzle parameters |
||
173 | * |
||
174 | * @return array |
||
175 | * @throws ErrorException |
||
176 | */ |
||
177 | public function guzzle(): array |
||
197 | } |
||
198 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.