1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApiClients\Client\Supervisord; |
6
|
|
|
|
7
|
|
|
use ApiClients\Client\Supervisord\CommandBus\Command\APIVersionCommand; |
8
|
|
|
use ApiClients\Client\Supervisord\CommandBus\Command\IdentificationCommand; |
9
|
|
|
use ApiClients\Client\Supervisord\CommandBus\Command\PidCommand; |
10
|
|
|
use ApiClients\Client\Supervisord\CommandBus\Command\ProgramsCommand; |
11
|
|
|
use ApiClients\Client\Supervisord\CommandBus\Command\RestartCommand; |
12
|
|
|
use ApiClients\Client\Supervisord\CommandBus\Command\ShutdownCommand; |
13
|
|
|
use ApiClients\Client\Supervisord\CommandBus\Command\StateCommand; |
14
|
|
|
use ApiClients\Client\Supervisord\CommandBus\Command\VersionCommand; |
15
|
|
|
use ApiClients\Foundation\ClientInterface; |
|
|
|
|
16
|
|
|
use ApiClients\Foundation\Factory; |
17
|
|
|
use ApiClients\Foundation\Resource\ResourceInterface; |
18
|
|
|
use React\EventLoop\LoopInterface; |
19
|
|
|
use React\Promise\CancellablePromiseInterface; |
20
|
|
|
use Rx\Observable; |
21
|
|
|
use function ApiClients\Tools\Rx\unwrapObservableFromPromise; |
22
|
|
|
|
23
|
|
|
final class AsyncClient implements AsyncClientInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ClientInterface |
27
|
|
|
*/ |
28
|
|
|
private $client; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param ClientInterface $client |
32
|
|
|
*/ |
33
|
|
|
private function __construct(ClientInterface $client) |
34
|
|
|
{ |
35
|
|
|
$this->client = $client; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param LoopInterface $loop |
40
|
|
|
* @param array $options |
41
|
|
|
* @return AsyncClient |
42
|
|
|
*/ |
43
|
|
|
public static function create(string $host, LoopInterface $loop, array $options = []): self |
44
|
|
|
{ |
45
|
|
|
$options = ApiSettings::getOptions($host, $options, 'Async'); |
46
|
|
|
$client = Factory::create($loop, $options); |
47
|
|
|
|
48
|
|
|
return new self($client); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @internal |
53
|
|
|
* @param ClientInterface $client |
54
|
|
|
* @return AsyncClient |
55
|
|
|
*/ |
56
|
|
|
public static function createFromClient(ClientInterface $client): self |
57
|
|
|
{ |
58
|
|
|
return new self($client); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function hydrate(string $resource): CancellablePromiseInterface |
62
|
|
|
{ |
63
|
|
|
return $this->client->hydrate($resource); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function extract(ResourceInterface $resource): CancellablePromiseInterface |
67
|
|
|
{ |
68
|
|
|
return $this->client->extract($resource); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function APIVersion(): CancellablePromiseInterface |
72
|
|
|
{ |
73
|
|
|
return $this->client->handle(new APIVersionCommand()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function version(): CancellablePromiseInterface |
77
|
|
|
{ |
78
|
|
|
return $this->client->handle(new VersionCommand()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function identification(): CancellablePromiseInterface |
82
|
|
|
{ |
83
|
|
|
return $this->client->handle(new IdentificationCommand()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function state(): CancellablePromiseInterface |
87
|
|
|
{ |
88
|
|
|
return $this->client->handle(new StateCommand()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function pid(): CancellablePromiseInterface |
92
|
|
|
{ |
93
|
|
|
return $this->client->handle(new PidCommand()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function restart(): CancellablePromiseInterface |
97
|
|
|
{ |
98
|
|
|
return $this->client->handle(new RestartCommand()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function shutdown(): CancellablePromiseInterface |
102
|
|
|
{ |
103
|
|
|
return $this->client->handle(new ShutdownCommand()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function programs(): Observable |
107
|
|
|
{ |
108
|
|
|
return unwrapObservableFromPromise($this->client->handle(new ProgramsCommand())); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: