@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | */ |
72 | 72 | private function bootResolvers(array $config): void |
73 | 73 | { |
74 | - foreach ($config['resolvers'] ?? [] as $name => $child) { |
|
75 | - if (!\is_string($name)) { |
|
74 | + foreach ($config['resolvers'] ?? [] as $name => $child){ |
|
75 | + if (!\is_string($name)){ |
|
76 | 76 | throw new InvalidArgumentException( |
77 | 77 | \vsprintf('Distribution driver config key must be a string, but %s given', [ |
78 | 78 | \get_debug_type($child), |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
83 | - if (!\is_array($child)) { |
|
83 | + if (!\is_array($child)){ |
|
84 | 84 | throw new InvalidArgumentException( |
85 | 85 | \vsprintf('Distribution driver config `%s` must be an array, but %s given', [ |
86 | 86 | $name, |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | { |
101 | 101 | $default = $config['default'] ?? null; |
102 | 102 | |
103 | - if ($default !== null) { |
|
103 | + if ($default !== null){ |
|
104 | 104 | // Validate config |
105 | - if (!\is_string($default)) { |
|
105 | + if (!\is_string($default)){ |
|
106 | 106 | throw new InvalidArgumentException( |
107 | 107 | \vsprintf('Distribution config default driver must be a string, but %s given', [ |
108 | 108 | \get_debug_type($default), |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | */ |
122 | 122 | private function createResolver(string $name, array $config): UriResolverInterface |
123 | 123 | { |
124 | - if (!isset($config['type']) || !\is_string($config['type'])) { |
|
124 | + if (!isset($config['type']) || !\is_string($config['type'])){ |
|
125 | 125 | throw $this->invalidConfigKey($name, 'type', 'string'); |
126 | 126 | } |
127 | 127 | |
128 | 128 | $type = $config['type']; |
129 | 129 | |
130 | - switch ($type) { |
|
130 | + switch ($type){ |
|
131 | 131 | case 'static': |
132 | 132 | return $this->createStaticResolver($name, $config); |
133 | 133 | |
@@ -150,17 +150,17 @@ discard block |
||
150 | 150 | */ |
151 | 151 | private function createCustomResolver(string $type, string $name, array $config): UriResolverInterface |
152 | 152 | { |
153 | - if (!\is_subclass_of($type, UriResolverInterface::class, true)) { |
|
153 | + if (!\is_subclass_of($type, UriResolverInterface::class, true)){ |
|
154 | 154 | throw $this->invalidConfigKey($name, 'type', UriResolverInterface::class); |
155 | 155 | } |
156 | 156 | |
157 | - if (isset($config['options']) && !\is_array($config['options'])) { |
|
157 | + if (isset($config['options']) && !\is_array($config['options'])){ |
|
158 | 158 | throw $this->invalidConfigKey($name, 'options', 'array'); |
159 | 159 | } |
160 | 160 | |
161 | - try { |
|
161 | + try{ |
|
162 | 162 | return new $type(...\array_values($config['options'] ?? [])); |
163 | - } catch (\Throwable $e) { |
|
163 | + }catch (\Throwable $e){ |
|
164 | 164 | $message = 'An error occurred while resolver `%s` initializing: %s'; |
165 | 165 | throw new InvalidArgumentException(\sprintf($message, $name, $e->getMessage()), 0, $e); |
166 | 166 | } |
@@ -174,32 +174,32 @@ discard block |
||
174 | 174 | private function createS3Resolver(string $name, array $config): UriResolverInterface |
175 | 175 | { |
176 | 176 | // Required config options |
177 | - if (!isset($config['region']) || !\is_string($config['region'])) { |
|
177 | + if (!isset($config['region']) || !\is_string($config['region'])){ |
|
178 | 178 | throw $this->invalidConfigKey($name, 'region', 'string'); |
179 | 179 | } |
180 | 180 | |
181 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
181 | + if (!isset($config['key']) || !\is_string($config['key'])){ |
|
182 | 182 | throw $this->invalidConfigKey($name, 'key', 'string'); |
183 | 183 | } |
184 | 184 | |
185 | - if (!isset($config['secret']) || !\is_string($config['secret'])) { |
|
185 | + if (!isset($config['secret']) || !\is_string($config['secret'])){ |
|
186 | 186 | throw $this->invalidConfigKey($name, 'secret', 'string'); |
187 | 187 | } |
188 | 188 | |
189 | - if (!isset($config['bucket']) || !\is_string($config['bucket'])) { |
|
189 | + if (!isset($config['bucket']) || !\is_string($config['bucket'])){ |
|
190 | 190 | throw $this->invalidConfigKey($name, 'bucket', 'string'); |
191 | 191 | } |
192 | 192 | |
193 | 193 | // Optional config options |
194 | - if (!\is_string($config['version'] ?? '')) { |
|
194 | + if (!\is_string($config['version'] ?? '')){ |
|
195 | 195 | throw $this->invalidConfigKey($name, 'version', 'string or null'); |
196 | 196 | } |
197 | 197 | |
198 | - if (!\is_string($config['token'] ?? '')) { |
|
198 | + if (!\is_string($config['token'] ?? '')){ |
|
199 | 199 | throw $this->invalidConfigKey($name, 'token', 'string or null'); |
200 | 200 | } |
201 | 201 | |
202 | - if (!\is_int($config['expires'] ?? 0)) { |
|
202 | + if (!\is_int($config['expires'] ?? 0)){ |
|
203 | 203 | throw $this->invalidConfigKey($name, 'expires', 'positive int (unix timestamp)'); |
204 | 204 | } |
205 | 205 | |
@@ -224,15 +224,15 @@ discard block |
||
224 | 224 | */ |
225 | 225 | private function createCloudFrontResolver(string $name, array $config): UriResolverInterface |
226 | 226 | { |
227 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
227 | + if (!isset($config['key']) || !\is_string($config['key'])){ |
|
228 | 228 | throw $this->invalidConfigKey($name, 'key', 'string'); |
229 | 229 | } |
230 | 230 | |
231 | - if (!isset($config['private']) || !\is_string($config['private'])) { |
|
231 | + if (!isset($config['private']) || !\is_string($config['private'])){ |
|
232 | 232 | throw $this->invalidConfigKey($name, 'private', 'string value or path to key file'); |
233 | 233 | } |
234 | 234 | |
235 | - if (!isset($config['domain']) || !\is_string($config['domain'])) { |
|
235 | + if (!isset($config['domain']) || !\is_string($config['domain'])){ |
|
236 | 236 | throw $this->invalidConfigKey($name, 'domain', 'string'); |
237 | 237 | } |
238 | 238 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | private function createStaticResolver(string $name, array $config): UriResolverInterface |
252 | 252 | { |
253 | - if (!isset($config['uri']) || !\is_string($config['uri'])) { |
|
253 | + if (!isset($config['uri']) || !\is_string($config['uri'])){ |
|
254 | 254 | throw $this->invalidConfigKey($name, 'uri', 'string'); |
255 | 255 | } |
256 | 256 | |
@@ -265,17 +265,17 @@ discard block |
||
265 | 265 | */ |
266 | 266 | private function createUri(string $name, string $uri, array $config): UriInterface |
267 | 267 | { |
268 | - if (!\is_string($config['factory'] ?? '')) { |
|
268 | + if (!\is_string($config['factory'] ?? '')){ |
|
269 | 269 | throw $this->invalidConfigKey($name, 'factory', 'string (PSR-7 uri factory implementation)'); |
270 | 270 | } |
271 | 271 | |
272 | - switch (true) { |
|
272 | + switch (true){ |
|
273 | 273 | case isset($config['factory']): |
274 | 274 | /** @var UriFactoryInterface $factory */ |
275 | 275 | $factory = new $config['factory'](); |
276 | 276 | |
277 | - if (!$factory instanceof UriFactoryInterface) { |
|
278 | - $message = 'Distribution config driver `%s` should contain class that must be a valid PSR-7 ' . |
|
277 | + if (!$factory instanceof UriFactoryInterface){ |
|
278 | + $message = 'Distribution config driver `%s` should contain class that must be a valid PSR-7 '. |
|
279 | 279 | 'uri factory implementation, but `%s` given'; |
280 | 280 | throw new InvalidArgumentException(\sprintf($message, $name, $config['factory'])); |
281 | 281 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | return new GuzzleUri($uri); |
290 | 290 | |
291 | 291 | default: |
292 | - $message = 'Can not resolve available PSR-7 UriFactory implementation; ' . |
|
292 | + $message = 'Can not resolve available PSR-7 UriFactory implementation; '. |
|
293 | 293 | 'Please define `factory` config section in `%s` distribution driver config'; |
294 | 294 | throw new InvalidArgumentException(\sprintf($message, $name)); |
295 | 295 | } |
@@ -71,8 +71,10 @@ discard block |
||
71 | 71 | */ |
72 | 72 | private function bootResolvers(array $config): void |
73 | 73 | { |
74 | - foreach ($config['resolvers'] ?? [] as $name => $child) { |
|
75 | - if (!\is_string($name)) { |
|
74 | + foreach ($config['resolvers'] ?? [] as $name => $child) |
|
75 | + { |
|
76 | + if (!\is_string($name)) |
|
77 | + { |
|
76 | 78 | throw new InvalidArgumentException( |
77 | 79 | \vsprintf('Distribution driver config key must be a string, but %s given', [ |
78 | 80 | \get_debug_type($child), |
@@ -80,7 +82,8 @@ discard block |
||
80 | 82 | ); |
81 | 83 | } |
82 | 84 | |
83 | - if (!\is_array($child)) { |
|
85 | + if (!\is_array($child)) |
|
86 | + { |
|
84 | 87 | throw new InvalidArgumentException( |
85 | 88 | \vsprintf('Distribution driver config `%s` must be an array, but %s given', [ |
86 | 89 | $name, |
@@ -100,9 +103,11 @@ discard block |
||
100 | 103 | { |
101 | 104 | $default = $config['default'] ?? null; |
102 | 105 | |
103 | - if ($default !== null) { |
|
106 | + if ($default !== null) |
|
107 | + { |
|
104 | 108 | // Validate config |
105 | - if (!\is_string($default)) { |
|
109 | + if (!\is_string($default)) |
|
110 | + { |
|
106 | 111 | throw new InvalidArgumentException( |
107 | 112 | \vsprintf('Distribution config default driver must be a string, but %s given', [ |
108 | 113 | \get_debug_type($default), |
@@ -121,13 +126,15 @@ discard block |
||
121 | 126 | */ |
122 | 127 | private function createResolver(string $name, array $config): UriResolverInterface |
123 | 128 | { |
124 | - if (!isset($config['type']) || !\is_string($config['type'])) { |
|
129 | + if (!isset($config['type']) || !\is_string($config['type'])) |
|
130 | + { |
|
125 | 131 | throw $this->invalidConfigKey($name, 'type', 'string'); |
126 | 132 | } |
127 | 133 | |
128 | 134 | $type = $config['type']; |
129 | 135 | |
130 | - switch ($type) { |
|
136 | + switch ($type) |
|
137 | + { |
|
131 | 138 | case 'static': |
132 | 139 | return $this->createStaticResolver($name, $config); |
133 | 140 | |
@@ -150,17 +157,22 @@ discard block |
||
150 | 157 | */ |
151 | 158 | private function createCustomResolver(string $type, string $name, array $config): UriResolverInterface |
152 | 159 | { |
153 | - if (!\is_subclass_of($type, UriResolverInterface::class, true)) { |
|
160 | + if (!\is_subclass_of($type, UriResolverInterface::class, true)) |
|
161 | + { |
|
154 | 162 | throw $this->invalidConfigKey($name, 'type', UriResolverInterface::class); |
155 | 163 | } |
156 | 164 | |
157 | - if (isset($config['options']) && !\is_array($config['options'])) { |
|
165 | + if (isset($config['options']) && !\is_array($config['options'])) |
|
166 | + { |
|
158 | 167 | throw $this->invalidConfigKey($name, 'options', 'array'); |
159 | 168 | } |
160 | 169 | |
161 | - try { |
|
170 | + try |
|
171 | + { |
|
162 | 172 | return new $type(...\array_values($config['options'] ?? [])); |
163 | - } catch (\Throwable $e) { |
|
173 | + } |
|
174 | + catch (\Throwable $e) |
|
175 | + { |
|
164 | 176 | $message = 'An error occurred while resolver `%s` initializing: %s'; |
165 | 177 | throw new InvalidArgumentException(\sprintf($message, $name, $e->getMessage()), 0, $e); |
166 | 178 | } |
@@ -174,32 +186,39 @@ discard block |
||
174 | 186 | private function createS3Resolver(string $name, array $config): UriResolverInterface |
175 | 187 | { |
176 | 188 | // Required config options |
177 | - if (!isset($config['region']) || !\is_string($config['region'])) { |
|
189 | + if (!isset($config['region']) || !\is_string($config['region'])) |
|
190 | + { |
|
178 | 191 | throw $this->invalidConfigKey($name, 'region', 'string'); |
179 | 192 | } |
180 | 193 | |
181 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
194 | + if (!isset($config['key']) || !\is_string($config['key'])) |
|
195 | + { |
|
182 | 196 | throw $this->invalidConfigKey($name, 'key', 'string'); |
183 | 197 | } |
184 | 198 | |
185 | - if (!isset($config['secret']) || !\is_string($config['secret'])) { |
|
199 | + if (!isset($config['secret']) || !\is_string($config['secret'])) |
|
200 | + { |
|
186 | 201 | throw $this->invalidConfigKey($name, 'secret', 'string'); |
187 | 202 | } |
188 | 203 | |
189 | - if (!isset($config['bucket']) || !\is_string($config['bucket'])) { |
|
204 | + if (!isset($config['bucket']) || !\is_string($config['bucket'])) |
|
205 | + { |
|
190 | 206 | throw $this->invalidConfigKey($name, 'bucket', 'string'); |
191 | 207 | } |
192 | 208 | |
193 | 209 | // Optional config options |
194 | - if (!\is_string($config['version'] ?? '')) { |
|
210 | + if (!\is_string($config['version'] ?? '')) |
|
211 | + { |
|
195 | 212 | throw $this->invalidConfigKey($name, 'version', 'string or null'); |
196 | 213 | } |
197 | 214 | |
198 | - if (!\is_string($config['token'] ?? '')) { |
|
215 | + if (!\is_string($config['token'] ?? '')) |
|
216 | + { |
|
199 | 217 | throw $this->invalidConfigKey($name, 'token', 'string or null'); |
200 | 218 | } |
201 | 219 | |
202 | - if (!\is_int($config['expires'] ?? 0)) { |
|
220 | + if (!\is_int($config['expires'] ?? 0)) |
|
221 | + { |
|
203 | 222 | throw $this->invalidConfigKey($name, 'expires', 'positive int (unix timestamp)'); |
204 | 223 | } |
205 | 224 | |
@@ -224,15 +243,18 @@ discard block |
||
224 | 243 | */ |
225 | 244 | private function createCloudFrontResolver(string $name, array $config): UriResolverInterface |
226 | 245 | { |
227 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
246 | + if (!isset($config['key']) || !\is_string($config['key'])) |
|
247 | + { |
|
228 | 248 | throw $this->invalidConfigKey($name, 'key', 'string'); |
229 | 249 | } |
230 | 250 | |
231 | - if (!isset($config['private']) || !\is_string($config['private'])) { |
|
251 | + if (!isset($config['private']) || !\is_string($config['private'])) |
|
252 | + { |
|
232 | 253 | throw $this->invalidConfigKey($name, 'private', 'string value or path to key file'); |
233 | 254 | } |
234 | 255 | |
235 | - if (!isset($config['domain']) || !\is_string($config['domain'])) { |
|
256 | + if (!isset($config['domain']) || !\is_string($config['domain'])) |
|
257 | + { |
|
236 | 258 | throw $this->invalidConfigKey($name, 'domain', 'string'); |
237 | 259 | } |
238 | 260 | |
@@ -250,7 +272,8 @@ discard block |
||
250 | 272 | */ |
251 | 273 | private function createStaticResolver(string $name, array $config): UriResolverInterface |
252 | 274 | { |
253 | - if (!isset($config['uri']) || !\is_string($config['uri'])) { |
|
275 | + if (!isset($config['uri']) || !\is_string($config['uri'])) |
|
276 | + { |
|
254 | 277 | throw $this->invalidConfigKey($name, 'uri', 'string'); |
255 | 278 | } |
256 | 279 | |
@@ -265,16 +288,19 @@ discard block |
||
265 | 288 | */ |
266 | 289 | private function createUri(string $name, string $uri, array $config): UriInterface |
267 | 290 | { |
268 | - if (!\is_string($config['factory'] ?? '')) { |
|
291 | + if (!\is_string($config['factory'] ?? '')) |
|
292 | + { |
|
269 | 293 | throw $this->invalidConfigKey($name, 'factory', 'string (PSR-7 uri factory implementation)'); |
270 | 294 | } |
271 | 295 | |
272 | - switch (true) { |
|
296 | + switch (true) |
|
297 | + { |
|
273 | 298 | case isset($config['factory']): |
274 | 299 | /** @var UriFactoryInterface $factory */ |
275 | 300 | $factory = new $config['factory'](); |
276 | 301 | |
277 | - if (!$factory instanceof UriFactoryInterface) { |
|
302 | + if (!$factory instanceof UriFactoryInterface) |
|
303 | + { |
|
278 | 304 | $message = 'Distribution config driver `%s` should contain class that must be a valid PSR-7 ' . |
279 | 305 | 'uri factory implementation, but `%s` given'; |
280 | 306 | throw new InvalidArgumentException(\sprintf($message, $name, $config['factory'])); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | { |
66 | 66 | $name = $name ?? $this->default; |
67 | 67 | |
68 | - if (!isset($this->resolvers[$name])) { |
|
68 | + if (!isset($this->resolvers[$name])){ |
|
69 | 69 | throw new \InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
70 | 70 | } |
71 | 71 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function add(string $name, UriResolverInterface $resolver, bool $overwrite = false): void |
79 | 79 | { |
80 | - if ($overwrite === false && isset($this->resolvers[$name])) { |
|
80 | + if ($overwrite === false && isset($this->resolvers[$name])){ |
|
81 | 81 | throw new \InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
82 | 82 | } |
83 | 83 |
@@ -65,7 +65,8 @@ discard block |
||
65 | 65 | { |
66 | 66 | $name = $name ?? $this->default; |
67 | 67 | |
68 | - if (!isset($this->resolvers[$name])) { |
|
68 | + if (!isset($this->resolvers[$name])) |
|
69 | + { |
|
69 | 70 | throw new \InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
70 | 71 | } |
71 | 72 | |
@@ -77,7 +78,8 @@ discard block |
||
77 | 78 | */ |
78 | 79 | public function add(string $name, UriResolverInterface $resolver, bool $overwrite = false): void |
79 | 80 | { |
80 | - if ($overwrite === false && isset($this->resolvers[$name])) { |
|
81 | + if ($overwrite === false && isset($this->resolvers[$name])) |
|
82 | + { |
|
81 | 83 | throw new \InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
82 | 84 | } |
83 | 85 |