@@ 10-31 (lines=22) @@ | ||
7 | use React\Promise\CancellablePromiseInterface; |
|
8 | use function WyriHaximus\React\futureFunctionPromise; |
|
9 | ||
10 | final class JsonDecodeService implements ServiceInterface |
|
11 | { |
|
12 | /** |
|
13 | * @var LoopInterface |
|
14 | */ |
|
15 | private $loop; |
|
16 | ||
17 | /** |
|
18 | * @param LoopInterface $loop |
|
19 | */ |
|
20 | public function __construct(LoopInterface $loop) |
|
21 | { |
|
22 | $this->loop = $loop; |
|
23 | } |
|
24 | ||
25 | public function handle($input): CancellablePromiseInterface |
|
26 | { |
|
27 | return futureFunctionPromise($this->loop, $input, function ($json) { |
|
28 | return json_decode($json, true); |
|
29 | }); |
|
30 | } |
|
31 | } |
|
32 |
@@ 12-37 (lines=26) @@ | ||
9 | use function React\Promise\resolve; |
|
10 | use function WyriHaximus\React\futureFunctionPromise; |
|
11 | ||
12 | final class JsonEncodeService implements ServiceInterface |
|
13 | { |
|
14 | /** |
|
15 | * @var LoopInterface |
|
16 | */ |
|
17 | private $loop; |
|
18 | ||
19 | /** |
|
20 | * @param LoopInterface $loop |
|
21 | */ |
|
22 | public function __construct(LoopInterface $loop) |
|
23 | { |
|
24 | $this->loop = $loop; |
|
25 | } |
|
26 | ||
27 | /** |
|
28 | * @param $input |
|
29 | * @return CancellablePromiseInterface |
|
30 | */ |
|
31 | public function handle($input): CancellablePromiseInterface |
|
32 | { |
|
33 | return futureFunctionPromise($this->loop, $input, function ($json) { |
|
34 | return json_encode($json); |
|
35 | }); |
|
36 | } |
|
37 | } |
|
38 |