Completed
Push — master ( da9025...5f7c52 )
by summer
20s
created

AliOssAdapter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 9
c 1
b 0
f 1
nc 1
nop 9
dl 0
loc 21
rs 9.9666

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Created by jacob.
4
 * Date: 2016/5/19 0019
5
 * Time: 下午 17:07
6
 */
7
8
namespace Jacobcyl\AliOSS;
9
10
use League\Flysystem\Adapter\AbstractAdapter;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Adapter\AbstractAdapter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use League\Flysystem\AdapterInterface;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\AdapterInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use League\Flysystem\Config;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use League\Flysystem\Util;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Util was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use OSS\Core\OssException;
15
use OSS\OssClient;
16
use Log;
17
use Illuminate\Contracts\Filesystem\FileNotFoundException;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Fil...m\FileNotFoundException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
19
class AliOssAdapter extends AbstractAdapter
20
{
21
    /**
22
     * @var Log debug Mode true|false
23
     */
24
    protected $debug;
25
    /**
26
     * @var array
27
     */
28
    protected static $resultMap = [
29
        'Body'           => 'raw_contents',
30
        'Content-Length' => 'size',
31
        'ContentType'    => 'mimetype',
32
        'Size'           => 'size',
33
        'StorageClass'   => 'storage_class',
34
    ];
35
36
    /**
37
     * @var array
38
     */
39
    protected static $metaOptions = [
40
        'CacheControl',
41
        'Expires',
42
        'ServerSideEncryption',
43
        'Metadata',
44
        'ACL',
45
        'ContentType',
46
        'ContentDisposition',
47
        'ContentLanguage',
48
        'ContentEncoding',
49
    ];
50
51
    protected static $metaMap = [
52
        'CacheControl'         => 'Cache-Control',
53
        'Expires'              => 'Expires',
54
        'ServerSideEncryption' => 'x-oss-server-side-encryption',
55
        'Metadata'             => 'x-oss-metadata-directive',
56
        'ACL'                  => 'x-oss-object-acl',
57
        'ContentType'          => 'Content-Type',
58
        'ContentDisposition'   => 'Content-Disposition',
59
        'ContentLanguage'      => 'response-content-language',
60
        'ContentEncoding'      => 'Content-Encoding',
61
    ];
62
63
    //Aliyun OSS Client OssClient
64
    protected $client;
65
    //bucket name
66
    protected $bucket;
67
68
    protected $endPoint;
69
70
    protected $cdnDomain;
71
72
    protected $ssl;
73
74
    protected $isCname;
75
76
    //配置
77
    protected $options = [
78
        'Multipart'   => 128
79
    ];
80
81
82
    /**
83
     * AliOssAdapter constructor.
84
     *
85
     * @param OssClient $client
86
     * @param string    $bucket
87
     * @param string    $endPoint
88
     * @param bool      $ssl
89
     * @param bool      $isCname
90
     * @param bool      $debug
91
     * @param null      $prefix
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $prefix is correct as it would always require null to be passed?
Loading history...
92
     * @param array     $options
93
     */
94
    public function __construct(
95
        OssClient $client,
96
        $bucket,
97
        $endPoint,
98
        $ssl,
99
        $isCname = false,
100
        $debug = false,
101
        $cdnDomain,
102
        $prefix = null,
103
        array $options = []
104
    )
105
    {
106
        $this->debug = $debug;
0 ignored issues
show
Documentation Bug introduced by
It seems like $debug of type boolean is incompatible with the declared type Log of property $debug.

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..

Loading history...
107
        $this->client = $client;
108
        $this->bucket = $bucket;
109
        $this->setPathPrefix($prefix);
110
        $this->endPoint = $endPoint;
111
        $this->ssl = $ssl;
112
        $this->isCname = $isCname;
113
        $this->cdnDomain = $cdnDomain;
114
        $this->options = array_merge($this->options, $options);
115
    }
116
117
    /**
118
     * Get the OssClient bucket.
119
     *
120
     * @return string
121
     */
122
    public function getBucket()
123
    {
124
        return $this->bucket;
125
    }
126
127
    /**
128
     * Get the OSSClient instance.
129
     *
130
     * @return OssClient
131
     */
132
    public function getClient()
133
    {
134
        return $this->client;
135
    }
136
137
    /**
138
     * Write a new file.
139
     *
140
     * @param string $path
141
     * @param string $contents
142
     * @param Config $config Config object
143
     *
144
     * @return array|false false on failure file meta data on success
145
     */
146
    public function write($path, $contents, Config $config)
147
    {
148
        $object = $this->applyPathPrefix($path);
149
        $options = $this->getOptions($this->options, $config);
150
151
        if (! isset($options[OssClient::OSS_LENGTH])) {
152
            $options[OssClient::OSS_LENGTH] = Util::contentSize($contents);
153
        }
154
        if (! isset($options[OssClient::OSS_CONTENT_TYPE])) {
155
            $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, $contents);
156
        }
157
        try {
158
            $this->client->putObject($this->bucket, $object, $contents, $options);
159
        } catch (OssException $e) {
160
            $this->logErr(__FUNCTION__, $e);
161
            return false;
162
        }
163
        return $this->normalizeResponse($options, $path);
164
    }
