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\Storage; |
16
|
|
|
use Spiral\Storage\StorageInterface; |
17
|
|
|
use Spiral\Storage\BucketInterface; |
18
|
|
|
use Spiral\Storage\Visibility; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @mixin ReadableInterface |
22
|
|
|
*/ |
23
|
|
|
trait ReadableTrait |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@see StorageInterface::bucket()} |
27
|
|
|
*/ |
28
|
|
|
abstract public function bucket(string $name = null): BucketInterface; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
*/ |
33
|
|
|
public function getContents($id): string |
34
|
|
|
{ |
35
|
|
|
[$name, $pathname] = $this->parseUri($id); |
36
|
|
|
|
37
|
|
|
$bucket = $this->bucket($name); |
38
|
|
|
|
39
|
|
|
return $bucket->getContents($pathname); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritDoc} |
44
|
|
|
*/ |
45
|
|
|
public function getStream($id) |
46
|
|
|
{ |
47
|
|
|
[$name, $pathname] = $this->parseUri($id); |
48
|
|
|
|
49
|
|
|
$bucket = $this->bucket($name); |
50
|
|
|
|
51
|
|
|
return $bucket->getStream($pathname); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritDoc} |
56
|
|
|
*/ |
57
|
|
|
public function exists($id): bool |
58
|
|
|
{ |
59
|
|
|
[$name, $pathname] = $this->parseUri($id); |
60
|
|
|
|
61
|
|
|
$bucket = $this->bucket($name); |
62
|
|
|
|
63
|
|
|
return $bucket->exists($pathname); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritDoc} |
68
|
|
|
*/ |
69
|
|
|
public function getLastModified($id): int |
70
|
|
|
{ |
71
|
|
|
[$name, $pathname] = $this->parseUri($id); |
72
|
|
|
|
73
|
|
|
$bucket = $this->bucket($name); |
74
|
|
|
|
75
|
|
|
return $bucket->getLastModified($pathname); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritDoc} |
80
|
|
|
*/ |
81
|
|
|
public function getSize($id): int |
82
|
|
|
{ |
83
|
|
|
[$name, $pathname] = $this->parseUri($id); |
84
|
|
|
|
85
|
|
|
$bucket = $this->bucket($name); |
86
|
|
|
|
87
|
|
|
return $bucket->getSize($pathname); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritDoc} |
92
|
|
|
*/ |
93
|
|
|
public function getMimeType($id): string |
94
|
|
|
{ |
95
|
|
|
[$name, $pathname] = $this->parseUri($id); |
96
|
|
|
|
97
|
|
|
$bucket = $this->bucket($name); |
98
|
|
|
|
99
|
|
|
return $bucket->getMimeType($pathname); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritDoc} |
104
|
|
|
*/ |
105
|
|
|
#[ExpectedValues(valuesFromClass: Visibility::class)] |
106
|
|
|
public function getVisibility($id): string |
107
|
|
|
{ |
108
|
|
|
[$name, $pathname] = $this->parseUri($id); |
109
|
|
|
|
110
|
|
|
$bucket = $this->bucket($name); |
111
|
|
|
|
112
|
|
|
return $bucket->getVisibility($pathname); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@see Storage::parseUri()} |
117
|
|
|
*/ |
118
|
|
|
abstract protected function parseUri($uri, bool $withScheme = true): array; |
119
|
|
|
} |
120
|
|
|
|