1 | <?php declare(strict_types=1); |
||
19 | final class AsyncClient |
||
20 | { |
||
21 | /** |
||
22 | * @var ClientInterface |
||
23 | */ |
||
24 | protected $client; |
||
25 | |||
26 | /** |
||
27 | * @param LoopInterface $loop |
||
28 | * @param string $token |
||
29 | * @param array $options |
||
30 | * @param ClientInterface|null $client |
||
31 | */ |
||
32 | 6 | public function __construct( |
|
33 | LoopInterface $loop, |
||
34 | string $token = '', |
||
35 | array $options = [], |
||
36 | ClientInterface $client = null |
||
37 | ) { |
||
38 | 6 | if (!($client instanceof ClientInterface)) { |
|
39 | $this->options = ApiSettings::getOptions($token, 'Async', $options); |
||
40 | $client = Factory::create($loop, $this->options); |
||
41 | } |
||
42 | 6 | $this->client = $client; |
|
43 | 6 | } |
|
44 | |||
45 | /** |
||
46 | * @param string $repository |
||
47 | * @return CancellablePromiseInterface |
||
48 | */ |
||
49 | 1 | public function repository(string $repository): CancellablePromiseInterface |
|
50 | { |
||
51 | 1 | return $this->client->handle(new Command\RepositoryCommand($repository)); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return ObservableInterface |
||
56 | */ |
||
57 | public function repositories(): ObservableInterface |
||
58 | { |
||
59 | return $this->hooks()->filter(function ($hook) { |
||
60 | return $hook->active(); |
||
61 | })->flatMap(function (HookInterface $hook) { |
||
62 | return Promise::toObservable($this->client->handle( |
||
63 | new Command\RepositoryIdCommand($hook->id()) |
||
64 | )); |
||
65 | }); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @return PromiseInterface |
||
70 | */ |
||
71 | public function user(): PromiseInterface |
||
72 | { |
||
73 | 1 | return $this->client->handle(new Command\UserCommand()); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param int $id |
||
78 | * @return PromiseInterface |
||
79 | */ |
||
80 | 1 | public function sshKey(int $id): PromiseInterface |
|
81 | { |
||
82 | 1 | return $this->client->handle(new Command\SSHKeyCommand($id)); |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return ObservableInterface |
||
87 | */ |
||
88 | public function hooks(): ObservableInterface |
||
94 | |||
95 | /** |
||
96 | * @return ObservableInterface |
||
97 | */ |
||
98 | public function accounts(): ObservableInterface |
||
104 | |||
105 | /** |
||
106 | * @return ObservableInterface |
||
107 | */ |
||
108 | public function broadcasts(): ObservableInterface |
||
114 | } |
||
115 |
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: