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\VersionCommand; |
14
|
|
|
use ApiClients\Foundation\ClientInterface; |
|
|
|
|
15
|
|
|
use ApiClients\Foundation\Factory; |
16
|
|
|
use ApiClients\Foundation\Resource\ResourceInterface; |
17
|
|
|
use React\EventLoop\LoopInterface; |
18
|
|
|
use React\Promise\CancellablePromiseInterface; |
19
|
|
|
use Rx\Observable; |
20
|
|
|
use function ApiClients\Tools\Rx\unwrapObservableFromPromise; |
21
|
|
|
|
22
|
|
|
final class AsyncClient implements AsyncClientInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ClientInterface |
26
|
|
|
*/ |
27
|
|
|
private $client; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param ClientInterface $client |
31
|
|
|
*/ |
32
|
|
|
private function __construct(ClientInterface $client) |
33
|
|
|
{ |
34
|
|
|
$this->client = $client; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param LoopInterface $loop |
39
|
|
|
* @param array $options |
40
|
|
|
* @return AsyncClient |
41
|
|
|
*/ |
42
|
|
|
public static function create(string $host, LoopInterface $loop, array $options = []): self |
43
|
|
|
{ |
44
|
|
|
$options = ApiSettings::getOptions($host, $options, 'Async'); |
45
|
|
|
$client = Factory::create($loop, $options); |
46
|
|
|
|
47
|
|
|
return new self($client); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @internal |
52
|
|
|
* @param ClientInterface $client |
53
|
|
|
* @return AsyncClient |
54
|
|
|
*/ |
55
|
|
|
public static function createFromClient(ClientInterface $client): self |
56
|
|
|
{ |
57
|
|
|
return new self($client); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function hydrate(string $resource): CancellablePromiseInterface |
61
|
|
|
{ |
62
|
|
|
return $this->client->hydrate($resource); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function extract(ResourceInterface $resource): CancellablePromiseInterface |
66
|
|
|
{ |
67
|
|
|
return $this->client->extract($resource); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function APIVersion(): CancellablePromiseInterface |
71
|
|
|
{ |
72
|
|
|
return $this->client->handle(new APIVersionCommand()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function version(): CancellablePromiseInterface |
76
|
|
|
{ |
77
|
|
|
return $this->client->handle(new VersionCommand()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function identification(): CancellablePromiseInterface |
81
|
|
|
{ |
82
|
|
|
return $this->client->handle(new IdentificationCommand()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function pid(): CancellablePromiseInterface |
86
|
|
|
{ |
87
|
|
|
return $this->client->handle(new PidCommand()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function restart(): CancellablePromiseInterface |
91
|
|
|
{ |
92
|
|
|
return $this->client->handle(new RestartCommand()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function shutdown(): CancellablePromiseInterface |
96
|
|
|
{ |
97
|
|
|
return $this->client->handle(new ShutdownCommand()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function programs(): Observable |
101
|
|
|
{ |
102
|
|
|
return unwrapObservableFromPromise($this->client->handle(new ProgramsCommand())); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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: