@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | */ |
104 | 104 | private function bootStorages(array $config): void |
105 | 105 | { |
106 | - foreach ($config['buckets'] as $name => $bucket) { |
|
107 | - if (!\is_string($name)) { |
|
106 | + foreach ($config['buckets'] as $name => $bucket){ |
|
107 | + if (!\is_string($name)){ |
|
108 | 108 | throw new InvalidArgumentException( |
109 | 109 | \vsprintf('Storage bucket config key must be a string, but %s defined', [ |
110 | 110 | \get_debug_type($name), |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | $serverName = $bucket['server'] ?? null; |
116 | - if (!\is_string($serverName)) { |
|
116 | + if (!\is_string($serverName)){ |
|
117 | 117 | throw new InvalidArgumentException( |
118 | 118 | \vsprintf('Storage bucket `%s.server` config key required and must be a string, but %s defined', [ |
119 | 119 | $name, |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | $server = $config['servers'][$serverName] ?? null; |
126 | - if (!\is_array($server)) { |
|
126 | + if (!\is_array($server)){ |
|
127 | 127 | throw new InvalidArgumentException( |
128 | 128 | \vsprintf('Storage bucket `%s` relates to non-existing server `%s`', [ |
129 | 129 | $name, |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | $adapter = $server['adapter'] ?? null; |
136 | - if (!\is_string($adapter)) { |
|
136 | + if (!\is_string($adapter)){ |
|
137 | 137 | throw new InvalidArgumentException( |
138 | 138 | \vsprintf('Storage server `%s.adapter` config key required and must be a string, but %s defined', [ |
139 | 139 | $serverName, |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | $this->adapters[$name] = $adapter; |
148 | 148 | |
149 | - if (isset($bucket['distribution'])) { |
|
149 | + if (isset($bucket['distribution'])){ |
|
150 | 150 | $this->distributions[$name] = $bucket['distribution']; |
151 | 151 | } |
152 | 152 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | private function createAdapter(string $serverName, array $bucket, array $server): FilesystemAdapter |
162 | 162 | { |
163 | - switch ($server['adapter']) { |
|
163 | + switch ($server['adapter']){ |
|
164 | 164 | case 'local': |
165 | 165 | return $this->createLocalAdapter($serverName, $bucket, $server); |
166 | 166 | |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | */ |
185 | 185 | private function createS3Adapter(string $serverName, array $bucket, array $server, bool $async): FilesystemAdapter |
186 | 186 | { |
187 | - if (!\class_exists(Credentials::class)) { |
|
187 | + if (!\class_exists(Credentials::class)){ |
|
188 | 188 | throw new ConfigException( |
189 | - 'Can not create AWS credentials while creating "' . $serverName . '" server. ' |
|
189 | + 'Can not create AWS credentials while creating "'.$serverName.'" server. ' |
|
190 | 190 | . 'Perhaps you forgot to install the "league/flysystem-aws-s3-v3" package?' |
191 | 191 | ); |
192 | 192 | } |
@@ -206,8 +206,8 @@ discard block |
||
206 | 206 | $name = $bucket['bucket'] ?? $server['bucket']; |
207 | 207 | $visibility = $bucket['visibility'] ?? $server['bucket'] ?? Visibility::VISIBILITY_PUBLIC; |
208 | 208 | |
209 | - if ($async) { |
|
210 | - if (!\class_exists(AsyncAwsS3Adapter::class)) { |
|
209 | + if ($async){ |
|
210 | + if (!\class_exists(AsyncAwsS3Adapter::class)){ |
|
211 | 211 | throw new InvalidArgumentException( |
212 | 212 | 'Can not create async S3 client, please install "league/flysystem-async-aws-s3"' |
213 | 213 | ); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - if (!\class_exists(AwsS3V3Adapter::class)) { |
|
226 | + if (!\class_exists(AwsS3V3Adapter::class)){ |
|
227 | 227 | throw new InvalidArgumentException( |
228 | 228 | 'Can not create S3 client, please install "league/flysystem-aws-s3-v3"' |
229 | 229 | ); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | */ |
248 | 248 | private function createLocalAdapter(string $serverName, array $bucket, array $server): FilesystemAdapter |
249 | 249 | { |
250 | - if (!\is_string($server['directory'] ?? null)) { |
|
250 | + if (!\is_string($server['directory'] ?? null)){ |
|
251 | 251 | throw new InvalidArgumentException( |
252 | 252 | \vsprintf('Storage server `%s.directory` config key required and must be a string, but %s defined', [ |
253 | 253 | $serverName, |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $adapter = $server['adapter']; |
283 | 283 | $isFilesystemAdapter = \is_subclass_of($adapter, FilesystemAdapter::class, true); |
284 | 284 | |
285 | - if (!$isFilesystemAdapter) { |
|
285 | + if (!$isFilesystemAdapter){ |
|
286 | 286 | throw new InvalidArgumentException( |
287 | 287 | \vsprintf('Storage server `%s` must be a class string of %s, but `%s` defined', [ |
288 | 288 | $serverName, |
@@ -292,9 +292,9 @@ discard block |
||
292 | 292 | ); |
293 | 293 | } |
294 | 294 | |
295 | - try { |
|
295 | + try{ |
|
296 | 296 | return new $adapter(...\array_values($server['options'] ?? [])); |
297 | - } catch (\Throwable $e) { |
|
297 | + }catch (\Throwable $e){ |
|
298 | 298 | $message = 'An error occurred while server `%s` initializing: %s'; |
299 | 299 | throw new InvalidArgumentException(\sprintf($message, $serverName, $e->getMessage()), 0, $e); |
300 | 300 | } |
@@ -103,8 +103,10 @@ discard block |
||
103 | 103 | */ |
104 | 104 | private function bootStorages(array $config): void |
105 | 105 | { |
106 | - foreach ($config['buckets'] as $name => $bucket) { |
|
107 | - if (!\is_string($name)) { |
|
106 | + foreach ($config['buckets'] as $name => $bucket) |
|
107 | + { |
|
108 | + if (!\is_string($name)) |
|
109 | + { |
|
108 | 110 | throw new InvalidArgumentException( |
109 | 111 | \vsprintf('Storage bucket config key must be a string, but %s defined', [ |
110 | 112 | \get_debug_type($name), |
@@ -113,7 +115,8 @@ discard block |
||
113 | 115 | } |
114 | 116 | |
115 | 117 | $serverName = $bucket['server'] ?? null; |
116 | - if (!\is_string($serverName)) { |
|
118 | + if (!\is_string($serverName)) |
|
119 | + { |
|
117 | 120 | throw new InvalidArgumentException( |
118 | 121 | \vsprintf('Storage bucket `%s.server` config key required and must be a string, but %s defined', [ |
119 | 122 | $name, |
@@ -123,7 +126,8 @@ discard block |
||
123 | 126 | } |
124 | 127 | |
125 | 128 | $server = $config['servers'][$serverName] ?? null; |
126 | - if (!\is_array($server)) { |
|
129 | + if (!\is_array($server)) |
|
130 | + { |
|
127 | 131 | throw new InvalidArgumentException( |
128 | 132 | \vsprintf('Storage bucket `%s` relates to non-existing server `%s`', [ |
129 | 133 | $name, |
@@ -133,7 +137,8 @@ discard block |
||
133 | 137 | } |
134 | 138 | |
135 | 139 | $adapter = $server['adapter'] ?? null; |
136 | - if (!\is_string($adapter)) { |
|
140 | + if (!\is_string($adapter)) |
|
141 | + { |
|
137 | 142 | throw new InvalidArgumentException( |
138 | 143 | \vsprintf('Storage server `%s.adapter` config key required and must be a string, but %s defined', [ |
139 | 144 | $serverName, |
@@ -146,7 +151,8 @@ discard block |
||
146 | 151 | |
147 | 152 | $this->adapters[$name] = $adapter; |
148 | 153 | |
149 | - if (isset($bucket['distribution'])) { |
|
154 | + if (isset($bucket['distribution'])) |
|
155 | + { |
|
150 | 156 | $this->distributions[$name] = $bucket['distribution']; |
151 | 157 | } |
152 | 158 | } |
@@ -160,7 +166,8 @@ discard block |
||
160 | 166 | */ |
161 | 167 | private function createAdapter(string $serverName, array $bucket, array $server): FilesystemAdapter |
162 | 168 | { |
163 | - switch ($server['adapter']) { |
|
169 | + switch ($server['adapter']) |
|
170 | + { |
|
164 | 171 | case 'local': |
165 | 172 | return $this->createLocalAdapter($serverName, $bucket, $server); |
166 | 173 | |
@@ -184,7 +191,8 @@ discard block |
||
184 | 191 | */ |
185 | 192 | private function createS3Adapter(string $serverName, array $bucket, array $server, bool $async): FilesystemAdapter |
186 | 193 | { |
187 | - if (!\class_exists(Credentials::class)) { |
|
194 | + if (!\class_exists(Credentials::class)) |
|
195 | + { |
|
188 | 196 | throw new ConfigException( |
189 | 197 | 'Can not create AWS credentials while creating "' . $serverName . '" server. ' |
190 | 198 | . 'Perhaps you forgot to install the "league/flysystem-aws-s3-v3" package?' |
@@ -206,8 +214,10 @@ discard block |
||
206 | 214 | $name = $bucket['bucket'] ?? $server['bucket']; |
207 | 215 | $visibility = $bucket['visibility'] ?? $server['bucket'] ?? Visibility::VISIBILITY_PUBLIC; |
208 | 216 | |
209 | - if ($async) { |
|
210 | - if (!\class_exists(AsyncAwsS3Adapter::class)) { |
|
217 | + if ($async) |
|
218 | + { |
|
219 | + if (!\class_exists(AsyncAwsS3Adapter::class)) |
|
220 | + { |
|
211 | 221 | throw new InvalidArgumentException( |
212 | 222 | 'Can not create async S3 client, please install "league/flysystem-async-aws-s3"' |
213 | 223 | ); |
@@ -223,7 +233,8 @@ discard block |
||
223 | 233 | ); |
224 | 234 | } |
225 | 235 | |
226 | - if (!\class_exists(AwsS3V3Adapter::class)) { |
|
236 | + if (!\class_exists(AwsS3V3Adapter::class)) |
|
237 | + { |
|
227 | 238 | throw new InvalidArgumentException( |
228 | 239 | 'Can not create S3 client, please install "league/flysystem-aws-s3-v3"' |
229 | 240 | ); |
@@ -247,7 +258,8 @@ discard block |
||
247 | 258 | */ |
248 | 259 | private function createLocalAdapter(string $serverName, array $bucket, array $server): FilesystemAdapter |
249 | 260 | { |
250 | - if (!\is_string($server['directory'] ?? null)) { |
|
261 | + if (!\is_string($server['directory'] ?? null)) |
|
262 | + { |
|
251 | 263 | throw new InvalidArgumentException( |
252 | 264 | \vsprintf('Storage server `%s.directory` config key required and must be a string, but %s defined', [ |
253 | 265 | $serverName, |
@@ -282,7 +294,8 @@ discard block |
||
282 | 294 | $adapter = $server['adapter']; |
283 | 295 | $isFilesystemAdapter = \is_subclass_of($adapter, FilesystemAdapter::class, true); |
284 | 296 | |
285 | - if (!$isFilesystemAdapter) { |
|
297 | + if (!$isFilesystemAdapter) |
|
298 | + { |
|
286 | 299 | throw new InvalidArgumentException( |
287 | 300 | \vsprintf('Storage server `%s` must be a class string of %s, but `%s` defined', [ |
288 | 301 | $serverName, |
@@ -292,9 +305,12 @@ discard block |
||
292 | 305 | ); |
293 | 306 | } |
294 | 307 | |
295 | - try { |
|
308 | + try |
|
309 | + { |
|
296 | 310 | return new $adapter(...\array_values($server['options'] ?? [])); |
297 | - } catch (\Throwable $e) { |
|
311 | + } |
|
312 | + catch (\Throwable $e) |
|
313 | + { |
|
298 | 314 | $message = 'An error occurred while server `%s` initializing: %s'; |
299 | 315 | throw new InvalidArgumentException(\sprintf($message, $serverName, $e->getMessage()), 0, $e); |
300 | 316 | } |
@@ -39,18 +39,18 @@ discard block |
||
39 | 39 | |
40 | 40 | $app->bindInjector(StorageConfig::class, ConfiguratorInterface::class); |
41 | 41 | |
42 | - $app->bindSingleton(StorageInterface::class, static function (StorageConfig $config, Container $app) { |
|
42 | + $app->bindSingleton(StorageInterface::class, static function (StorageConfig $config, Container $app){ |
|
43 | 43 | $manager = new Storage($config->getDefaultBucket()); |
44 | 44 | |
45 | 45 | $distributions = $config->getDistributions(); |
46 | 46 | |
47 | - foreach ($config->getAdapters() as $name => $adapter) { |
|
47 | + foreach ($config->getAdapters() as $name => $adapter){ |
|
48 | 48 | $resolver = null; |
49 | 49 | |
50 | - if (isset($distributions[$name])) { |
|
51 | - try { |
|
50 | + if (isset($distributions[$name])){ |
|
51 | + try{ |
|
52 | 52 | $cdn = $app->make(CdnInterface::class); |
53 | - } catch (NotFoundException $e) { |
|
53 | + }catch (NotFoundException $e){ |
|
54 | 54 | $message = 'Unable to create distribution for bucket "%s". ' |
55 | 55 | . 'Please make sure that bootloader %s is added in your application'; |
56 | 56 | $message = \sprintf($message, $name, DistributionBootloader::class); |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | return $manager; |
68 | 68 | }); |
69 | 69 | |
70 | - $app->bindSingleton(Storage::class, static function (StorageInterface $manager) { |
|
70 | + $app->bindSingleton(Storage::class, static function (StorageInterface $manager){ |
|
71 | 71 | return $manager; |
72 | 72 | }); |
73 | 73 | |
74 | - $app->bindSingleton(BucketInterface::class, static function (StorageInterface $manager) { |
|
74 | + $app->bindSingleton(BucketInterface::class, static function (StorageInterface $manager){ |
|
75 | 75 | return $manager->bucket(); |
76 | 76 | }); |
77 | 77 | |
78 | - $app->bindSingleton(Bucket::class, static function (BucketInterface $storage) { |
|
78 | + $app->bindSingleton(Bucket::class, static function (BucketInterface $storage){ |
|
79 | 79 | return $storage; |
80 | 80 | }); |
81 | 81 | } |
@@ -39,18 +39,24 @@ discard block |
||
39 | 39 | |
40 | 40 | $app->bindInjector(StorageConfig::class, ConfiguratorInterface::class); |
41 | 41 | |
42 | - $app->bindSingleton(StorageInterface::class, static function (StorageConfig $config, Container $app) { |
|
42 | + $app->bindSingleton(StorageInterface::class, static function (StorageConfig $config, Container $app) |
|
43 | + { |
|
43 | 44 | $manager = new Storage($config->getDefaultBucket()); |
44 | 45 | |
45 | 46 | $distributions = $config->getDistributions(); |
46 | 47 | |
47 | - foreach ($config->getAdapters() as $name => $adapter) { |
|
48 | + foreach ($config->getAdapters() as $name => $adapter) |
|
49 | + { |
|
48 | 50 | $resolver = null; |
49 | 51 | |
50 | - if (isset($distributions[$name])) { |
|
51 | - try { |
|
52 | + if (isset($distributions[$name])) |
|
53 | + { |
|
54 | + try |
|
55 | + { |
|
52 | 56 | $cdn = $app->make(CdnInterface::class); |
53 | - } catch (NotFoundException $e) { |
|
57 | + } |
|
58 | + catch (NotFoundException $e) |
|
59 | + { |
|
54 | 60 | $message = 'Unable to create distribution for bucket "%s". ' |
55 | 61 | . 'Please make sure that bootloader %s is added in your application'; |
56 | 62 | $message = \sprintf($message, $name, DistributionBootloader::class); |
@@ -67,15 +73,18 @@ discard block |
||
67 | 73 | return $manager; |
68 | 74 | }); |
69 | 75 | |
70 | - $app->bindSingleton(Storage::class, static function (StorageInterface $manager) { |
|
76 | + $app->bindSingleton(Storage::class, static function (StorageInterface $manager) |
|
77 | + { |
|
71 | 78 | return $manager; |
72 | 79 | }); |
73 | 80 | |
74 | - $app->bindSingleton(BucketInterface::class, static function (StorageInterface $manager) { |
|
81 | + $app->bindSingleton(BucketInterface::class, static function (StorageInterface $manager) |
|
82 | + { |
|
75 | 83 | return $manager->bucket(); |
76 | 84 | }); |
77 | 85 | |
78 | - $app->bindSingleton(Bucket::class, static function (BucketInterface $storage) { |
|
86 | + $app->bindSingleton(Bucket::class, static function (BucketInterface $storage) |
|
87 | + { |
|
79 | 88 | return $storage; |
80 | 89 | }); |
81 | 90 | } |