UnableToRetrieveMetadata.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. namespace League\Flysystem;
  4. use RuntimeException;
  5. use Throwable;
  6. final class UnableToRetrieveMetadata extends RuntimeException implements FilesystemOperationFailed
  7. {
  8. /**
  9. * @var string
  10. */
  11. private $location;
  12. /**
  13. * @var string
  14. */
  15. private $metadataType;
  16. /**
  17. * @var string
  18. */
  19. private $reason;
  20. public static function lastModified(string $location, string $reason = '', Throwable $previous = null): self
  21. {
  22. return static::create($location, FileAttributes::ATTRIBUTE_LAST_MODIFIED, $reason, $previous);
  23. }
  24. public static function visibility(string $location, string $reason = '', Throwable $previous = null): self
  25. {
  26. return static::create($location, FileAttributes::ATTRIBUTE_VISIBILITY, $reason, $previous);
  27. }
  28. public static function fileSize(string $location, string $reason = '', Throwable $previous = null): self
  29. {
  30. return static::create($location, FileAttributes::ATTRIBUTE_FILE_SIZE, $reason, $previous);
  31. }
  32. public static function mimeType(string $location, string $reason = '', Throwable $previous = null): self
  33. {
  34. return static::create($location, FileAttributes::ATTRIBUTE_MIME_TYPE, $reason, $previous);
  35. }
  36. public static function create(string $location, string $type, string $reason = '', Throwable $previous = null): self
  37. {
  38. $e = new static("Unable to retrieve the $type for file at location: $location. {$reason}", 0, $previous);
  39. $e->reason = $reason;
  40. $e->location = $location;
  41. $e->metadataType = $type;
  42. return $e;
  43. }
  44. public function reason(): string
  45. {
  46. return $this->reason;
  47. }
  48. public function location(): string
  49. {
  50. return $this->location;
  51. }
  52. public function metadataType(): string
  53. {
  54. return $this->metadataType;
  55. }
  56. public function operation(): string
  57. {
  58. return FilesystemOperationFailed::OPERATION_RETRIEVE_METADATA;
  59. }
  60. }