Browse Source

Injection de repo

François Drouhard 2 years ago
parent
commit
8920bcf35c
1 changed files with 13 additions and 8 deletions
  1. 13 8
      src/Service/UniciteCollections.php

+ 13 - 8
src/Service/UniciteCollections.php

@@ -2,29 +2,34 @@
 
 namespace App\Service;
 
+use App\Repository\GenreRepository;
+use App\Repository\RealisateurRepository;
 use Doctrine\ORM\EntityManagerInterface;
+use App\Entity\Film;
 
 /**
  * Faire des recherches de films
  */
 class UniciteCollections
 {
-    protected $em;
+    protected $repoReal;
+    protected $repoGenre;
 
     /**
      * Search constructor.
      * @param EntityManagerInterface $em
      */
-    public function __construct(EntityManagerInterface $em)
+    public function __construct(RealisateurRepository $repoReal, GenreRepository $repoGenre)
     {
-        $this->em = $em;
+        $this->repoGenre = $repoGenre;
+        $this->repoReal = $repoReal;
     }
 
     /**
      * @param \App\Entity\Film $film
      * @return \App\Entity\Film
      */
-    public function assureUniciteCollections(\App\Entity\Film $film)
+    public function assureUniciteCollections(Film $film)
     {
         $film = $this->checkRealisateurs($film);
         $film = $this->checkGenres($film);
@@ -35,14 +40,14 @@ class UniciteCollections
      * @param \App\Entity\Film $film
      * @return \App\Entity\Film
      */
-    protected function checkRealisateurs(\App\Entity\Film $film)
+    protected function checkRealisateurs(Film $film, )
     {
         $realisateurs = $film->getRealisateurs();
         foreach ($realisateurs as $realisateur)
         {
             if ($realisateur->getId() == null)
             {
-                $recherche = $this->em->getRepository('App:Realisateur')->findOneBy(array('nomComplet'=>$realisateur->getNomComplet()));
+                $recherche = $this->repoReal->findOneBy(array('nomComplet'=>$realisateur->getNomComplet()));
                 if ($recherche != null)
                 {
                     $film->removeRealisateur($realisateur);
@@ -58,14 +63,14 @@ class UniciteCollections
      * @param \App\Entity\Film $film
      * @return \App\Entity\Film
      */
-    protected function checkGenres(\App\Entity\Film $film)
+    protected function checkGenres(Film $film)
     {
         $genres = $film->getGenres();
         foreach ($genres as $genre)
         {
             if ($genre->getId() == null)
             {
-                $recherche = $this->em->getRepository('App:Genre')->findOneBy(array('name'=>$genre->getName()));
+                $recherche = $this->repoGenre->findOneBy(array('name'=>$genre->getName()));
                 if ($recherche != null)
                 {
                     $film->removeGenre($genre);