-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathFile.php
More file actions
63 lines (51 loc) · 1.52 KB
/
File.php
File metadata and controls
63 lines (51 loc) · 1.52 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
<?php
namespace React\Filesystem\Fallback;
use React\EventLoop\LoopInterface;
use React\Filesystem\Node\FileInterface;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;
use function WyriHaximus\React\FallbackPromiseClosure;
final class File implements FileInterface
{
use StatTrait;
private string $path;
private string $name;
public function __construct(string $path, string $name)
{
$this->path = $path;
$this->name = $name;
}
public function stat(): PromiseInterface
{
return $this->internalStat($this->path . $this->name);
}
public function getContents(int $offset = 0 , ?int $maxlen = null): PromiseInterface
{
$path = $this->path . $this->name;
return resolve(file_get_contents($path, false, null, $offset, $maxlen));
}
public function putContents(string $contents, int $flags = 0): PromiseInterface
{
// Making sure we only pass in one flag for security reasons
if (($flags & \FILE_APPEND) == \FILE_APPEND) {
$flags = \FILE_APPEND;
} else {
$flags = 0;
}
$path = $this->path . $this->name;
return resolve(file_put_contents($path, $contents, $flags));
}
public function unlink(): PromiseInterface
{
$path = $this->path . $this->name;
return resolve(unlink($path));
}
public function path(): string
{
return $this->path;
}
public function name(): string
{
return $this->name;
}
}