浏览代码

Ajout des Asserts

François 6 年之前
父节点
当前提交
64bffd2cac
共有 2 个文件被更改,包括 18 次插入20 次删除
  1. 0 5
      src/AppBundle/Controller/VideothequeController.php
  2. 18 15
      src/AppBundle/Entity/Film.php

+ 0 - 5
src/AppBundle/Controller/VideothequeController.php

@@ -76,11 +76,6 @@ class VideothequeController extends Controller
             }
 
 			$em->persist($film);
-            if ($film->getMediaVideo()->getType() == null) {
-                $media = $film->getMediaVideo();
-                $film->setMediaVideo(null);
-                $em->remove($media);
-            }
 			$em->flush();
 			$this->addFlash('success', 'Le film a été ajouté');
 			return $this->redirectToRoute('videotheque_voirfilm', array('id'=>$film->getId()));

+ 18 - 15
src/AppBundle/Entity/Film.php

@@ -3,6 +3,8 @@
 namespace AppBundle\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Validator\Constraints as Assert;
+
 
 /**
  * Film
@@ -66,6 +68,7 @@ class Film
     }
 
     /**
+     * @Assert\Valid()
      * @ORM\OneToOne(targetEntity="AppBundle\Entity\MediaVideo", cascade={"persist","remove"})
      * @ORM\JoinColumn(nullable=true)
      */
@@ -106,9 +109,9 @@ class Film
     }
 
     /**
-     * @param mixed $mediaVideo
+     * @param \AppBundle\Entity\MediaVideo $mediaVideo
      */
-    public function setMediaVideo(\AppBundle\Entity\MediaVideo $mediaVideo = null)
+    public function setMediaVideo(MediaVideo $mediaVideo = null)
     {
         $this->mediaVideo = $mediaVideo;
     }
@@ -120,7 +123,7 @@ class Film
     private $genres;
 
     /**
-     * @return mixed
+     * @return \AppBundle\Entity\User $authered
      */
     public function getAuthered()
     {
@@ -128,9 +131,9 @@ class Film
     }
 
     /**
-     * @param mixed $authered
+     * @param \AppBundle\Entity\User $authered
      */
-    public function setAuthered($authered)
+    public function setAuthered(User $authered)
     {
         $this->authered = $authered;
         $this->addUserWantToView($authered);
@@ -229,7 +232,7 @@ class Film
      *
      * @return Film
      */
-    public function addRealisateur(\AppBundle\Entity\Realisateur $realisateur)
+    public function addRealisateur(Realisateur $realisateur)
     {
         $this->realisateurs[] = $realisateur;
 
@@ -241,7 +244,7 @@ class Film
      *
      * @param \AppBundle\Entity\Realisateur $realisateur
      */
-    public function removeRealisateur(\AppBundle\Entity\Realisateur $realisateur)
+    public function removeRealisateur(Realisateur $realisateur)
     {
         $this->realisateurs->removeElement($realisateur);
     }
@@ -264,7 +267,7 @@ class Film
      *
      * @return film
      */
-    public function addUserWantToView(\AppBundle\Entity\User $user)
+    public function addUserWantToView(User $user)
     {
         $this->usersWantToView[] = $user;
         $user->addFilm($this);
@@ -277,7 +280,7 @@ class Film
      *
      * @param \AppBundle\Entity\User $user
      */
-    public function removeUserWantToView(\AppBundle\Entity\User $user)
+    public function removeUserWantToView(User $user)
     {
         $this->usersWantToView->removeElement($user);
         $user->removeFilm($this);
@@ -297,7 +300,7 @@ class Film
      * Inverse ToSee
      * @param \AppBundle\Entity\User $user
      */
-    public function inverseUserWantToView(\AppBundle\Entity\User $user)
+    public function inverseUserWantToView(User $user)
     {
         if ($this->usersWantToView->contains($user)) {
             $this->removeUserWantToView($user);
@@ -315,7 +318,7 @@ class Film
      *
      * @return film
      */
-    public function addUserWhoSeen(\AppBundle\Entity\User $user)
+    public function addUserWhoSeen(User $user)
     {
         $this->usersWhoSeen[] = $user;
         $user->addFilmVu($this);
@@ -328,7 +331,7 @@ class Film
      *
      * @param \AppBundle\Entity\User $user
      */
-    public function removeUserWhoSeen(\AppBundle\Entity\User $user)
+    public function removeUserWhoSeen(User $user)
     {
         $this->usersWhoSeen->removeElement($user);
         $user->removeFilmVu($this);
@@ -348,7 +351,7 @@ class Film
      * Inverse ToSee
      * @param \AppBundle\Entity\User $user
      */
-    public function inverseUserWhoSeen(\AppBundle\Entity\User $user)
+    public function inverseUserWhoSeen(User $user)
     {
         if ($this->usersWhoSeen->contains($user)) {
             $this->removeUserWhoSeen($user);
@@ -374,7 +377,7 @@ class Film
      *
      * @return film
      */
-    public function addGenre(\AppBundle\Entity\Genre $genre)
+    public function addGenre(Genre $genre)
     {
         $this->genres[] = $genre;
         return $this;
@@ -386,7 +389,7 @@ class Film
      * @param \AppBundle\Entity\Genre $genre
      * @return Film
      */
-    public function removeGenre(\AppBundle\Entity\Genre $genre)
+    public function removeGenre(Genre $genre)
     {
         $this->genres->removeElement($genre);
         return $this;