1 | <?php |
||
5 | class Config |
||
6 | { |
||
7 | /** |
||
8 | * List of allowed parameters |
||
9 | */ |
||
10 | public const ALLOWED = [ |
||
11 | 'webpassword', |
||
12 | 'json_force_object', |
||
13 | 'proxy', |
||
14 | 'base_url', |
||
15 | 'user_agent', |
||
16 | 'timeout', |
||
17 | 'tries', |
||
18 | 'seconds', |
||
19 | 'debug', |
||
20 | 'track_redirects', |
||
21 | ]; |
||
22 | |||
23 | /** |
||
24 | * List of minimal required parameters |
||
25 | */ |
||
26 | public const REQUIRED = [ |
||
27 | 'user_agent', |
||
28 | 'base_url', |
||
29 | 'timeout', |
||
30 | 'webpassword', |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * List of configured parameters |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | private $_parameters; |
||
39 | |||
40 | /** |
||
41 | * Config constructor. |
||
42 | * |
||
43 | * @param array $parameters List of parameters which can be set on object creation stage |
||
44 | * |
||
45 | * @throws \InvalidArgumentException |
||
46 | */ |
||
47 | public function __construct(array $parameters = []) |
||
74 | |||
75 | /** |
||
76 | * Magic setter parameter by name |
||
77 | * |
||
78 | * @param string $name Name of parameter |
||
79 | * @param string|bool|int|null $value Value of parameter |
||
80 | */ |
||
81 | public function __set(string $name, $value) |
||
85 | |||
86 | /** |
||
87 | * Check if parameter if available |
||
88 | * |
||
89 | * @param string $name Name of parameter |
||
90 | * |
||
91 | * @return bool |
||
92 | * @throws \InvalidArgumentException |
||
93 | */ |
||
94 | public function __isset($name): bool |
||
98 | |||
99 | /** |
||
100 | * Get parameter via magic call |
||
101 | * |
||
102 | * @param string $name Name of parameter |
||
103 | * |
||
104 | * @return bool|int|string|null |
||
105 | * @throws \InvalidArgumentException |
||
106 | */ |
||
107 | public function __get($name) |
||
111 | |||
112 | /** |
||
113 | * Remove parameter from array |
||
114 | * |
||
115 | * @param string $name Name of parameter |
||
116 | */ |
||
117 | public function __unset($name) |
||
121 | |||
122 | /** |
||
123 | * Set parameter by name |
||
124 | * |
||
125 | * @param string $name Name of parameter |
||
126 | * @param string|bool|int|null $value Value of parameter |
||
127 | * |
||
128 | * @return $this |
||
129 | * @throws \InvalidArgumentException |
||
130 | */ |
||
131 | public function set(string $name, $value): self |
||
141 | |||
142 | /** |
||
143 | * Get available parameter by name |
||
144 | * |
||
145 | * @param string $name Name of parameter |
||
146 | * |
||
147 | * @return bool|int|string|null |
||
148 | * @throws \InvalidArgumentException |
||
149 | */ |
||
150 | public function get(string $name) |
||
158 | |||
159 | /** |
||
160 | * Get all available parameters |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | public function all(): array |
||
168 | |||
169 | /** |
||
170 | * Generate query by parameters |
||
171 | * |
||
172 | * @param array $url |
||
173 | * @param bool $auth |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | public function getBaseUrl(array $url = [], bool $auth = false): string |
||
189 | |||
190 | /** |
||
191 | * Return all ready for Guzzle parameters |
||
192 | * |
||
193 | * @return array |
||
194 | */ |
||
195 | public function guzzle(): array |
||
213 | } |
||
214 |
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.