1 | <?php |
||
35 | class AwsS3Provider extends Provider implements ProviderInterface |
||
36 | { |
||
37 | /** |
||
38 | * All the configurations needed by this class with the |
||
39 | * optional configurations default values. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $default = [ |
||
44 | 'url' => null, |
||
45 | 'threshold' => 10, |
||
46 | 'providers' => [ |
||
47 | 'aws' => [ |
||
48 | 's3' => [ |
||
49 | 'version' => null, |
||
50 | 'region' => null, |
||
51 | 'buckets' => null, |
||
52 | 'http' => null, |
||
53 | 'acl' => 'public-read', |
||
54 | 'cloudfront' => [ |
||
55 | 'use' => false, |
||
56 | 'cdn_url' => null, |
||
57 | ], |
||
58 | ], |
||
59 | ], |
||
60 | ], |
||
61 | ]; |
||
62 | |||
63 | /** |
||
64 | * Required configurations (must exist in the config file). |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $rules = ['version', 'region', 'key', 'secret', 'buckets', 'url']; |
||
69 | |||
70 | /** |
||
71 | * this array holds the parsed configuration to be used across the class. |
||
72 | * |
||
73 | * @var Array |
||
74 | */ |
||
75 | protected $supplier; |
||
76 | |||
77 | /** |
||
78 | * @var Instance of Aws\S3\S3Client |
||
79 | */ |
||
80 | protected $s3_client; |
||
81 | |||
82 | /** |
||
83 | * @var Instance of Guzzle\Batch\BatchBuilder |
||
84 | */ |
||
85 | protected $batch; |
||
86 | |||
87 | /** |
||
88 | * @var \Vinelab\Cdn\Contracts\CdnHelperInterface |
||
89 | */ |
||
90 | protected $cdn_helper; |
||
91 | |||
92 | /** |
||
93 | * @var \Vinelab\Cdn\Validators\Contracts\ConfigurationsInterface |
||
94 | */ |
||
95 | protected $configurations; |
||
96 | |||
97 | /** |
||
98 | * @var \Vinelab\Cdn\Validators\Contracts\ProviderValidatorInterface |
||
99 | */ |
||
100 | protected $provider_validator; |
||
101 | |||
102 | /** |
||
103 | * @param \Symfony\Component\Console\Output\ConsoleOutput $console |
||
104 | * @param \Vinelab\Cdn\Validators\Contracts\ProviderValidatorInterface $provider_validator |
||
105 | * @param \Vinelab\Cdn\Contracts\CdnHelperInterface $cdn_helper |
||
106 | */ |
||
107 | public function __construct( |
||
116 | |||
117 | /** |
||
118 | * Read the configuration and prepare an array with the relevant configurations |
||
119 | * for the (AWS S3) provider. and return itself. |
||
120 | * |
||
121 | * @param $configurations |
||
122 | * |
||
123 | * @return $this |
||
124 | */ |
||
125 | public function init($configurations) |
||
126 | { |
||
127 | // merge the received config array with the default configurations array to |
||
128 | // fill missed keys with null or default values. |
||
129 | $this->default = array_replace_recursive($this->default, $configurations); |
||
130 | |||
131 | $supplier = [ |
||
132 | 'provider_url' => $this->default['url'], |
||
133 | 'threshold' => $this->default['threshold'], |
||
134 | 'version' => $this->default['providers']['aws']['s3']['version'], |
||
135 | 'region' => $this->default['providers']['aws']['s3']['region'], |
||
136 | 'buckets' => $this->default['providers']['aws']['s3']['buckets'], |
||
137 | 'acl' => $this->default['providers']['aws']['s3']['acl'], |
||
138 | 'cloudfront' => $this->default['providers']['aws']['s3']['cloudfront']['use'], |
||
139 | 'cloudfront_url' => $this->default['providers']['aws']['s3']['cloudfront']['cdn_url'], |
||
140 | 'http' => $this->default['providers']['aws']['s3']['http'], |
||
141 | ]; |
||
142 | |||
143 | // check if any required configuration is missed |
||
144 | $this->provider_validator->validate($supplier, $this->rules); |
||
145 | |||
146 | $this->supplier = $supplier; |
||
147 | |||
148 | return $this; |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Create an S3 client instance |
||
153 | * (Note: it will read the credentials form the .env file). |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function connect() |
||
174 | |||
175 | /** |
||
176 | * Upload assets. |
||
177 | * |
||
178 | * @param $assets |
||
179 | * |
||
180 | * @return bool |
||
181 | */ |
||
182 | public function upload($assets) |
||
237 | |||
238 | /** |
||
239 | * Empty bucket. |
||
240 | * |
||
241 | * @return bool |
||
242 | */ |
||
243 | public function emptyBucket() |
||
288 | |||
289 | /** |
||
290 | * This function will be called from the CdnFacade class when |
||
291 | * someone use this {{ Cdn::asset('') }} facade helper. |
||
292 | * |
||
293 | * @param $path |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | public function urlGenerator($path) |
||
312 | |||
313 | /** |
||
314 | * @param $s3_client |
||
315 | */ |
||
316 | public function setS3Client($s3_client) |
||
320 | |||
321 | /** |
||
322 | * @return string |
||
323 | */ |
||
324 | public function getUrl() |
||
328 | |||
329 | /** |
||
330 | * @return string |
||
331 | */ |
||
332 | public function getCloudFront() |
||
340 | |||
341 | /** |
||
342 | * @return string |
||
343 | */ |
||
344 | public function getCloudFrontUrl() |
||
348 | |||
349 | /** |
||
350 | * @return array |
||
351 | */ |
||
352 | public function getBucket() |
||
364 | |||
365 | /** |
||
366 | * @param $attr |
||
367 | * |
||
368 | * @return Mix | null |
||
369 | */ |
||
370 | public function __get($attr) |
||
374 | |||
375 | /** |
||
376 | * @param $assets |
||
377 | * @return mixed |
||
378 | */ |
||
379 | private function getFilesAlreadyOnBucket($assets) |
||
412 | } |
||
413 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..