From c3bce7b6e26c3697240cfc1bdb7c0789f35b814c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 28 Jun 2018 09:59:22 +0200 Subject: [PATCH] Only expose relevant attributes in the Person entity. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/Entity/Person.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Entity/Person.php b/src/Entity/Person.php index d1c7886..7897cfb 100644 --- a/src/Entity/Person.php +++ b/src/Entity/Person.php @@ -3,11 +3,17 @@ namespace App\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use JMS\Serializer\Annotation\ExclusionPolicy; +use JMS\Serializer\Annotation\Expose; /** * @ORM\Entity() * @ORM\Table(name="Person", indexes={@ORM\Index(name="authentification_idx", columns={"email", "password"}), - * @ORM\Index(name="search_idx", columns={"firstname", "lastname"})}); + * @ORM\Index(name="search_idx", columns={"firstname", "lastname", "email"})}); + * The following annotations tells the serializer to skip all properties which + * have not marked with @Expose. + * + * @ExclusionPolicy("all") */ class Person { @@ -15,31 +21,37 @@ class Person * @ORM\Id * @ORM\Column(type="bigint") * @ORM\GeneratedValue(strategy="AUTO") + * @Expose */ protected $id; /** * @ORM\Column(type="string") + * @Expose */ protected $firstname; /** * @ORM\Column(type="string") + * @Expose */ protected $lastname; /** * @ORM\Column(type="string", unique=true) + * @Expose */ protected $email; /** * @ORM\Column(type="string") + * @Expose */ protected $password; /** * @ORM\Column(type="boolean", options={"default":false}) + * @Expose */ protected $online; -- 2.34.1