165
166
    /**
167
     * Write a new file using a stream.
168
     *
169
     * @param string $path
170
     * @param resource $resource
171
     * @param Config $config Config object
172
     *
173
     * @return array|false false on failure file meta data on success
174
     */
175
    public function writeStream($path, $resource, Config $config)
176
    {
177
        $options = $this->getOptions($this->options, $config);
0 ignored issues
show
Unused Code introduced by
The assignment to $options is dead and can be removed.
Loading history...
178
        $contents = stream_get_contents($resource);
179
180
        return $this->write($path, $contents, $config);
181
    }
182
183
    public function writeFile($path, $filePath, Config $config){
184
        $object = $this->applyPathPrefix($path);
185
        $options = $this->getOptions($this->options, $config);
186
187
        $options[OssClient::OSS_CHECK_MD5] = true;
188
189
        if (! isset($options[OssClient::OSS_CONTENT_TYPE])) {
190
            $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, '');
191
        }
192
        try {
193
            $this->client->uploadFile($this->bucket, $object, $filePath, $options);
194
        } catch (OssException $e) {
195
            $this->logErr(__FUNCTION__, $e);
196
            return false;
197
        }
198
        return $this->normalizeResponse($options, $path);
199
    }
200
201
    /**
202
     * Update a file.
203
     *
204
     * @param string $path
205
     * @param string $contents
206
     * @param Config $config Config object
207
     *
208
     * @return array|false false on failure file meta data on success
209
     */
210
    public function update($path, $contents, Config $config)
211
    {
212
        if (! $config->has('visibility') && ! $config->has('ACL')) {
213
            $config->set(static::$metaMap['ACL'], $this->getObjectACL($path));
214
        }
215
        // $this->delete($path);
216
        return $this->write($path, $contents, $config);
217
    }
218
219
    /**
220
     * Update a file using a stream.
221
     *
222
     * @param string $path
223
     * @param resource $resource
224
     * @param Config $config Config object
225
     *
226
     * @return array|false false on failure file meta data on success
227
     */
228
    public function updateStream($path, $resource, Config $config)
229
    {
230
        $contents = stream_get_contents($resource);
231
        return $this->update($path, $contents, $config);
232
    }
233
234
    /**
235
     * {@inheritdoc}
236
     */
237
    public function rename($path, $newpath)
238
    {
239
        if (! $this->copy($path, $newpath)){
240
            return false;
241
        }
242
243
        return $this->delete($path);
244
    }
245
246
    /**
247
     * {@inheritdoc}
248
     */
249
    public function copy($path, $newpath)
250
    {
251
        $object = $this->applyPathPrefix($path);
252
        $newObject = $this->applyPathPrefix($newpath);
253
        try{
254
            $this->client->copyObject($this->bucket, $object, $this->bucket, $newObject);
255
        } catch (OssException $e) {
256
            $this->logErr(__FUNCTION__, $e);
257
            return false;
258
        }
259
260
        return true;
261
    }
262
263
    /**
264
     * {@inheritdoc}
265
     */
266
    public function delete($path)
267
    {
268
        $bucket = $this->bucket;
269
        $object = $this->applyPathPrefix($path);
270
271
        try{
272
            $this->client->deleteObject($bucket, $object);
273
        }catch (OssException $e) {
274
            $this->logErr(__FUNCTION__, $e);
275
            return false;
276
        }
277
278
        return ! $this->has($path);
279
    }
280
281
    /**
282
     * {@inheritdoc}
283
     */
