File tree Expand file tree Collapse file tree 2 files changed +53
-18
lines changed Expand file tree Collapse file tree 2 files changed +53
-18
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace ApiClients \Client \Pusher \CommandBus \Handler ;
4
4
5
- use ApiClients \Client \Pusher \AsyncClient ;
6
5
use ApiClients \Client \Pusher \CommandBus \Command \SharedAppClientCommand ;
7
- use React \ EventLoop \ LoopInterface ;
6
+ use ApiClients \ Client \ Pusher \ Service \ SharedAppClientService ;
8
7
use React \Promise \PromiseInterface ;
9
8
use function React \Promise \resolve ;
10
9
use function WyriHaximus \React \futureFunctionPromise ;
11
10
12
11
final class SharedAppClientHandler
13
12
{
14
13
/**
15
- * @var LoopInterface
14
+ * @var SharedAppClientService
16
15
*/
17
- private $ loop ;
18
-
19
- /**
20
- * @var array
21
- */
22
- private $ apps = [];
16
+ private $ service ;
23
17
24
18
/**
25
19
* SharedAppClientHandler constructor.
26
- * @param LoopInterface $loop
20
+ * @param SharedAppClientService $service
27
21
*/
28
- public function __construct (LoopInterface $ loop )
22
+ public function __construct (SharedAppClientService $ service )
29
23
{
30
- $ this ->loop = $ loop ;
24
+ $ this ->service = $ service ;
31
25
}
32
26
33
27
/**
@@ -36,11 +30,6 @@ public function __construct(LoopInterface $loop)
36
30
*/
37
31
public function handle (SharedAppClientCommand $ command ): PromiseInterface
38
32
{
39
- if (isset ($ this ->apps [$ command ->getAppId ()])) {
40
- return resolve ($ this ->apps [$ command ->getAppId ()]);
41
- }
42
-
43
- $ this ->apps [$ command ->getAppId ()] = new AsyncClient ($ this ->loop , $ command ->getAppId ());
44
- return resolve ($ this ->apps [$ command ->getAppId ()]);
33
+ return resolve ($ this ->service ->handle ($ command ->getAppId ()));
45
34
}
46
35
}
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Client \Pusher \Service ;
4
+
5
+ use ApiClients \Client \Pusher \AsyncClient ;
6
+ use ApiClients \Foundation \Service \ServiceInterface ;
7
+ use React \EventLoop \LoopInterface ;
8
+ use React \Promise \CancellablePromiseInterface ;
9
+ use function React \Promise \resolve ;
10
+ use function WyriHaximus \React \futureFunctionPromise ;
11
+
12
+ final class SharedAppClientService implements ServiceInterface
13
+ {
14
+ /**
15
+ * @var LoopInterface
16
+ */
17
+ private $ loop ;
18
+
19
+ /**
20
+ * @var array
21
+ */
22
+ private $ apps = [];
23
+
24
+ /**
25
+ * SharedAppClientHandler constructor.
26
+ * @param LoopInterface $loop
27
+ */
28
+ public function __construct (LoopInterface $ loop )
29
+ {
30
+ $ this ->loop = $ loop ;
31
+ }
32
+
33
+ /**
34
+ * @param string|null $appId
35
+ * @return CancellablePromiseInterface
36
+ */
37
+ public function handle (string $ appId = null ): CancellablePromiseInterface
38
+ {
39
+ if (isset ($ this ->apps [$ appId ])) {
40
+ return resolve ($ this ->apps [$ appId ]);
41
+ }
42
+
43
+ $ this ->apps [$ appId ] = new AsyncClient ($ this ->loop , $ appId );
44
+ return resolve ($ this ->apps [$ appId ]);
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments