Symfony Serializer enabled. Serializer groups added to Post, Tag and Comment.

This commit is contained in:
Alexey Skobkin 2016-03-16 23:08:48 +03:00
parent ae8cbde3e1
commit c1e01c4738
4 changed files with 39 additions and 1 deletions

View file

@ -6,6 +6,9 @@ imports:
framework: framework:
#esi: ~ #esi: ~
translator: { fallbacks: ["%locale%"] } translator: { fallbacks: ["%locale%"] }
serializer:
#enabled: true
enable_annotations: true
secret: "%secret%" secret: "%secret%"
router: router:
resource: "%kernel.root_dir%/config/routing.yml" resource: "%kernel.root_dir%/config/routing.yml"

View file

@ -4,6 +4,7 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* Comment * Comment
@ -18,6 +19,8 @@ class Comment
/** /**
* @var integer * @var integer
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
*/ */
@ -26,6 +29,8 @@ class Comment
/** /**
* @var string * @var string
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="text", type="text") * @ORM\Column(name="text", type="text")
*/ */
private $text; private $text;
@ -33,6 +38,8 @@ class Comment
/** /**
* @var \DateTime * @var \DateTime
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="created_at", type="datetime") * @ORM\Column(name="created_at", type="datetime")
*/ */
private $createdAt; private $createdAt;
@ -40,6 +47,8 @@ class Comment
/** /**
* @var boolean * @var boolean
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_rec", type="boolean") * @ORM\Column(name="is_rec", type="boolean")
*/ */
private $rec; private $rec;
@ -47,6 +56,8 @@ class Comment
/** /**
* @var bool * @var bool
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_deleted", type="boolean") * @ORM\Column(name="is_deleted", type="boolean")
*/ */
private $deleted = false; private $deleted = false;
@ -55,7 +66,7 @@ class Comment
* @var Post * @var Post
* *
* @ORM\Id * @ORM\Id
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post", inversedBy="comments")
* @ORM\JoinColumn(name="post_id") * @ORM\JoinColumn(name="post_id")
*/ */
private $post; private $post;
@ -63,6 +74,8 @@ class Comment
/** /**
* @var User * @var User
* *
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author_id") * @ORM\JoinColumn(name="author_id")
*/ */
@ -71,6 +84,8 @@ class Comment
/** /**
* @var Comment|null * @var Comment|null
* *
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment")
* @ORM\JoinColumn(name="to_comment_id", nullable=true) * @ORM\JoinColumn(name="to_comment_id", nullable=true)
*/ */

View file

@ -5,6 +5,7 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* Post * Post
@ -23,6 +24,8 @@ class Post
/** /**
* @var int * @var int
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="id", type="string", length=16) * @ORM\Column(name="id", type="string", length=16)
* @ORM\Id * @ORM\Id
*/ */
@ -31,6 +34,8 @@ class Post
/** /**
* @var string * @var string
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="text", type="text") * @ORM\Column(name="text", type="text")
*/ */
private $text; private $text;
@ -38,6 +43,8 @@ class Post
/** /**
* @var \DateTime * @var \DateTime
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="created_at", type="datetime") * @ORM\Column(name="created_at", type="datetime")
*/ */
private $createdAt; private $createdAt;
@ -45,6 +52,8 @@ class Post
/** /**
* @var string * @var string
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="type", type="string", length=6) * @ORM\Column(name="type", type="string", length=6)
*/ */
private $type; private $type;
@ -66,6 +75,8 @@ class Post
/** /**
* @var User * @var User
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author") * @ORM\JoinColumn(name="author")
*/ */
@ -74,6 +85,8 @@ class Post
/** /**
* @var Tag[]|ArrayCollection * @var Tag[]|ArrayCollection
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EXTRA_LAZY") * @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="posts.posts_tags", * @ORM\JoinTable(name="posts.posts_tags",
* joinColumns={@ORM\JoinColumn(name="post_id")}, * joinColumns={@ORM\JoinColumn(name="post_id")},
@ -84,6 +97,10 @@ class Post
/** /**
* @var Comment[]|ArrayCollection * @var Comment[]|ArrayCollection
*
* @Serializer\Groups({"post_show"})
*
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post")
*/ */
private $comments; private $comments;

View file

@ -3,6 +3,7 @@
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* Tag * Tag
@ -26,6 +27,8 @@ class Tag
/** /**
* @var string * @var string
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="text", type="text", unique=true) * @ORM\Column(name="text", type="text", unique=true)
*/ */
private $text; private $text;