284
    public function deleteDir($dirname)
285
    {
286
        $dirname = rtrim($this->applyPathPrefix($dirname), '/').'/';
287
        $dirObjects = $this->listDirObjects($dirname, true);
288
289
        if(count($dirObjects['objects']) > 0 ){
290
291
            foreach($dirObjects['objects'] as $object)
292
            {
293
                $objects[] = $object['Key'];
294
            }
295
296
            try {
297
                $this->client->deleteObjects($this->bucket, $objects);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $objects seems to be defined by a foreach iteration on line 291. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
298
            } catch (OssException $e) {
299
                $this->logErr(__FUNCTION__, $e);
300
                return false;
301
            }
302
303
        }
304
305
        try {
306
            $this->client->deleteObject($this->bucket, $dirname);
307
        } catch (OssException $e) {
308
            $this->logErr(__FUNCTION__, $e);
309
            return false;
310
        }
311
312
        return true;
313
    }
314
315
    /**
316
     * 列举文件夹内文件列表;可递归获取子文件夹;
317
     * @param string $dirname 目录
318
     * @param bool $recursive 是否递归
319
     * @return mixed
320
     * @throws OssException
321
     */
322
    public function listDirObjects($dirname = '', $recursive =  false)
323
    {
324
        $delimiter = '/';
325
        $nextMarker = '';
326
        $maxkeys = 1000;
327
328
        //存储结果
329
        $result = [];
330
331
        while(true){
332
            $options = [
333
                'delimiter' => $delimiter,
334
                'prefix'    => $dirname,
335
                'max-keys'  => $maxkeys,
336
                'marker'    => $nextMarker,
337
            ];
338
339
            try {
340
                $listObjectInfo = $this->client->listObjects($this->bucket, $options);
341
            } catch (OssException $e) {
342
                $this->logErr(__FUNCTION__, $e);
343
                // return false;
344
                throw $e;
345
            }
346
347
            $nextMarker = $listObjectInfo->getNextMarker(); // 得到nextMarker,从上一次listObjects读到的最后一个文件的下一个文件开始继续获取文件列表
348
            $objectList = $listObjectInfo->getObjectList(); // 文件列表
349
            $prefixList = $listObjectInfo->getPrefixList(); // 目录列表
350
351
            if (!empty($objectList)) {
352
                foreach ($objectList as $objectInfo) {
353
354
                    $object['Prefix']       = $dirname;
355
                    $object['Key']          = $objectInfo->getKey();
356
                    $object['LastModified'] = $objectInfo->getLastModified();
357
                    $object['eTag']         = $objectInfo->getETag();
358
                    $object['Type']         = $objectInfo->getType();
359
                    $object['Size']         = $objectInfo->getSize();
360
                    $object['StorageClass'] = $objectInfo->getStorageClass();
361
362
                    $result['objects'][] = $object;
363
                }
364
            }else{
365
                $result["objects"] = [];
366
            }
367
368
            if (!empty($prefixList)) {
369
                foreach ($prefixList as $prefixInfo) {
370
                    $result['prefix'][] = $prefixInfo->getPrefix();
371
                }
372
            }else{
373
                $result['prefix'] = [];
374
            }
375
376
            //递归查询子目录所有文件
377
            if($recursive){
378
                foreach( $result['prefix'] as $pfix){
379
                    $next  =  $this->listDirObjects($pfix , $recursive);
380
                    $result["objects"] = array_merge($result['objects'], $next["objects"]);
381
                }
382
            }
383
384
            //没有更多结果了
385
            if ($nextMarker === '') {
386
                break;
387
            }
388
        }
389
390
        return $result;
391
    }
392
393
    /**
394
     * {@inheritdoc}
395
     */
396
    public function createDir($dirname, Config $config)
397
    {
398
        $object = $this->applyPathPrefix($dirname);
399
        $options = $this->getOptionsFromConfig($config);
400
401
        try {
402
            $this->client->createObjectDir($this->bucket, $object, $options);
403
        } catch (OssException $e) {
404
            $this->logErr(__FUNCTION__, $e);
405
            return false;
406
        }
407
408
        return ['path' => $dirname, 'type' => 'dir'];
409
    }
410
411
    /**
412
     * {@inheritdoc}
413
     */
414
    public function setVisibility($path, $visibility)
