@@ 15-54 (lines=40) @@ | ||
12 | use function React\Promise\resolve; |
|
13 | use function WyriHaximus\React\futureFunctionPromise; |
|
14 | ||
15 | final class RepositoryHandler |
|
16 | { |
|
17 | /** |
|
18 | * @var RequestService |
|
19 | */ |
|
20 | private $requestService; |
|
21 | ||
22 | /** |
|
23 | * @var Hydrator |
|
24 | */ |
|
25 | private $hydrator; |
|
26 | ||
27 | /** |
|
28 | * @param RequestService $requestService |
|
29 | * @param Hydrator $hydrator |
|
30 | */ |
|
31 | public function __construct(RequestService $requestService, Hydrator $hydrator) |
|
32 | { |
|
33 | $this->requestService = $requestService; |
|
34 | $this->hydrator = $hydrator; |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * Fetch the given repository and hydrate it |
|
39 | * |
|
40 | * @param RepositoryCommand $command |
|
41 | * @return PromiseInterface |
|
42 | */ |
|
43 | public function handle(RepositoryCommand $command): PromiseInterface |
|
44 | { |
|
45 | return $this->requestService->handle( |
|
46 | new Request('GET', 'repos/' . $command->getRepository()) |
|
47 | )->then(function (ResponseInterface $response) { |
|
48 | return resolve($this->hydrator->hydrate( |
|
49 | RepositoryInterface::HYDRATE_CLASS, |
|
50 | $response->getBody()->getJson()['repo'] |
|
51 | )); |
|
52 | }); |
|
53 | } |
|
54 | } |
|
55 |
@@ 15-54 (lines=40) @@ | ||
12 | use function React\Promise\resolve; |
|
13 | use function WyriHaximus\React\futureFunctionPromise; |
|
14 | ||
15 | final class UserHandler |
|
16 | { |
|
17 | /** |
|
18 | * @var RequestService |
|
19 | */ |
|
20 | private $requestService; |
|
21 | ||
22 | /** |
|
23 | * @var Hydrator |
|
24 | */ |
|
25 | private $hydrator; |
|
26 | ||
27 | /** |
|
28 | * @param RequestService $requestService |
|
29 | * @param Hydrator $hydrator |
|
30 | */ |
|
31 | public function __construct(RequestService $requestService, Hydrator $hydrator) |
|
32 | { |
|
33 | $this->requestService = $requestService; |
|
34 | $this->hydrator = $hydrator; |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * Fetch the given repository and hydrate it |
|
39 | * |
|
40 | * @param UserCommand $command |
|
41 | * @return PromiseInterface |
|
42 | */ |
|
43 | public function handle(UserCommand $command): PromiseInterface |
|
44 | { |
|
45 | return $this->requestService->handle( |
|
46 | new Request('GET', 'users') |
|
47 | )->then(function (ResponseInterface $response) { |
|
48 | return resolve($this->hydrator->hydrate( |
|
49 | UserInterface::HYDRATE_CLASS, |
|
50 | $response->getBody()->getJson()['user'] |
|
51 | )); |
|
52 | }); |
|
53 | } |
|
54 | } |
|
55 |