em = $em; $this->hydrator = $hydrator; } public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { $data = $this->getRequestData($request); $entity = $this->hydrator->hydrate($data, new Article()); $this->em->persist($entity); $this->em->flush(); return new JsonResponse([ 'success' => true, 'result' => $entity, ]); } }