1 | <?php declare(strict_types=1); |
||
13 | final class StreamingClient implements StreamingClientInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var LoopInterface |
||
17 | */ |
||
18 | protected $loop; |
||
19 | |||
20 | /** |
||
21 | * @var CommandBusInterface |
||
22 | */ |
||
23 | protected $commandBus; |
||
24 | |||
25 | /** |
||
26 | * @var AsyncStreamingClientInterface |
||
27 | */ |
||
28 | protected $client; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $hydrateClassConstantCache = []; |
||
|
|||
34 | |||
35 | /** |
||
36 | * StreamingClient constructor. |
||
37 | * @param LoopInterface $loop |
||
38 | * @param CommandBusInterface $commandBus |
||
39 | * @param AsyncStreamingClientInterface $client |
||
40 | */ |
||
41 | 6 | public function __construct( |
|
50 | |||
51 | 1 | public function sample(callable $listener) |
|
55 | |||
56 | 5 | public function filtered(callable $listener, array $filter = []) |
|
60 | |||
61 | 6 | protected function stream(ObservableInterface $observable, callable $listener) |
|
62 | { |
||
63 | $observable->flatMap(function (ResourceInterface $resource) { |
||
64 | 6 | return Promise::toObservable( |
|
65 | 6 | $this->commandBus->handle( |
|
66 | 6 | new BuildSyncFromAsyncCommand( |
|
67 | 6 | $this->loopUpHydrateClassConstant($resource), |
|
68 | $resource |
||
69 | ) |
||
70 | ) |
||
71 | ); |
||
72 | 6 | })->subscribe( |
|
73 | $listener, |
||
74 | 6 | function ($error) { |
|
75 | throw $error; |
||
76 | 6 | } |
|
77 | ); |
||
78 | 6 | $this->loop->run(); |
|
79 | 6 | } |
|
80 | |||
81 | 6 | protected function loopUpHydrateClassConstant(ResourceInterface $resource) |
|
90 | } |
||
91 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.