JimChenWYU /
flysystem-aliyun-oss
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the jimchen/flysystem-aliyun-oss. |
||
| 5 | * |
||
| 6 | * (c) JimChen <[email protected]> |
||
| 7 | * |
||
| 8 | * This source file is subject to the MIT license that is bundled. |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace JimChen\Flysystem\AliyunOss; |
||
| 12 | |||
| 13 | use GuzzleHttp\Psr7; |
||
| 14 | use League\Flysystem\Adapter\AbstractAdapter; |
||
| 15 | use League\Flysystem\Adapter\CanOverwriteFiles; |
||
| 16 | use League\Flysystem\Config; |
||
| 17 | use League\Flysystem\Util; |
||
| 18 | use OSS\Core\OssException; |
||
| 19 | use OSS\OssClient; |
||
| 20 | |||
| 21 | class AliyunOssAdapter extends AbstractAdapter implements CanOverwriteFiles |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var OssClient |
||
| 25 | */ |
||
| 26 | protected $ossClient; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $bucket; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | protected $options = []; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Constructor. |
||
| 40 | * |
||
| 41 | * @param OssClient $ossClient |
||
| 42 | * @param string $bucket |
||
| 43 | * @param string $prefix |
||
| 44 | 86 | * @param array $options |
|
| 45 | */ |
||
| 46 | 86 | public function __construct(OssClient $ossClient, $bucket, $prefix = '', array $options = []) |
|
| 47 | 86 | { |
|
| 48 | 86 | $this->ossClient = $ossClient; |
|
| 49 | 86 | $this->bucket = $bucket; |
|
| 50 | 86 | $this->setPathPrefix($prefix); |
|
| 51 | $this->options = $options; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Get the OssClient bucket. |
||
| 56 | * |
||
| 57 | 4 | * @return string |
|
| 58 | */ |
||
| 59 | 4 | public function getBucket() |
|
| 60 | { |
||
| 61 | return $this->bucket; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Set the OssClient bucket. |
||
| 66 | * |
||
| 67 | 2 | * @param string $bucket |
|
| 68 | */ |
||
| 69 | 2 | public function setBucket($bucket) |
|
| 70 | 2 | { |
|
| 71 | $this->bucket = $bucket; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Get the OssClient instance. |
||
| 76 | * |
||
| 77 | 2 | * @return OssClient |
|
| 78 | */ |
||
| 79 | 2 | public function getClient() |
|
| 80 | { |
||
| 81 | return $this->ossClient; |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Write a new file. |
||
| 86 | * |
||
| 87 | * @param string $path |
||
| 88 | * @param string $contents |
||
| 89 | * @param Config $config Config object |
||
| 90 | * |
||
| 91 | 4 | * @return array |
|
| 92 | */ |
||
| 93 | 4 | public function write($path, $contents, Config $config) |
|
| 94 | { |
||
| 95 | return $this->upload($path, $contents, $config); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Update a file. |
||
| 100 | * |
||
| 101 | * @param string $path |
||
| 102 | * @param string $contents |
||
| 103 | * @param Config $config Config object |
||
| 104 | * |
||
| 105 | 2 | * @return array |
|
| 106 | */ |
||
| 107 | 2 | public function update($path, $contents, Config $config) |
|
| 108 | { |
||
| 109 | return $this->upload($path, $contents, $config); |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Write a new file using a stream. |
||
| 114 | * |
||
| 115 | * @param string $path |
||
| 116 | * @param resource $resource |
||
| 117 | * @param Config $config Config object |
||
| 118 | * |
||
| 119 | 2 | * @return array|false false on failure file meta data on success |
|
| 120 | */ |
||
| 121 | 2 | public function writeStream($path, $resource, Config $config) |
|
| 122 | { |
||
| 123 | return $this->upload($path, $resource, $config); |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Update a file using a stream. |
||
| 128 | * |
||
| 129 | * @param string $path |
||
| 130 | * @param resource $resource |
||
| 131 | * @param Config $config Config object |
||
| 132 | * |
||
| 133 | 2 | * @return array|false false on failure file meta data on success |
|
| 134 | */ |
||
| 135 | 2 | public function updateStream($path, $resource, Config $config) |
|
| 136 | { |
||
| 137 | return $this->upload($path, $resource, $config); |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Rename a file. |
||
| 142 | * |
||
| 143 | * @param string $path |
||
| 144 | * @param string $newpath |
||
| 145 | * |
||
| 146 | 4 | * @return bool |
|
| 147 | */ |
||
| 148 | 4 | public function rename($path, $newpath) |
|
| 149 | 2 | { |
|
| 150 | if (!$this->copy($path, $newpath)) { |
||
| 151 | return false; |
||
| 152 | 2 | } |
|
| 153 | |||
| 154 | return $this->delete($path); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Copy a file. |
||
| 159 | * |
||
| 160 | * @param string $path |
||
| 161 | * @param string $newpath |
||
| 162 | * |
||
| 163 | 8 | * @return bool |
|
| 164 | */ |
||
| 165 | public function copy($path, $newpath) |
||
| 166 | 8 | { |
|
| 167 | 8 | try { |
|
| 168 | 8 | $this->ossClient->copyObject( |
|
| 169 | 8 | $this->bucket, |
|
| 170 | 8 | $this->applyPathPrefix($path), |
|
| 171 | 8 | $this->bucket, |
|
| 172 | 8 | $this->applyPathPrefix($newpath), |
|
| 173 | 8 | $this->options |
|
| 174 | 4 | ); |
|
| 175 | } catch (OssException $e) { |
||
| 176 | return false; |
||
| 177 | 4 | } |
|
| 178 | |||
| 179 | return true; |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Delete a file. |
||
| 184 | * |
||
| 185 | * @param string $path |
||
| 186 | * |
||
| 187 | 4 | * @return bool |
|
| 188 | */ |
||
| 189 | 4 | public function delete($path) |
|
| 190 | { |
||
| 191 | 4 | $object = $this->applyPathPrefix($path); |
|
| 192 | |||
| 193 | 4 | $this->ossClient->deleteObject($this->bucket, $object, $this->options); |
|
| 194 | |||
| 195 | return !$this->has($path); |
||
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Delete a directory. |
||
| 200 | * |
||
| 201 | * @param string $dirname |
||
| 202 | * |
||
| 203 | 2 | * @return bool |
|
| 204 | */ |
||
| 205 | 2 | public function deleteDir($dirname) |
|
| 206 | { |
||
| 207 | return false; |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Create a directory. |
||
| 212 | * |
||
| 213 | * @param string $dirname directory name |
||
| 214 | * @param Config $config |
||
| 215 | * |
||
| 216 | 4 | * @return array|false |
|
| 217 | */ |
||
| 218 | public function createDir($dirname, Config $config) |
||
| 219 | 4 | { |
|
| 220 | 4 | try { |
|
| 221 | $key = $this->applyPathPrefix($dirname); |
||
| 222 | 4 | $options = $this->getOptionsFromConfig($config); |
|
| 223 | 4 | ||
| 224 | 2 | $response = $this->ossClient->createObjectDir($this->bucket, rtrim($key, '/'), $options); |
|
|
0 ignored issues
–
show
|
|||
| 225 | } catch (OssException $e) { |
||
| 226 | return false; |
||
| 227 | 2 | } |
|
| 228 | |||
| 229 | return $this->normalizeResponse($response, $key); |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Set the visibility for a file. |
||
| 234 | * |
||
| 235 | * @param string $path |
||
| 236 | * @param string $visibility |
||
| 237 | * |
||
| 238 | 6 | * @return array|false file meta data |
|
| 239 | */ |
||
| 240 | public function setVisibility($path, $visibility) |
||
| 241 | 6 | { |
|
| 242 | 6 | try { |
|
| 243 | 6 | $this->ossClient->putObjectAcl( |
|
| 244 | 6 | $this->bucket, |
|
| 245 | 6 | $this->applyPathPrefix($path), |
|
| 246 | 6 | in_array($visibility, OssClient::$OSS_ACL_TYPES) ? $visibility : 'default' |
|
|
0 ignored issues
–
show
The property
OSS_ACL_TYPES cannot be accessed from this context as it is declared private in class OSS\OssClient.
This check looks for access to properties that are not accessible from the current context. If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class. Loading history...
|
|||
| 247 | 2 | ); |
|
| 248 | } catch (OssException $e) { |
||
| 249 | return false; |
||
| 250 | 4 | } |
|
| 251 | |||
| 252 | return compact('path', 'visibility'); |
||
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Check whether a file exists. |
||
| 257 | * |
||
| 258 | * @param string $path |
||
| 259 | * |
||
| 260 | 12 | * @return bool |
|
| 261 | */ |
||
| 262 | 12 | public function has($path) |
|
| 263 | { |
||
| 264 | 12 | $location = $this->applyPathPrefix($path); |
|
| 265 | 2 | ||
| 266 | if ($this->ossClient->doesObjectExist($this->bucket, $location, $this->options)) { |
||
| 267 | return true; |
||
| 268 | 10 | } |
|
| 269 | |||
| 270 | return $this->doesDirectoryExist($location); |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Read a file. |
||
| 275 | * |
||
| 276 | * @param string $path |
||
| 277 | * |
||
| 278 | 6 | * @return array|false |
|
| 279 | */ |
||
| 280 | public function read($path) |
||
| 281 | 6 | { |
|
| 282 | try { |
||
| 283 | 2 | $response = $this->ossClient->getObject($this->bucket, $this->applyPathPrefix($path)); |
|
| 284 | 2 | ||
| 285 | 2 | return $this->normalizeResponse([ |
|
| 286 | 4 | 'contents' => $response, |
|
| 287 | 4 | ], $path); |
|
| 288 | } catch (OssException $e) { |
||
| 289 | return false; |
||
| 290 | } |
||
| 291 | } |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Read a file as a stream. |
||
| 295 | * |
||
| 296 | * @param string $path |
||
| 297 | * |
||
| 298 | 4 | * @return array|false |
|
| 299 | */ |
||
| 300 | public function readStream($path) |
||
| 301 | 4 | { |
|
| 302 | 4 | try { |
|
| 303 | 2 | $object = $this->applyPathPrefix($path); |
|
| 304 | $url = $this->ossClient->signUrl($this->bucket, $object, 60, OssClient::OSS_HTTP_GET, $this->options); |
||
| 305 | 2 | $handle = fopen($url, 'r'); |
|
| 306 | 2 | ||
| 307 | 2 | return $this->normalizeResponse([ |
|
| 308 | 2 | 'stream' => $handle, |
|
| 309 | 2 | ], $path); |
|
| 310 | } catch (OssException $e) { |
||
| 311 | return false; |
||
| 312 | } |
||
| 313 | } |
||
| 314 | |||
| 315 | /** |
||
| 316 | * List contents of a directory. |
||
| 317 | * |
||
| 318 | * @param string $directory |
||
| 319 | * @param bool $recursive |
||
| 320 | * |
||
| 321 | 6 | * @return array|false |
|
| 322 | */ |
||
| 323 | 6 | public function listContents($directory = '', $recursive = false) |
|
| 324 | { |
||
| 325 | $prefix = $this->applyPathPrefix(rtrim($directory, '/').'/'); |
||
| 326 | 6 | ||
| 327 | 6 | $options = [ |
|
| 328 | 6 | OssClient::OSS_PREFIX => ltrim($prefix, '/'), |
|
| 329 | 6 | OssClient::OSS_MARKER => '', |
|
| 330 | OssClient::OSS_MAX_KEYS => 100, |
||
| 331 | 6 | ]; |
|
| 332 | 2 | ||
| 333 | 2 | if ($recursive) { |
|
| 334 | 4 | $options[OssClient::OSS_DELIMITER] = ''; |
|
| 335 | } else { |
||
| 336 | $options[OssClient::OSS_DELIMITER] = '/'; |
||
| 337 | } |
||
| 338 | 6 | ||
| 339 | 6 | $listing = $this->retrieveListing($options); |
|
| 340 | 2 | ||
| 341 | $normalizer = [$this, 'normalizeResponse']; |
||
| 342 | $normalized = array_map($normalizer, $listing); |
||
| 343 | 4 | ||
| 344 | 4 | return Util::emulateDirectories($normalized); |
|
| 345 | } |
||
| 346 | 4 | ||
| 347 | /** |
||
| 348 | * @param array $options |
||
| 349 | * |
||
| 350 | * @return array |
||
| 351 | * |
||
| 352 | * @throws OssException |
||
| 353 | */ |
||
| 354 | protected function retrieveListing(array $options) |
||
| 355 | 6 | { |
|
| 356 | $result = $this->ossClient->listObjects($this->bucket, $options); |
||
| 357 | 6 | $listing = []; |
|
| 358 | 4 | ||
| 359 | foreach ($result->getObjectList() as $object) { |
||
| 360 | 4 | $listing[] = [ |
|
| 361 | 4 | 'key' => $object->getKey(), |
|
| 362 | 4 | 'last_modified' => $object->getLastModified(), |
|
| 363 | 4 | 'etag' => $object->getETag(), |
|
| 364 | 4 | 'type' => $object->getType(), |
|
| 365 | 4 | 'size' => $object->getSize(), |
|
| 366 | 4 | 'storage_class' => $object->getStorageClass(), |
|
| 367 | 4 | ]; |
|
| 368 | } |
||
| 369 | 4 | ||
| 370 | foreach ($result->getPrefixList() as $object) { |
||
| 371 | 4 | $listing[] = [ |
|
| 372 | 4 | 'prefix' => $object->getPrefix(), |
|
| 373 | 4 | ]; |
|
| 374 | } |
||
| 375 | 4 | ||
| 376 | return $listing; |
||
| 377 | 4 | } |
|
| 378 | |||
| 379 | /** |
||
| 380 | * Get all the meta data of a file or directory. |
||
| 381 | * |
||
| 382 | * @param string $path |
||
| 383 | * |
||
| 384 | * @return array|false |
||
| 385 | */ |
||
| 386 | public function getMetadata($path) |
||
| 387 | 12 | { |
|
| 388 | $response = $this->getObjectMeta($path); |
||
| 389 | 12 | ||
| 390 | if (empty($response)) { |
||
| 391 | 10 | return false; |
|
| 392 | 10 | } |
|
| 393 | |||
| 394 | return $this->normalizeResponse($response, $path); |
||
| 395 | 8 | } |
|
| 396 | |||
| 397 | /** |
||
| 398 | * Get the size of a file. |
||
| 399 | * |
||
| 400 | * @param string $path |
||
| 401 | * |
||
| 402 | * @return array|false |
||
| 403 | */ |
||
| 404 | public function getSize($path) |
||
| 405 | 2 | { |
|
| 406 | if ($metaData = $this->getMetadata($path)) { |
||
| 407 | 2 | return $this->normalizeResponse([ |
|
| 408 | 2 | 'size' => $metaData['content-length'], |
|
| 409 | 2 | ], $path); |
|
| 410 | 2 | } |
|
| 411 | |||
| 412 | return false; |
||
| 413 | 2 | } |
|
| 414 | |||
| 415 | /** |
||
| 416 | * Get the mimetype of a file. |
||
| 417 | * |
||
| 418 | * @param string $path |
||
| 419 | * |
||
| 420 | * @return array|false |
||
| 421 | */ |
||
| 422 | public function getMimetype($path) |
||
| 423 | 2 | { |
|
| 424 | if ($metaData = $this->getMetadata($path)) { |
||
| 425 | 2 | $contentType = array_key_exists('content_type', |
|
| 426 | 2 | $metaData) ? $metaData['content_type'] : $metaData['info']['content_type']; |
|
| 427 | 2 | ||
| 428 | return [ |
||
| 429 | 'mimetype' => $contentType, |
||
| 430 | 2 | ]; |
|
| 431 | 2 | } |
|
| 432 | |||
| 433 | return false; |
||
| 434 | 2 | } |
|
| 435 | |||
| 436 | /** |
||
| 437 | * Get the last modified time of a file as a timestamp. |
||
| 438 | * |
||
| 439 | * @param string $path |
||
| 440 | * |
||
| 441 | * @return array|false |
||
| 442 | */ |
||
| 443 | public function getTimestamp($path) |
||
| 444 | 2 | { |
|
| 445 | if ($metaData = $this->getMetadata($path)) { |
||
| 446 | 2 | return $this->normalizeResponse([ |
|
| 447 | 2 | 'timestamp' => strtotime($metaData['last-modified']), |
|
| 448 | 2 | ], $path); |
|
| 449 | 2 | } |
|
| 450 | |||
| 451 | return false; |
||
| 452 | 2 | } |
|
| 453 | |||
| 454 | /** |
||
| 455 | * Get the visibility of a file. |
||
| 456 | * |
||
| 457 | * @param string $path |
||
| 458 | * |
||
| 459 | * @return array|false |
||
| 460 | */ |
||
| 461 | public function getVisibility($path) |
||
| 462 | 6 | { |
|
| 463 | try { |
||
| 464 | return [ |
||
| 465 | 'visibility' => $this->ossClient->getObjectAcl($this->bucket, $this->applyPathPrefix($path)), |
||
| 466 | 6 | ]; |
|
| 467 | 4 | } catch (OssException $e) { |
|
| 468 | 2 | return false; |
|
| 469 | 2 | } |
|
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * {@inheritdoc} |
||
| 474 | */ |
||
| 475 | public function applyPathPrefix($path) |
||
| 476 | 74 | { |
|
| 477 | return ltrim(parent::applyPathPrefix($path), '/'); |
||
| 478 | 74 | } |
|
| 479 | |||
| 480 | /** |
||
| 481 | * {@inheritdoc} |
||
| 482 | */ |
||
| 483 | public function setPathPrefix($prefix) |
||
| 484 | 86 | { |
|
| 485 | $prefix = ltrim($prefix, '/'); |
||
| 486 | 86 | ||
| 487 | parent::setPathPrefix($prefix); |
||
| 488 | 86 | } |
|
| 489 | 86 | ||
| 490 | /** |
||
| 491 | * Get the object meta. |
||
| 492 | * |
||
| 493 | * @param $path |
||
| 494 | * |
||
| 495 | * @return array|bool |
||
| 496 | */ |
||
| 497 | protected function getObjectMeta($path) |
||
| 498 | 12 | { |
|
| 499 | try { |
||
| 500 | return $this->ossClient->getObjectMeta($this->bucket, $this->applyPathPrefix($path)); |
||
| 501 | 12 | } catch (OssException $e) { |
|
| 502 | 12 | if (404 === $e->getHTTPStatus()) { |
|
| 503 | 12 | return false; |
|
| 504 | 10 | } |
|
| 505 | |||
| 506 | throw $e; |
||
| 507 | 2 | } |
|
| 508 | } |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Upload an object. |
||
| 512 | * |
||
| 513 | * @param string $path |
||
| 514 | * @param string|resource $body |
||
| 515 | * @param Config $config |
||
| 516 | * |
||
| 517 | * @return array|false |
||
| 518 | * |
||
| 519 | * @throws \InvalidArgumentException |
||
| 520 | */ |
||
| 521 | 10 | protected function upload($path, $body, Config $config) |
|
| 522 | { |
||
| 523 | 10 | $key = $this->applyPathPrefix($path); |
|
| 524 | |||
| 525 | try { |
||
| 526 | 10 | $options = $this->getOptionsFromConfig($config, [ |
|
| 527 | 10 | OssClient::OSS_LENGTH, |
|
| 528 | 10 | OssClient::OSS_CONTENT_TYPE, |
|
| 529 | 10 | OssClient::OSS_CALLBACK, |
|
| 530 | 10 | ]); |
|
| 531 | 10 | $response = $this->ossClient->putObject($this->bucket, $key, Psr7\stream_for($body)->getContents(), |
|
|
0 ignored issues
–
show
Are you sure the assignment to
$response is correct as $this->ossClient->putObj...etContents(), $options) (which targets OSS\OssClient::putObject()) seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 532 | 10 | $options); |
|
| 533 | 10 | } catch (OssException $e) { |
|
| 534 | 2 | return false; |
|
| 535 | } |
||
| 536 | |||
| 537 | 8 | return $this->normalizeResponse($response, $key); |
|
| 538 | } |
||
| 539 | |||
| 540 | /** |
||
| 541 | * Get options from the config. |
||
| 542 | * |
||
| 543 | * @param Config $config |
||
| 544 | * @param array $keys |
||
| 545 | * |
||
| 546 | * @return array |
||
| 547 | */ |
||
| 548 | 14 | protected function getOptionsFromConfig(Config $config, $keys = []) |
|
| 549 | { |
||
| 550 | 14 | $options = $this->options; |
|
| 551 | |||
| 552 | 14 | foreach ((array) $keys as $key) { |
|
| 553 | 10 | if ($value = $config->get($key)) { |
|
| 554 | $options[$key] = $value; |
||
| 555 | } |
||
| 556 | 14 | } |
|
| 557 | |||
| 558 | 14 | return $options; |
|
| 559 | } |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Normalize the object result array. |
||
| 563 | * |
||
| 564 | * @param array $response |
||
| 565 | * @param null $path |
||
| 566 | * |
||
| 567 | * @return array |
||
| 568 | */ |
||
| 569 | 26 | protected function normalizeResponse(array $response, $path = null) |
|
| 570 | { |
||
| 571 | $result = [ |
||
| 572 | 26 | 'path' => $path ?: $this->removePathPrefix( |
|
| 573 | 4 | isset($response['key']) ? $response['key'] : $response['prefix'] |
|
| 574 | 26 | ), |
|
| 575 | 26 | ]; |
|
| 576 | |||
| 577 | 26 | $result = array_merge($result, Util::pathinfo($result['path'])); |
|
| 578 | |||
| 579 | 26 | if ('/' === substr($result['path'], -1)) { |
|
| 580 | 4 | $result['type'] = 'dir'; |
|
| 581 | 4 | $result['path'] = rtrim($result['path'], '/'); |
|
| 582 | |||
| 583 | 4 | return $result; |
|
| 584 | } |
||
| 585 | |||
| 586 | 26 | return array_merge($result, $response, [ |
|
| 587 | 26 | 'type' => 'file', |
|
| 588 | 26 | ]); |
|
| 589 | } |
||
| 590 | |||
| 591 | /** |
||
| 592 | * @param $location |
||
| 593 | * |
||
| 594 | * @return bool |
||
| 595 | */ |
||
| 596 | 10 | protected function doesDirectoryExist($location) |
|
| 597 | { |
||
| 598 | // Maybe this isn't an actual key, but a prefix. |
||
| 599 | // Do a prefix listing of objects to determine. |
||
| 600 | try { |
||
| 601 | 10 | $result = $this->ossClient->listObjects($this->bucket, [ |
|
| 602 | 10 | OssClient::OSS_PREFIX => rtrim($location, '/').'/', |
|
| 603 | 10 | OssClient::OSS_MAX_KEYS => 1, |
|
| 604 | 10 | ]); |
|
| 605 | |||
| 606 | 6 | return $result->getObjectList() || $result->getPrefixList(); |
|
| 607 | 4 | } catch (OssException $e) { |
|
| 608 | 4 | if (403 === $e->getHTTPStatus()) { |
|
| 609 | 2 | return false; |
|
| 610 | } |
||
| 611 | |||
| 612 | 2 | throw $e; |
|
| 613 | } |
||
| 614 | } |
||
| 615 | } |
||
| 616 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.