415
    {
416
        $object = $this->applyPathPrefix($path);
417
        $acl = ( $visibility === AdapterInterface::VISIBILITY_PUBLIC ) ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE;
418
419
        $this->client->putObjectAcl($this->bucket, $object, $acl);
420
421
        return compact('visibility');
422
    }
423
424
    /**
425
     * {@inheritdoc}
426
     */
427
    public function has($path)
428
    {
429
        $object = $this->applyPathPrefix($path);
430
431
        return $this->client->doesObjectExist($this->bucket, $object);
432
    }
433
434
    /**
435
     * {@inheritdoc}
436
     */
437
    public function read($path)
438
    {
439
        $result = $this->readObject($path);
440
        $result['contents'] = (string) $result['raw_contents'];
441
        unset($result['raw_contents']);
442
        return $result;
443
    }
444
445
    /**
446
     * {@inheritdoc}
447
     */
448
    public function readStream($path)
449
    {
450
        $result = $this->readObject($path);
451
        if (is_resource($result['raw_contents'])) {
452
            $result['stream'] = $result['raw_contents'];
453
            $result['raw_contents']->detachStream();
454
        } else {
455
            $result['stream'] = fopen('php://temp', 'r+');
456
            fwrite($result['stream'], $result['raw_contents']);
457
        }
458
        rewind($result['stream']);
459
        // Ensure the EntityBody object destruction doesn't close the stream
460
        unset($result['raw_contents']);
461
        return $result;
462
    }
463
464
    /**
465
     * Read an object from the OssClient.
466
     *
467
     * @param string $path
468
     *
469
     * @return array
470
     */
471
    protected function readObject($path)
472
    {
473
        $object = $this->applyPathPrefix($path);
474
475
        $result['Body'] = $this->client->getObject($this->bucket, $object);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.
Loading history...
476
        $result = array_merge($result, ['type' => 'file']);
477
        return $this->normalizeResponse($result, $path);
478
    }
479
480
    /**
481
     * {@inheritdoc}
482
     */
483
    public function listContents($directory = '', $recursive = false)
484
    {
485
        $dirObjects = $this->listDirObjects($directory, true);
486
        $contents = $dirObjects["objects"];
487
488
        $result = array_map([$this, 'normalizeResponse'], $contents);
489
        $result = array_filter($result, function ($value) {
490
            return $value['path'] !== false;
491
        });
492
493
        return Util::emulateDirectories($result);
494
    }
495
496
    /**
497
     * {@inheritdoc}
498
     */
499
    public function getMetadata($path)
500
    {
501
        $object = $this->applyPathPrefix($path);
502
503
        try {
504
            $objectMeta = $this->client->getObjectMeta($this->bucket, $object);
505
        } catch (OssException $e) {
506
            $this->logErr(__FUNCTION__, $e);
507
            return false;
508
        }
509
510
        return $objectMeta;
511
    }
512
513
    /**
514
     * {@inheritdoc}
515
     */
516
    public function getSize($path)
517
    {
518
        $object = $this->getMetadata($path);
519
        $object['size'] = $object['content-length'];
520
        return $object;
521
    }
522
523
    /**
524
     * {@inheritdoc}
525
     */
526
    public function getMimetype($path)
527
    {
528
        if( $object = $this->getMetadata($path))
529
            $object['mimetype'] = $object['content-type'];
530
        return $object;
531
    }
532
533
    /**
534
     * {@inheritdoc}
535
     */
536
    public function getTimestamp($path)
537
    {
538
        if( $object = $this->getMetadata($path))
539
            $object['timestamp'] = strtotime( $object['last-modified'] );
540
        return $object;
541
    }
542
543
    /**
544
     * {@inheritdoc}
545
     */
546
    public function getVisibility($path)
547
    {
548
        $object = $this->applyPathPrefix($path);
549
        try {
550
            $acl = $this->client->getObjectAcl($this->bucket, $object);
551
        } catch (OssException $e) {
552
            $this->logErr(__FUNCTION__, $e);
553
            return false;
554
        }
555
556
        if ($acl == OssClient::OSS_ACL_TYPE_PUBLIC_READ ){
557
            $res['visibility'] = AdapterInterface::VISIBILITY_PUBLIC;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Loading history...
558
        }else{
559
            $res['visibility'] = AdapterInterface::VISIBILITY_PRIVATE;
560
        }
561
562
        return $res;
563
    }
