-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathAdapter.php
More file actions
67 lines (56 loc) · 1.86 KB
/
Adapter.php
File metadata and controls
67 lines (56 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace React\Filesystem\Eio;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use React\Filesystem\AdapterInterface;
use React\Filesystem\ModeTypeDetector;
use React\Filesystem\Node;
use React\Filesystem\PollInterface;
use React\Filesystem\Stat;
use React\Promise\PromiseInterface;
final class Adapter implements AdapterInterface
{
use StatTrait;
private LoopInterface $loop;
private PollInterface $poll;
public function __construct()
{
$this->loop = Loop::get();
$this->poll = new Poll();
}
public function detect(string $path): PromiseInterface
{
return $this->internalStat($path)->then(function (?Stat $stat) use ($path) {
if ($stat === null) {
return new NotExist($this->poll, $this, $this->loop, dirname($path) . DIRECTORY_SEPARATOR, basename($path));
}
switch (ModeTypeDetector::detect($stat->mode())) {
case Node\FileInterface::class:
return $this->file($stat->path());
break;
case Node\DirectoryInterface::class:
return $this->directory($stat->path());
break;
default:
return new Node\Unknown($stat->path(), $stat->path());
break;
}
});
}
public function directory(string $path): Node\DirectoryInterface
{
return new Directory($this->poll, $this, dirname($path) . DIRECTORY_SEPARATOR, basename($path));
}
public function file(string $path): Node\FileInterface
{
return new File($this->poll, dirname($path) . DIRECTORY_SEPARATOR, basename($path));
}
protected function activate(): void
{
$this->poll->activate();
}
protected function deactivate(): void
{
$this->poll->deactivate();
}
}