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\Storage; |
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 StorageInterface::bucket()} |
26
|
|
|
*/ |
27
|
|
|
abstract public function bucket(string $name = null): BucketInterface; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritDoc} |
31
|
|
|
*/ |
32
|
|
|
public function create($id, array $config = []): FileInterface |
33
|
|
|
{ |
34
|
|
|
[$name, $pathname] = $this->parseUri($id); |
35
|
|
|
|
36
|
|
|
$bucket = $this->bucket($name); |
37
|
|
|
|
38
|
|
|
return $bucket->create($pathname, $config); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritDoc} |
43
|
|
|
*/ |
44
|
|
|
public function write($id, $content, array $config = []): FileInterface |
45
|
|
|
{ |
46
|
|
|
[$name, $pathname] = $this->parseUri($id); |
47
|
|
|
|
48
|
|
|
$bucket = $this->bucket($name); |
49
|
|
|
|
50
|
|
|
return $bucket->write($pathname, $content, $config); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritDoc} |
55
|
|
|
*/ |
56
|
|
|
public function setVisibility( |
57
|
|
|
$id, |
58
|
|
|
#[ExpectedValues(valuesFromClass: Visibility::class)] |
59
|
|
|
string $visibility |
60
|
|
|
): FileInterface { |
61
|
|
|
[$name, $pathname] = $this->parseUri($id); |
62
|
|
|
|
63
|
|
|
$bucket = $this->bucket($name); |
64
|
|
|
|
65
|
|
|
return $bucket->setVisibility($pathname, $visibility); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritDoc} |
70
|
|
|
*/ |
71
|
|
|
public function copy($source, $destination, array $config = []): FileInterface |
72
|
|
|
{ |
73
|
|
|
[$sourceName, $sourcePathname] = $this->parseUri($source); |
74
|
|
|
[$destName, $destPathname] = $this->parseUri($destination, false); |
75
|
|
|
|
76
|
|
|
$sourceStorage = $this->bucket($sourceName); |
77
|
|
|
$destStorage = $destName ? $this->bucket($destName) : null; |
78
|
|
|
|
79
|
|
|
return $sourceStorage->copy($sourcePathname, $destPathname, $destStorage, $config); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
*/ |
85
|
|
|
public function move($source, $destination, array $config = []): FileInterface |
86
|
|
|
{ |
87
|
|
|
[$sourceName, $sourcePathname] = $this->parseUri($source); |
88
|
|
|
[$destName, $destPathname] = $this->parseUri($destination, false); |
89
|
|
|
|
90
|
|
|
$sourceStorage = $this->bucket($sourceName); |
91
|
|
|
$destStorage = $destName ? $this->bucket($destName) : null; |
92
|
|
|
|
93
|
|
|
return $sourceStorage->move($sourcePathname, $destPathname, $destStorage, $config); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritDoc} |
98
|
|
|
*/ |
99
|
|
|
public function delete($id, bool $clean = false): void |
100
|
|
|
{ |
101
|
|
|
[$name, $pathname] = $this->parseUri($id); |
102
|
|
|
|
103
|
|
|
$bucket = $this->bucket($name); |
104
|
|
|
|
105
|
|
|
$bucket->delete($pathname, $clean); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@see Storage::parseUri()} |
110
|
|
|
*/ |
111
|
|
|
abstract protected function parseUri($uri, bool $withScheme = true): array; |
112
|
|
|
} |
113
|
|
|
|