@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | $object = $this->applyPathPrefix($path); |
| 149 | 149 | $options = $this->getOptions($this->options, $config); |
| 150 | 150 | |
| 151 | - if (! isset($options[OssClient::OSS_LENGTH])) { |
|
| 151 | + if (!isset($options[OssClient::OSS_LENGTH])) { |
|
| 152 | 152 | $options[OssClient::OSS_LENGTH] = Util::contentSize($contents); |
| 153 | 153 | } |
| 154 | - if (! isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 154 | + if (!isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 155 | 155 | $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, $contents); |
| 156 | 156 | } |
| 157 | 157 | try { |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | return $this->write($path, $contents, $config); |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - public function writeFile($path, $filePath, Config $config){ |
|
| 183 | + public function writeFile($path, $filePath, Config $config) { |
|
| 184 | 184 | $object = $this->applyPathPrefix($path); |
| 185 | 185 | $options = $this->getOptions($this->options, $config); |
| 186 | 186 | |
| 187 | 187 | $options[OssClient::OSS_CHECK_MD5] = true; |
| 188 | 188 | |
| 189 | - if (! isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 189 | + if (!isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 190 | 190 | $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, ''); |
| 191 | 191 | } |
| 192 | 192 | try { |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public function update($path, $contents, Config $config) |
| 211 | 211 | { |
| 212 | - if (! $config->has('visibility') && ! $config->has('ACL')) { |
|
| 212 | + if (!$config->has('visibility') && !$config->has('ACL')) { |
|
| 213 | 213 | $config->set(static::$metaMap['ACL'], $this->getObjectACL($path)); |
| 214 | 214 | } |
| 215 | 215 | // $this->delete($path); |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | public function rename($path, $newpath) |
| 238 | 238 | { |
| 239 | - if (! $this->copy($path, $newpath)){ |
|
| 239 | + if (!$this->copy($path, $newpath)) { |
|
| 240 | 240 | return false; |
| 241 | 241 | } |
| 242 | 242 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | { |
| 251 | 251 | $object = $this->applyPathPrefix($path); |
| 252 | 252 | $newObject = $this->applyPathPrefix($newpath); |
| 253 | - try{ |
|
| 253 | + try { |
|
| 254 | 254 | $this->client->copyObject($this->bucket, $object, $this->bucket, $newObject); |
| 255 | 255 | } catch (OssException $e) { |
| 256 | 256 | $this->logErr(__FUNCTION__, $e); |
@@ -268,14 +268,14 @@ discard block |
||
| 268 | 268 | $bucket = $this->bucket; |
| 269 | 269 | $object = $this->applyPathPrefix($path); |
| 270 | 270 | |
| 271 | - try{ |
|
| 271 | + try { |
|
| 272 | 272 | $this->client->deleteObject($bucket, $object); |
| 273 | - }catch (OssException $e) { |
|
| 273 | + } catch (OssException $e) { |
|
| 274 | 274 | $this->logErr(__FUNCTION__, $e); |
| 275 | 275 | return false; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - return ! $this->has($path); |
|
| 278 | + return !$this->has($path); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -286,9 +286,9 @@ discard block |
||
| 286 | 286 | $dirname = rtrim($this->applyPathPrefix($dirname), '/').'/'; |
| 287 | 287 | $dirObjects = $this->listDirObjects($dirname, true); |
| 288 | 288 | |
| 289 | - if(count($dirObjects['objects']) > 0 ){ |
|
| 289 | + if (count($dirObjects['objects']) > 0) { |
|
| 290 | 290 | |
| 291 | - foreach($dirObjects['objects'] as $object) |
|
| 291 | + foreach ($dirObjects['objects'] as $object) |
|
| 292 | 292 | { |
| 293 | 293 | $objects[] = $object['Key']; |
| 294 | 294 | } |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * @return mixed |
| 320 | 320 | * @throws OssException |
| 321 | 321 | */ |
| 322 | - public function listDirObjects($dirname = '', $recursive = false) |
|
| 322 | + public function listDirObjects($dirname = '', $recursive = false) |
|
| 323 | 323 | { |
| 324 | 324 | $delimiter = '/'; |
| 325 | 325 | $nextMarker = ''; |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | //存储结果 |
| 329 | 329 | $result = []; |
| 330 | 330 | |
| 331 | - while(true){ |
|
| 331 | + while (true) { |
|
| 332 | 332 | $options = [ |
| 333 | 333 | 'delimiter' => $delimiter, |
| 334 | 334 | 'prefix' => $dirname, |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | $result['objects'][] = $object; |
| 363 | 363 | } |
| 364 | - }else{ |
|
| 364 | + } else { |
|
| 365 | 365 | $result["objects"] = []; |
| 366 | 366 | } |
| 367 | 367 | |
@@ -369,14 +369,14 @@ discard block |
||
| 369 | 369 | foreach ($prefixList as $prefixInfo) { |
| 370 | 370 | $result['prefix'][] = $prefixInfo->getPrefix(); |
| 371 | 371 | } |
| 372 | - }else{ |
|
| 372 | + } else { |
|
| 373 | 373 | $result['prefix'] = []; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | //递归查询子目录所有文件 |
| 377 | - if($recursive){ |
|
| 378 | - foreach( $result['prefix'] as $pfix){ |
|
| 379 | - $next = $this->listDirObjects($pfix , $recursive); |
|
| 377 | + if ($recursive) { |
|
| 378 | + foreach ($result['prefix'] as $pfix) { |
|
| 379 | + $next = $this->listDirObjects($pfix, $recursive); |
|
| 380 | 380 | $result["objects"] = array_merge($result['objects'], $next["objects"]); |
| 381 | 381 | } |
| 382 | 382 | } |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | public function setVisibility($path, $visibility) |
| 415 | 415 | { |
| 416 | 416 | $object = $this->applyPathPrefix($path); |
| 417 | - $acl = ( $visibility === AdapterInterface::VISIBILITY_PUBLIC ) ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE; |
|
| 417 | + $acl = ($visibility === AdapterInterface::VISIBILITY_PUBLIC) ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE; |
|
| 418 | 418 | |
| 419 | 419 | $this->client->putObjectAcl($this->bucket, $object, $acl); |
| 420 | 420 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | public function read($path) |
| 438 | 438 | { |
| 439 | 439 | $result = $this->readObject($path); |
| 440 | - $result['contents'] = (string) $result['raw_contents']; |
|
| 440 | + $result['contents'] = (string)$result['raw_contents']; |
|
| 441 | 441 | unset($result['raw_contents']); |
| 442 | 442 | return $result; |
| 443 | 443 | } |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | $contents = $dirObjects["objects"]; |
| 483 | 483 | |
| 484 | 484 | $result = array_map([$this, 'normalizeResponse'], $contents); |
| 485 | - $result = array_filter($result, function ($value) { |
|
| 485 | + $result = array_filter($result, function($value) { |
|
| 486 | 486 | return $value['path'] !== false; |
| 487 | 487 | }); |
| 488 | 488 | |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | */ |
| 522 | 522 | public function getMimetype($path) |
| 523 | 523 | { |
| 524 | - if( $object = $this->getMetadata($path)) |
|
| 524 | + if ($object = $this->getMetadata($path)) |
|
| 525 | 525 | $object['mimetype'] = $object['content-type']; |
| 526 | 526 | return $object; |
| 527 | 527 | } |
@@ -531,8 +531,8 @@ discard block |
||
| 531 | 531 | */ |
| 532 | 532 | public function getTimestamp($path) |
| 533 | 533 | { |
| 534 | - if( $object = $this->getMetadata($path)) |
|
| 535 | - $object['timestamp'] = strtotime( $object['last-modified'] ); |
|
| 534 | + if ($object = $this->getMetadata($path)) |
|
| 535 | + $object['timestamp'] = strtotime($object['last-modified']); |
|
| 536 | 536 | return $object; |
| 537 | 537 | } |
| 538 | 538 | |
@@ -549,9 +549,9 @@ discard block |
||
| 549 | 549 | return false; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - if ($acl == OssClient::OSS_ACL_TYPE_PUBLIC_READ ){ |
|
| 552 | + if ($acl == OssClient::OSS_ACL_TYPE_PUBLIC_READ) { |
|
| 553 | 553 | $res['visibility'] = AdapterInterface::VISIBILITY_PUBLIC; |
| 554 | - }else{ |
|
| 554 | + } else { |
|
| 555 | 555 | $res['visibility'] = AdapterInterface::VISIBILITY_PRIVATE; |
| 556 | 556 | } |
| 557 | 557 | |
@@ -564,10 +564,10 @@ discard block |
||
| 564 | 564 | * |
| 565 | 565 | * @return string |
| 566 | 566 | */ |
| 567 | - public function getUrl( $path ) |
|
| 567 | + public function getUrl($path) |
|
| 568 | 568 | { |
| 569 | 569 | if (!$this->has($path)) throw new FileNotFoundException($path.' not found'); |
| 570 | - return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/'); |
|
| 570 | + return ($this->ssl ? 'https://' : 'http://').($this->isCname ? ($this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain) : $this->bucket.'.'.$this->endPoint).'/'.ltrim($path, '/'); |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | $options = []; |
| 644 | 644 | |
| 645 | 645 | foreach (static::$metaOptions as $option) { |
| 646 | - if (! $config->has($option)) { |
|
| 646 | + if (!$config->has($option)) { |
|
| 647 | 647 | continue; |
| 648 | 648 | } |
| 649 | 649 | $options[static::$metaMap[$option]] = $config->get($option); |
@@ -670,9 +670,9 @@ discard block |
||
| 670 | 670 | * @param $fun string function name : __FUNCTION__ |
| 671 | 671 | * @param $e |
| 672 | 672 | */ |
| 673 | - protected function logErr($fun, $e){ |
|
| 674 | - if( $this->debug ){ |
|
| 675 | - Log::error($fun . ": FAILED"); |
|
| 673 | + protected function logErr($fun, $e) { |
|
| 674 | + if ($this->debug) { |
|
| 675 | + Log::error($fun.": FAILED"); |
|
| 676 | 676 | Log::error($e->getMessage()); |
| 677 | 677 | } |
| 678 | 678 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | |
| 271 | 271 | try{ |
| 272 | 272 | $this->client->deleteObject($bucket, $object); |
| 273 | - }catch (OssException $e) { |
|
| 273 | + } catch (OssException $e) { |
|
| 274 | 274 | $this->logErr(__FUNCTION__, $e); |
| 275 | 275 | return false; |
| 276 | 276 | } |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | $result['objects'][] = $object; |
| 363 | 363 | } |
| 364 | - }else{ |
|
| 364 | + } else{ |
|
| 365 | 365 | $result["objects"] = []; |
| 366 | 366 | } |
| 367 | 367 | |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | foreach ($prefixList as $prefixInfo) { |
| 370 | 370 | $result['prefix'][] = $prefixInfo->getPrefix(); |
| 371 | 371 | } |
| 372 | - }else{ |
|
| 372 | + } else{ |
|
| 373 | 373 | $result['prefix'] = []; |
| 374 | 374 | } |
| 375 | 375 | |
@@ -521,8 +521,9 @@ discard block |
||
| 521 | 521 | */ |
| 522 | 522 | public function getMimetype($path) |
| 523 | 523 | { |
| 524 | - if( $object = $this->getMetadata($path)) |
|
| 525 | - $object['mimetype'] = $object['content-type']; |
|
| 524 | + if( $object = $this->getMetadata($path)) { |
|
| 525 | + $object['mimetype'] = $object['content-type']; |
|
| 526 | + } |
|
| 526 | 527 | return $object; |
| 527 | 528 | } |
| 528 | 529 | |
@@ -531,8 +532,9 @@ discard block |
||
| 531 | 532 | */ |
| 532 | 533 | public function getTimestamp($path) |
| 533 | 534 | { |
| 534 | - if( $object = $this->getMetadata($path)) |
|
| 535 | - $object['timestamp'] = strtotime( $object['last-modified'] ); |
|
| 535 | + if( $object = $this->getMetadata($path)) { |
|
| 536 | + $object['timestamp'] = strtotime( $object['last-modified'] ); |
|
| 537 | + } |
|
| 536 | 538 | return $object; |
| 537 | 539 | } |
| 538 | 540 | |
@@ -551,7 +553,7 @@ discard block |
||
| 551 | 553 | |
| 552 | 554 | if ($acl == OssClient::OSS_ACL_TYPE_PUBLIC_READ ){ |
| 553 | 555 | $res['visibility'] = AdapterInterface::VISIBILITY_PUBLIC; |
| 554 | - }else{ |
|
| 556 | + } else{ |
|
| 555 | 557 | $res['visibility'] = AdapterInterface::VISIBILITY_PRIVATE; |
| 556 | 558 | } |
| 557 | 559 | |
@@ -566,7 +568,9 @@ discard block |
||
| 566 | 568 | */ |
| 567 | 569 | public function getUrl( $path ) |
| 568 | 570 | { |
| 569 | - if (!$this->has($path)) throw new FileNotFoundException($path.' not found'); |
|
| 571 | + if (!$this->has($path)) { |
|
| 572 | + throw new FileNotFoundException($path.' not found'); |
|
| 573 | + } |
|
| 570 | 574 | return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/'); |
| 571 | 575 | } |
| 572 | 576 | |
@@ -33,15 +33,15 @@ |
||
| 33 | 33 | * @return string 返回 url 链接地址 |
| 34 | 34 | * @throws \Exception |
| 35 | 35 | */ |
| 36 | - public function handle($path, $action = 'resize', $option = ['m' => 'fixed','h' => '100','w' => '100']){ |
|
| 37 | - if(empty($action) || empty($option)){ |
|
| 36 | + public function handle($path, $action = 'resize', $option = ['m' => 'fixed', 'h' => '100', 'w' => '100']) { |
|
| 37 | + if (empty($action) || empty($option)) { |
|
| 38 | 38 | throw new \Exception('操作名称和操作参数不能为空!'); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $url = $this->filesystem->getAdapter()->getUrl($path); |
| 42 | 42 | |
| 43 | 43 | $param = ''; |
| 44 | - foreach ($option as $key => $value){ |
|
| 44 | + foreach ($option as $key => $value) { |
|
| 45 | 45 | $param .= ','.$key.'_'.$value; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | return 'putRemoteFile'; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public function handle($path, $remoteUrl, array $options = []){ |
|
| 23 | + public function handle($path, $remoteUrl, array $options = []) { |
|
| 24 | 24 | $config = new Config($options); |
| 25 | 25 | if (method_exists($this->filesystem, 'getConfig')) { |
| 26 | 26 | $config->setFallback($this->filesystem->getConfig()); |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | return 'putFile'; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public function handle($path, $filePath, array $options = []){ |
|
| 27 | + public function handle($path, $filePath, array $options = []) { |
|
| 28 | 28 | $config = new Config($options); |
| 29 | 29 | if (method_exists($this->filesystem, 'getConfig')) { |
| 30 | 30 | $config->setFallback($this->filesystem->getConfig()); |
@@ -24,8 +24,8 @@ |
||
| 24 | 24 | return 'signUrl'; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public function handle($path, $timeout = 600){ |
|
| 27 | + public function handle($path, $timeout = 600) { |
|
| 28 | 28 | if (!$this->filesystem->getAdapter()->has($path)) throw new FileNotFoundException($path.' not found'); |
| 29 | - return $this->filesystem->getAdapter()->getClient()->signUrl($this->filesystem->getAdapter()->getBucket(),$path,$timeout); |
|
| 29 | + return $this->filesystem->getAdapter()->getClient()->signUrl($this->filesystem->getAdapter()->getBucket(), $path, $timeout); |
|
| 30 | 30 | } |
| 31 | 31 | } |
@@ -25,7 +25,9 @@ |
||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function handle($path, $timeout = 600){ |
| 28 | - if (!$this->filesystem->getAdapter()->has($path)) throw new FileNotFoundException($path.' not found'); |
|
| 28 | + if (!$this->filesystem->getAdapter()->has($path)) { |
|
| 29 | + throw new FileNotFoundException($path.' not found'); |
|
| 30 | + } |
|
| 29 | 31 | return $this->filesystem->getAdapter()->getClient()->signUrl($this->filesystem->getAdapter()->getBucket(),$path,$timeout); |
| 30 | 32 | } |
| 31 | 33 | } |
@@ -43,15 +43,15 @@ |
||
| 43 | 43 | $debug = empty($config['debug']) ? false : $config['debug']; |
| 44 | 44 | |
| 45 | 45 | $endPoint = $config['endpoint']; // 默认作为外部节点 |
| 46 | - $epInternal= $isCname?$cdnDomain:(empty($config['endpoint_internal']) ? $endPoint : $config['endpoint_internal']); // 内部节点 |
|
| 46 | + $epInternal = $isCname ? $cdnDomain : (empty($config['endpoint_internal']) ? $endPoint : $config['endpoint_internal']); // 内部节点 |
|
| 47 | 47 | |
| 48 | - if($debug) Log::debug('OSS config:', $config); |
|
| 48 | + if ($debug) Log::debug('OSS config:', $config); |
|
| 49 | 49 | |
| 50 | 50 | $client = new OssClient($accessId, $accessKey, $epInternal, $isCname); |
| 51 | 51 | $adapter = new AliOssAdapter($client, $bucket, $endPoint, $ssl, $isCname, $debug, $cdnDomain); |
| 52 | 52 | |
| 53 | 53 | //Log::debug($client); |
| 54 | - $filesystem = new Filesystem($adapter); |
|
| 54 | + $filesystem = new Filesystem($adapter); |
|
| 55 | 55 | |
| 56 | 56 | $filesystem->addPlugin(new PutFile()); |
| 57 | 57 | $filesystem->addPlugin(new PutRemoteFile()); |
@@ -45,7 +45,9 @@ |
||
| 45 | 45 | $endPoint = $config['endpoint']; // 默认作为外部节点 |
| 46 | 46 | $epInternal= $isCname?$cdnDomain:(empty($config['endpoint_internal']) ? $endPoint : $config['endpoint_internal']); // 内部节点 |
| 47 | 47 | |
| 48 | - if($debug) Log::debug('OSS config:', $config); |
|
| 48 | + if($debug) { |
|
| 49 | + Log::debug('OSS config:', $config); |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | $client = new OssClient($accessId, $accessKey, $epInternal, $isCname); |
| 51 | 53 | $adapter = new AliOssAdapter($client, $bucket, $endPoint, $ssl, $isCname, $debug, $cdnDomain); |