1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Spiral Framework package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Spiral\Storage\File; |
13
|
|
|
|
14
|
|
|
use JetBrains\PhpStorm\ExpectedValues; |
15
|
|
|
use Spiral\Storage\FileInterface; |
16
|
|
|
use Spiral\Storage\BucketInterface; |
17
|
|
|
use Spiral\Storage\Visibility; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @mixin WritableInterface |
21
|
|
|
*/ |
22
|
|
|
trait WritableTrait |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@see EntryInterface::getPathname()} |
26
|
|
|
*/ |
27
|
|
|
abstract public function getPathname(): string; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@see EntryInterface::getBucket()} |
31
|
|
|
*/ |
32
|
|
|
abstract public function getBucket(): BucketInterface; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritDoc} |
36
|
|
|
*/ |
37
|
|
|
public function create(array $config = []): FileInterface |
38
|
|
|
{ |
39
|
|
|
$bucket = $this->getBucket(); |
40
|
|
|
|
41
|
|
|
return $bucket->create($this->getPathname(), $config); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritDoc} |
46
|
|
|
*/ |
47
|
|
|
public function write($content, array $config = []): FileInterface |
48
|
|
|
{ |
49
|
|
|
$bucket = $this->getBucket(); |
50
|
|
|
|
51
|
|
|
return $bucket->write($this->getPathname(), $content, $config); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritDoc} |
56
|
|
|
*/ |
57
|
|
|
public function setVisibility( |
58
|
|
|
#[ExpectedValues(valuesFromClass: Visibility::class)] |
59
|
|
|
string $visibility |
60
|
|
|
): FileInterface { |
61
|
|
|
$bucket = $this->getBucket(); |
62
|
|
|
|
63
|
|
|
return $bucket->setVisibility($this->getPathname(), $visibility); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritDoc} |
68
|
|
|
*/ |
69
|
|
|
public function copy(string $pathname, BucketInterface $bucket = null, array $config = []): FileInterface |
70
|
|
|
{ |
71
|
|
|
$source = $this->getBucket(); |
72
|
|
|
|
73
|
|
|
return $source->copy($this->getPathname(), $pathname, $bucket, $config); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritDoc} |
78
|
|
|
*/ |
79
|
|
|
public function move(string $pathname, BucketInterface $bucket = null, array $config = []): FileInterface |
80
|
|
|
{ |
81
|
|
|
$source = $this->getBucket(); |
82
|
|
|
|
83
|
|
|
return $source->move($this->getPathname(), $pathname, $bucket, $config); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritDoc} |
88
|
|
|
*/ |
89
|
|
|
public function delete(bool $clean = false): void |
90
|
|
|
{ |
91
|
|
|
$source = $this->getBucket(); |
92
|
|
|
|
93
|
|
|
$source->delete($this->getPathname(), $clean); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|