RestBundle\Controller\RestController::updateCommentAction PHP Метод

updateCommentAction() публичный Метод

Update existing comment from the submitted data or create a new comment at a specific location.
public updateCommentAction ( Request $request, integer $id ) : FOS\RestBundle\View\View | Response
$request Symfony\Component\HttpFoundation\Request
$id integer
Результат FOS\RestBundle\View\View | Symfony\Component\HttpFoundation\Response
    public function updateCommentAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();
        $comment = $em->getRepository('AppBundle:Comment')->find($id);
        if (null === $comment) {
            $comment = new Comment();
            $comment->setId($id);
            $em->persist($comment);
            $metadata = $em->getClassMetadata(get_class($comment));
            $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
            $metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
            $statusCode = Response::HTTP_CREATED;
        } else {
            $statusCode = Response::HTTP_NO_CONTENT;
        }
        $form = $this->createForm(new CommentRestType(), $comment);
        $form->submit($request);
        if ($form->isValid()) {
            $em->flush();
            return $this->routeRedirectView('get_comment', array('id' => $comment->getId()), $statusCode);
        }
        $view = new View($form);
        return $this->handleView($view);
    }