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\StorageInterface; |
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::getStorage()} |
31
|
|
|
*/ |
32
|
|
|
abstract public function getStorage(): StorageInterface; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritDoc} |
36
|
|
|
*/ |
37
|
|
|
public function create(array $config = []): FileInterface |
38
|
|
|
{ |
39
|
|
|
if (!$this->exists()) { |
|
|
|
|
40
|
|
|
return $this->write('', $config); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritDoc} |
48
|
|
|
*/ |
49
|
|
|
public function write($content, array $config = []): FileInterface |
50
|
|
|
{ |
51
|
|
|
$storage = $this->getStorage(); |
52
|
|
|
|
53
|
|
|
return $storage->write($this->getPathname(), $content, $config); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritDoc} |
58
|
|
|
*/ |
59
|
|
|
public function setVisibility( |
60
|
|
|
#[ExpectedValues(valuesFromClass: Visibility::class)] |
61
|
|
|
string $visibility |
62
|
|
|
): FileInterface { |
63
|
|
|
$storage = $this->getStorage(); |
64
|
|
|
|
65
|
|
|
return $storage->setVisibility($this->getPathname(), $visibility); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritDoc} |
70
|
|
|
*/ |
71
|
|
|
public function copy(string $pathname, StorageInterface $storage = null, array $config = []): FileInterface |
72
|
|
|
{ |
73
|
|
|
$source = $this->getStorage(); |
74
|
|
|
|
75
|
|
|
return $source->copy($this->getPathname(), $pathname, $storage, $config); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritDoc} |
80
|
|
|
*/ |
81
|
|
|
public function move(string $pathname, StorageInterface $storage = null, array $config = []): FileInterface |
82
|
|
|
{ |
83
|
|
|
$source = $this->getStorage(); |
84
|
|
|
|
85
|
|
|
return $source->move($this->getPathname(), $pathname, $storage, $config); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritDoc} |
90
|
|
|
*/ |
91
|
|
|
public function delete(bool $clean = false): void |
92
|
|
|
{ |
93
|
|
|
$source = $this->getStorage(); |
94
|
|
|
|
95
|
|
|
$source->delete($this->getPathname(), $clean); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|