Kaynağa Gözat

Mise en place des factory (sites).

bastien 13 yıl önce
ebeveyn
işleme
a5bf50a0c9

+ 4 - 4
src/Muzich/CoreBundle/DataFixtures/ORM/LoadElementData.php Dosyayı Görüntüle

@@ -76,10 +76,10 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
76 76
     $joelle  = $this->entity_manager->merge($this->getReference('user_joelle'));
77 77
 
78 78
     // 'youtube', 'soundclound', 'son2teuf', 'jamendo'
79
-    $youtube     = $this->entity_manager->merge($this->getReference('element_type_youtube'));
80
-    $soundclound = $this->entity_manager->merge($this->getReference('element_type_soundclound'));
81
-    $son2teuf    = $this->entity_manager->merge($this->getReference('element_type_son2teuf'));
82
-    $jamendo     = $this->entity_manager->merge($this->getReference('element_type_jamendo'));
79
+    $youtube     = $this->entity_manager->merge($this->getReference('element_type_youtube.com'));
80
+    $soundclound = $this->entity_manager->merge($this->getReference('element_type_soundcloud.com'));
81
+    $son2teuf    = $this->entity_manager->merge($this->getReference('element_type_son2teuf.org'));
82
+    $jamendo     = $this->entity_manager->merge($this->getReference('element_type_jamendo.com'));
83 83
     
