|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Spiral\Storage\File; |
|
6
|
|
|
|
|
7
|
|
|
use JetBrains\PhpStorm\ExpectedValues; |
|
8
|
|
|
use Spiral\Storage\FileInterface; |
|
9
|
|
|
use Spiral\Storage\BucketInterface; |
|
10
|
|
|
use Spiral\Storage\Visibility; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @mixin WritableInterface |
|
14
|
|
|
*/ |
|
15
|
|
|
trait WritableTrait |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@see EntryInterface::getPathname()} |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract public function getPathname(): string; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* {@see EntryInterface::getBucket()} |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract public function getBucket(): BucketInterface; |
|
26
|
|
|
|
|
27
|
|
|
public function create(array $config = []): FileInterface |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->getBucket()->create($this->getPathname(), $config); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function write(mixed $content, array $config = []): FileInterface |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->getBucket()->write($this->getPathname(), $content, $config); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function setVisibility( |
|
38
|
|
|
#[ExpectedValues(valuesFromClass: Visibility::class)] |
|
39
|
|
|
string $visibility |
|
40
|
|
|
): FileInterface { |
|
41
|
|
|
return $this->getBucket()->setVisibility($this->getPathname(), $visibility); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function copy(string $pathname, BucketInterface $storage = null, array $config = []): FileInterface |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->getBucket()->copy($this->getPathname(), $pathname, $storage, $config); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function move(string $pathname, BucketInterface $storage = null, array $config = []): FileInterface |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getBucket()->move($this->getPathname(), $pathname, $storage, $config); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function delete(bool $clean = false): void |
|
55
|
|
|
{ |
|
56
|
|
|
$source = $this->getBucket(); |
|
57
|
|
|
|
|
58
|
|
|
$source->delete($this->getPathname(), $clean); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|