<?hh
final class ExampleAction
{
publicfunction __construct(
private ExampleService $exampleService
) {}
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
?callable $next = null
): JsonResponse {
$query = (array) $request->getQueryParams();
$example = HHAsiojoin($this->exampleService->get((string)$query['hoge']));
$res = [
'count'=> $example->count(),
'hoge' => $example->toArray()
];
return new JsonResponse($res);
}
}
18.
public function __construct(
privateExampleService $exampleService
) {}
はPHPの以下に相当
private $exampleService;
public function __construct(ExampleService $exampleService) {
$this->exampleService = $exampleService;
}
19.
Async function
$example =HHAsiojoin($this->exampleService->get((string)$query['hoge']));
$this->exampleService->get()
この関数はasync関数となっていて、Awaitable型が返却される。
async function get(string $hoge): Awaitable<Map>
その際には HHAsiojoin() で受け取ることで非同期から同期的な処理に
することができる。
感覚としてはjavascriptのPromiseっぽい?