84 84
     $this->createElement('youtube_heretik_1', 'Heretik System Popof - Resistance', 
85 85
       'http://www.youtube.com/watch?v=tq4DjQK7nsM',

+ 3 - 3
src/Muzich/CoreBundle/DataFixtures/ORM/LoadElementTypeData.php Dosyayı Görüntüle

@@ -39,10 +39,10 @@ class LoadElementTypeData  extends AbstractFixture implements OrderedFixtureInte
39 39
   public function load($entity_manager)
40 40
   {
41 41
     $this->entity_manager = $entity_manager;
42
-
42
+    
43 43
     foreach (array(
44
-      'youtube' => 'Youtube', 'soundclound' => 'SoundCloud', 
45
-      'son2teuf' => 'Son2Teuf', 'jamendo' => 'jamendo'
44
+      'youtube.com' => 'Youtube', 'soundcloud.com' => 'SoundCloud', 
45
+      'son2teuf.org' => 'Son2Teuf', 'jamendo.com' => 'jamendo'
46 46
       ) as $id => $name)
47 47
     {
48 48
       $this->createElementType($id, $name);

+ 26 - 4
src/Muzich/CoreBundle/ElementFactory/ElementFactory.php Dosyayı Görüntüle

@@ -6,6 +6,8 @@ use Muzich\CoreBundle\Entity\Element;
6 6
 use Muzich\CoreBundle\Entity\User;
7 7
 use Doctrine\ORM\EntityManager;
8 8
 
9
+use Muzich\CoreBundle\ElementFactory\Site\YoutubeFactory;
10
+
9 11
 /**
10 12
  * 
11 13
  *
@@ -14,10 +16,11 @@ use Doctrine\ORM\EntityManager;
14 16
 class ElementFactory
15 17
 {
16 18
   
17
-  const TYPE_UNKNOW = 'unknow';
18
-  
19 19
   protected $types = array(
20
-    'youtube', 'soundclound', 'son2teuf', 'jamendo'
20
+    'youtube.com'    => 'YoutubeFactory', 
21
+    'soundcloud.com' => 'SoundCloudFactory', 
22
+    'son2teuf.org'   => 'Son2TeufFactory', 
23
+    'jamendo.com'    => 'JamendoFactory'
21 24
   );
22 25
   
23 26
   protected $em;
@@ -75,7 +78,18 @@ class ElementFactory
75 78
    */
76 79
   protected function determineType()
77 80
   {
78
-    $this->element->setType(null);
81
+    preg_match("/^(http:\/\/)?([^\/]+)/i", $this->element->getUrl(), $chaines);
82
+    $host = $chaines[2];
83
+    // Repérer les derniers segments
84
+    preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$chaines);
85
+    
86
+    $type = null;
87
+    if (array_key_exists($chaines[0], $this->types))
88
+    {
89
+      $type = $this->em->getRepository('MuzichCoreBundle:ElementType')->find($chaines[0]);
90
+    }
91
+    
92
+    $this->element->setType($type);
79 93
   }
80 94
   
81 95
   /**
@@ -89,6 +103,14 @@ class ElementFactory
89 103
     // Instanciation d'un objet factory correspondant au type, par exemple
90 104
     // YoutubeFactory, qui répondant a une implementation retournera ces infos.
91 105
   
106
+    if ($this->element->getType())
107
+    {
108
+      $factory_name = $this->types[$this->element->getType()->getId()];
109
+      
110
+      $site_factory = new YoutubeFactory($this->element);
111
+      $this->element->getEmbed($site_factory->getEmbedCode());
112
+    }
113
+    
92 114
   }
93 115
     
94 116
 }

+ 28 - 0
src/Muzich/CoreBundle/ElementFactory/Site/BaseFactory.php Dosyayı Görüntüle

@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+use Muzich\CoreBundle\Entity\Element;
6
+
7
+/**
8
+ *
9
+ * @author bux
10
+ */
11
+class BaseFactory implements FactoryInterface
12
+{
13
+  
14
+  protected $element;
15
+  
16
+  public function __construct(Element $element)
17
+  {
18
+    $this->element = $element;
19
+  }
20
+  
21
+  public function getEmbedCode()
22
+  {
23
+    return null;
24
+  }
25
+  
26
+}
27
+
28
+?>

+ 16 - 0
src/Muzich/CoreBundle/ElementFactory/Site/FactoryInterface.php Dosyayı Görüntüle

@@ -0,0 +1,16 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+use Muzich\CoreBundle\Entity\Element;
6
+
7
+interface FactoryInterface
8
+{
9
+  
10
+  public function __construct(Element $element);
11
+  
12
+  public function getEmbedCode();
13
+  
14
+}
15
+
16
+?>

+ 15 - 0
src/Muzich/CoreBundle/ElementFactory/Site/JamendoFactory.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+/**
6
+ * 
7
+ *
8
+ * @author bux
9
+ */
10
+class JamendoFactory extends BaseFactory
11
+{
12
+  
13
+}
14
+
15
+?>

+ 15 - 0
src/Muzich/CoreBundle/ElementFactory/Site/Son2TeufFactory.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+/**
6
+ * 
7
+ *
8
+ * @author bux
9
+ */
10
+class Son2TeufFactory extends BaseFactory
11
+{
12
+  
13
+}
14
+
15
+?>

+ 15 - 0
src/Muzich/CoreBundle/ElementFactory/Site/SoundCloudFactory.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+/**
6
+ * 
7
+ *
8
+ * @author bux
9
+ */
10
+class SoundCloudFactory extends BaseFactory
11
+{
12
+  
13
+}
14
+
15
+?>

+ 15 - 0
src/Muzich/CoreBundle/ElementFactory/Site/YoutubeFactory.php Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+/**
6
+ * 
7
+ *
8
+ * @author bux
9
+ */
10
+class YoutubeFactory extends BaseFactory
11
+{
12
+  
13
+}
14
+
15
+?>

+ 20 - 0
src/Muzich/CoreBundle/Entity/Element.php Dosyayı Görüntüle

@@ -267,6 +267,26 @@ class Element
267 267
   }
268 268
 
269 269
   /**
270
+   * Set embed
271
+   *
272
+   * @param string $code
273
+   */
274
+  public function setEmbed($code)
275
+  {
276
+      $this->embed = $code;
277
+  }
278
+
279
+  /**
280
+   * Get embed
281
+   *
282
+   * @return string 
283
+   */
284
+  public function getEmbed()
285
+  {
286
+      return $this->embed;
287
+  }
288
+
289
+  /**
270 290
    * Set created
271 291
    *
272 292
    * @param date $created

+ 1 - 1
src/Muzich/CoreBundle/Entity/ElementType.php Dosyayı Görüntüle

@@ -19,7 +19,7 @@ class ElementType
19 19
   
20 20
   /**
21 21
    * @ORM\Id
22
-   * @ORM\Column(type="string", length=12)
22
+   * @ORM\Column(type="string", length=18)
23 23
    * @var type string
24 24
    */
25 25
   protected $id;