-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemote.php
More file actions
83 lines (73 loc) · 1.74 KB
/
Copy pathRemote.php
File metadata and controls
83 lines (73 loc) · 1.74 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
<?php
declare(strict_types = 1);
namespace Innmind\OperatingSystem;
use Innmind\Server\Control\Server;
use Innmind\IO\{
Sockets\Clients\Client,
Sockets\Internet\Transport,
};
use Innmind\Url\{
Url,
Authority,
Authority\Port,
};
use Innmind\HttpTransport\Transport as HttpTransport;
use Innmind\Immutable\Attempt;
use Formal\AccessLayer\Connection;
final class Remote
{
private function __construct(
private Server $server,
private Config $config,
private ?HttpTransport $http = null,
) {
}
/**
* @internal
*/
#[\NoDiscard]
public static function of(Server $server, Config $config): self
{
return new self($server, $config);
}
#[\NoDiscard]
public function ssh(Url $server): Server
{
$port = null;
if ($server->authority()->port()->value() !== Port::none()->value()) {
$port = $server->authority()->port();
}
return Server::remote(
$this->server,
$server->authority()->userInformation()->user(),
$server->authority()->host(),
$port,
);
}
/**
* @return Attempt<Client>
*/
#[\NoDiscard]
public function socket(Transport $transport, Authority $authority): Attempt
{
return $this
->config
->io()
->sockets()
->clients()
->internet($transport, $authority);
}
#[\NoDiscard]
public function http(): HttpTransport
{
return $this->http ??= $this->config->httpTransport();
}
/**
* @return Attempt<Connection>
*/
#[\NoDiscard]
public function sql(Url $server): Attempt
{
return $this->config->sql($server);
}
}