entityService = $entityService; } public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { $id = $request->getAttribute('id'); $entity = $this->entityService->get($id); if (null === $entity) { $ret = new JsonResponse(false); return $ret->withStatus(404); } return new JsonResponse($entity); } }