| Total Complexity | 7 |
| Total Lines | 94 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class CloudStorage |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string AWS S3 file key |
||
| 13 | */ |
||
| 14 | protected $s3Key; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string Storage S3 cloud disk name |
||
| 18 | */ |
||
| 19 | protected $disk; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var bool Enable/disable upload & download streaming |
||
| 23 | */ |
||
| 24 | protected $streaming; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * S3 constructor. |
||
| 28 | * |
||
| 29 | * @param string $s3Key |
||
| 30 | */ |
||
| 31 | public function __construct(string $s3Key) |
||
| 32 | { |
||
| 33 | $this->s3Key = $s3Key; |
||
| 34 | $this->disk = config('filesystem.cloud', 's3'); |
||
| 35 | $this->streaming = config('s3-helpers.streaming', true); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Retrieve a Filesystem instance for the specified disk. |
||
| 40 | * |
||
| 41 | * @return Filesystem|FilesystemAdapter |
||
| 42 | */ |
||
| 43 | protected function storageDisk(): FilesystemAdapter |
||
| 44 | { |
||
| 45 | return Storage::disk($this->disk); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Determine if upload/download streaming is enabled. |
||
| 50 | * |
||
| 51 | * @return bool |
||
| 52 | */ |
||
| 53 | protected function isStreamingEnabled(): bool |
||
| 54 | { |
||
| 55 | return $this->streaming; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Retrieve the S3 key (useful in conjunctions with `autocompletePath()` method). |
||
| 60 | * |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | public function getKey(): string |
||
| 64 | { |
||
| 65 | return $this->s3Key; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Set the filesystem disk. |
||
| 70 | * |
||
| 71 | * @param string $disk |
||
| 72 | * @return $this |
||
| 73 | */ |
||
| 74 | public function setDisk(string $disk): self |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Enable upload/download streaming regardless of config setting. |
||
| 83 | * |
||
| 84 | * @return $this |
||
| 85 | */ |
||
| 86 | public function enableStreaming(): self |
||
| 87 | { |
||
| 88 | $this->streaming = true; |
||
| 89 | |||
| 90 | return $this; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Disable upload/download streaming regardless of config setting. |
||
| 95 | * |
||
| 96 | * @return $this |
||
| 97 | */ |
||
| 98 | public function disableStreaming(): self |
||
| 103 | } |
||
| 104 | } |
||
| 105 |