-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperatingSystem.php
More file actions
102 lines (88 loc) · 2.29 KB
/
Copy pathOperatingSystem.php
File metadata and controls
102 lines (88 loc) · 2.29 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types = 1);
namespace Innmind\OperatingSystem;
use Innmind\Server\Status;
use Innmind\Server\Control;
use Innmind\Time\Clock;
final class OperatingSystem
{
private Config $config;
private ?Filesystem $filesystem = null;
private ?Status\Server $status = null;
private ?Control\Server $control = null;
private ?Ports $ports = null;
private ?Sockets $sockets = null;
private ?Remote $remote = null;
private ?CurrentProcess $process = null;
private function __construct(Config $config)
{
$this->config = $config;
}
#[\NoDiscard]
public static function new(?Config $config = null): self
{
return new self($config ?? Config::new());
}
/**
* This method allows to change the underlying OS implementation while being
* able to keep any decorators on top of it.
*
* @param callable(Config): Config $map
*/
#[\NoDiscard]
public function map(callable $map): self
{
return new self($map($this->config));
}
#[\NoDiscard]
public function clock(): Clock
{
return $this->config->clock();
}
#[\NoDiscard]
public function filesystem(): Filesystem
{
return $this->filesystem ??= Filesystem::of(
$this->control()->processes(),
$this->config,
);
}
#[\NoDiscard]
public function status(): Status\Server
{
return $this->status ??= $this->config->serverStatus(
$this->control(),
);
}
#[\NoDiscard]
public function control(): Control\Server
{
return $this->control ??= $this->config->serverControl();
}
#[\NoDiscard]
public function ports(): Ports
{
return $this->ports ??= Ports::of($this->config);
}
#[\NoDiscard]
public function sockets(): Sockets
{
return $this->sockets ??= Sockets::of($this->config);
}
#[\NoDiscard]
public function remote(): Remote
{
return $this->remote ??= Remote::of(
$this->control(),
$this->config,
);
}
#[\NoDiscard]
public function process(): CurrentProcess
{
return $this->process ??= CurrentProcess::of(
$this->config->halt(),
$this->config->signalsHandler(),
);
}
}