PHP code example of geosocio / http-serializer
1. Go to this page and download the library: Download geosocio/http-serializer library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
geosocio / http-serializer example snippets
/**
* @Route("/post/{post}")
* @Method({"GET"})
*
* @Groups({"show"})
*/
public function showAction(Post $post) {
return $post;
}
/**
* @Route("/post")
* @Method({"POST"})
*
* @RequestGroups({"create"})
* @ResponseGroups({"show"})
*/
public function createAction(Post $post) {
$em = $this->doctrine->getEntityManager();
$em->persist($post);
$em->flush();
return $post;
}
/**
* @Route("/post/{post}")
* @Method({"PUT"})
*
* @RequestGroups({"replace"})
* @ResponseGroups({"show"})
*/
public function replaceAction(Post $post, Post $content) {
$em = $this->doctrine->getEntityManager();
$em->merge($content);
$em->flush();
return $post;
}
/**
* @Route("/post/{post}")
* @Method({"PATCH"})
*
* @RequestGroups({"update"})
* @ResponseGroups({"show"})
*/
public function updateAction(Post $post, array $content) {
$em = $this->doctrine->getEntityManager();
$post = $this->serializer->denormalizer($content, $post);
$em->flush();
return $post;
}
/**
* @Route("/post/{post}")
* @Method({"DELETE"})
*/
public function deleteAction(Post $post) {
$em = $this->doctrine->getEntityManager();
$em->remove($post);
$em->flush();
return '';
}