Total Complexity | 5 |
Total Lines | 66 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class CloudStorage implements S3Accessors |
||
12 | { |
||
13 | /** |
||
14 | * @var string AWS S3 file key |
||
15 | */ |
||
16 | protected $s3Key; |
||
17 | |||
18 | /** |
||
19 | * @var string Storage S3 cloud disk name |
||
20 | */ |
||
21 | protected $disk; |
||
22 | |||
23 | /** |
||
24 | * S3 constructor. |
||
25 | * |
||
26 | * @param string $s3Key |
||
27 | * @param string|null $disk |
||
28 | */ |
||
29 | public function __construct(string $s3Key, string $disk = null) |
||
30 | { |
||
31 | $this->s3Key = $s3Key; |
||
32 | $this->disk = $disk ?? config('filesystem.cloud', 's3'); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Retrieve the S3 key (useful in conjunctions with `autocompletePath()` method). |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | public function getKey(): string |
||
41 | { |
||
42 | return $this->s3Key; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Return either an S3 file url. |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function url(): string |
||
51 | { |
||
52 | return $this->storageDisk()->url($this->s3Key); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Return either a temporary S3 file url. |
||
57 | * |
||
58 | * @param DateTimeInterface|null $expiration |
||
59 | * @return string |
||
60 | */ |
||
61 | public function urlTemp(DateTimeInterface $expiration = null): string |
||
62 | { |
||
63 | return $this->storageDisk()->temporaryUrl( |
||
64 | $this->s3Key, |
||
65 | $expiration ?? config('s3-helpers.expiration') |
||
66 | ); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Retrieve a Filesystem instance for the specified disk. |
||
71 | * |
||
72 | * @return Filesystem|FilesystemAdapter |
||
73 | */ |
||
74 | protected function storageDisk(): FilesystemAdapter |
||
77 | } |
||
78 | } |
||
79 |