564
565
566
    /**
567
     * @param $path
568
     *
569
     * @return string
570
     */
571
    public function getUrl( $path )
572
    {
573
        if (!$this->has($path)) throw new FileNotFoundException($path.' not found');
574
        return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/');
575
    }
576
    
577
    
578
    /**
579
     * @param $path
580
     * @param $expire
581
     * @param $options
582
     * @return string
583
     * @throws FileNotFoundException
584
     * @throws OssException
585
     */
586
    public function getTemporaryUrl($path, $expire, $options) {
587
        if (!$this->has($path))
588
            throw new FileNotFoundException($path.' not found');
589
        $method = OssClient::OSS_HTTP_GET;
590
        if (Arr::has($options, OssClient::OSS_METHOD)) {
0 ignored issues
show
Bug introduced by
The type Jacobcyl\AliOSS\Arr was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
591
            $method = $options['method'];
592
        }
593
        return $this->getClient()
594
            ->signUrl(
595
                $this->getBucket(),
596
                $path,
597
                now()->diffInSeconds($expire),
0 ignored issues
show
Bug introduced by
The function now was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

597
                /** @scrutinizer ignore-call */ 
598
                now()->diffInSeconds($expire),
Loading history...
598
                $method,
599
                $options
600
            );
601
    }
602
    
603
604
    /**
605
     * The the ACL visibility.
606
     *
607
     * @param string $path
608
     *
609
     * @return string
610
     */
611
    protected function getObjectACL($path)
612
    {
613
        $metadata = $this->getVisibility($path);
614
615
        return $metadata['visibility'] === AdapterInterface::VISIBILITY_PUBLIC ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE;
616
    }
617
618
    /**
619
     * Normalize a result from OSS.
620
     *
621
     * @param array  $object
622
     * @param string $path
623
     *
624
     * @return array file metadata
625
     */
626
    protected function normalizeResponse(array $object, $path = null)
627
    {
628
        $result = ['path' => $path ?: $this->removePathPrefix(isset($object['Key']) ? $object['Key'] : $object['Prefix'])];
629
        $result['dirname'] = Util::dirname($result['path']);
630
631
        if (isset($object['LastModified'])) {
632
            $result['timestamp'] = strtotime($object['LastModified']);
633
        }
634
635
        if (substr($result['path'], -1) === '/') {
636
            $result['type'] = 'dir';
637
            $result['path'] = rtrim($result['path'], '/');
638
639
            return $result;
640
        }
641
642
        $result = array_merge($result, Util::map($object, static::$resultMap), ['type' => 'file']);
643
644
        return $result;
645
    }
646
647
    /**
648
     * Get options for a OSS call. done
649
     *
650
     * @param array  $options
651
     *
652
     * @return array OSS options
653
     */
654
    protected function getOptions(array $options = [], Config $config = null)
655
    {
656
        $options = array_merge($this->options, $options);
657
658
        if ($config) {
659
            $options = array_merge($options, $this->getOptionsFromConfig($config));
660
        }
661
662
        return array(OssClient::OSS_HEADERS => $options);
663
    }
664
665
    /**
666
     * Retrieve options from a Config instance. done
667
     *
668
     * @param Config $config
669
     *
670
     * @return array
671
     */
672
    protected function getOptionsFromConfig(Config $config)
673
    {
674
        $options = [];
675
676
        foreach (static::$metaOptions as $option) {
677
            if (! $config->has($option)) {
678
                continue;
679
            }
680
            $options[static::$metaMap[$option]] = $config->get($option);
681
        }
682
683
        if ($visibility = $config->get('visibility')) {
684
            // For local reference
685
            // $options['visibility'] = $visibility;
686
            // For external reference
687
            $options['x-oss-object-acl'] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE;
688
        }
689
690
        if ($mimetype = $config->get('mimetype')) {
691
            // For local reference
692
            // $options['mimetype'] = $mimetype;
693
            // For external reference
694
            $options['Content-Type'] = $mimetype;
695
        }
696
697
        return $options;
698
    }
699
700
    /**
701
     * @param $fun string function name : __FUNCTION__
702
     * @param $e
703
     */
704
    protected function logErr($fun, $e){
705
        if( $this->debug ){
706
            Log::error($fun . ": FAILED");
707
            Log::error($e->getMessage());
708
        }
709
    }
710
}
711