|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace drupol\phpvfs\Filesystem; |
|
6
|
|
|
|
|
7
|
|
|
use drupol\phpvfs\Commands\Cd; |
|
8
|
|
|
use drupol\phpvfs\Commands\Exist; |
|
9
|
|
|
use drupol\phpvfs\Commands\Get; |
|
10
|
|
|
use drupol\phpvfs\Commands\Inspect; |
|
11
|
|
|
use drupol\phpvfs\Commands\Touch; |
|
12
|
|
|
use drupol\phpvfs\Node\Directory; |
|
13
|
|
|
use drupol\phpvfs\Node\DirectoryInterface; |
|
14
|
|
|
use drupol\phpvfs\Node\VfsInterface; |
|
15
|
|
|
|
|
16
|
|
|
class Filesystem implements FilesystemInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var \drupol\phpvfs\Node\DirectoryInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
private $cwd; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Filesystem constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $id |
|
27
|
|
|
* @param array $attributes |
|
28
|
|
|
* |
|
29
|
|
|
* @throws \Exception |
|
30
|
|
|
*/ |
|
31
|
13 |
|
public function __construct( |
|
32
|
|
|
string $id, |
|
33
|
|
|
array $attributes = [] |
|
34
|
|
|
) { |
|
35
|
|
|
$attributes = [ |
|
36
|
13 |
|
'id' => $id, |
|
37
|
13 |
|
'vfs' => $this, |
|
38
|
13 |
|
] + $attributes; |
|
39
|
|
|
|
|
40
|
13 |
|
$this->cwd = Directory::create($id, $attributes); |
|
41
|
13 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function cd(string $id) |
|
47
|
|
|
{ |
|
48
|
1 |
|
Cd::exec($this, $id); |
|
49
|
|
|
|
|
50
|
1 |
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public static function create(string $id, array $attributes = []) |
|
57
|
|
|
{ |
|
58
|
1 |
|
return new self($id, $attributes); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritdoc} |
|
63
|
|
|
*/ |
|
64
|
6 |
|
public function exist(string $id): bool |
|
65
|
|
|
{ |
|
66
|
6 |
|
return Exist::exec($this, $id); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
6 |
|
public function get(string $id): ?VfsInterface |
|
73
|
|
|
{ |
|
74
|
6 |
|
return Get::exec($this, $id); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
11 |
|
public function getCwd(): DirectoryInterface |
|
81
|
|
|
{ |
|
82
|
11 |
|
return $this->cwd; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function inspect(string $id): string |
|
89
|
|
|
{ |
|
90
|
1 |
|
return Inspect::exec($this, $id); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* {@inheritdoc} |
|
95
|
|
|
*/ |
|
96
|
2 |
|
public function root(): VfsInterface |
|
97
|
|
|
{ |
|
98
|
2 |
|
return $this->cwd->root(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* {@inheritdoc} |
|
103
|
|
|
*/ |
|
104
|
2 |
|
public function setCwd(DirectoryInterface $dir) |
|
105
|
|
|
{ |
|
106
|
2 |
|
$this->cwd = $dir; |
|
107
|
|
|
|
|
108
|
2 |
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* {@inheritdoc} |
|
113
|
|
|
*/ |
|
114
|
1 |
|
public function touch(string $id) |
|
115
|
|
|
{ |
|
116
|
1 |
|
Touch::exec($this, $id); |
|
117
|
|
|
|
|
118
|
1 |
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|