-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathAdapter.php
More file actions
52 lines (45 loc) · 1.51 KB
/
Adapter.php
File metadata and controls
52 lines (45 loc) · 1.51 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
<?php
namespace React\Filesystem\ChildProcess;
use React\EventLoop\ExtUvLoop;
use React\Filesystem\AdapterInterface;
use React\Filesystem\ModeTypeDetector;
use React\Filesystem\PollInterface;
use React\Filesystem\Stat;
use React\Promise\PromiseInterface;
use RuntimeException;
use React\EventLoop\LoopInterface;
use React\Filesystem\Node;
/**
* @internal
*/
final class Adapter implements AdapterInterface
{
use StatTrait;
public function detect(string $path): PromiseInterface
{
return $this->internalStat($path)->then(function (?Stat $stat) use ($path) {
if ($stat === null) {
return new NotExist($this, dirname($path) . DIRECTORY_SEPARATOR, basename($path));
}
switch (ModeTypeDetector::detect($stat->mode())) {
case Node\DirectoryInterface::class:
return $this->directory($stat->path());
break;
case Node\FileInterface::class:
return $this->file($stat->path());
break;
default:
return new Node\Unknown($stat->path(), $stat->path());
break;
}
});
}
public function directory(string $path): Node\DirectoryInterface
{
return new Directory($this,dirname($path) . DIRECTORY_SEPARATOR, basename($path));
}
public function file(string $path): Node\FileInterface
{
return new File(dirname($path) . DIRECTORY_SEPARATOR, basename($path));
}
}