Sfoglia il codice sorgente

Refactorisation de la factory de vimeo

Sevajol Bastien 11 anni fa
parent
commit
7924501e2d

+ 27 - 34
src/Muzich/CoreBundle/Factory/Elements/Vimeocom.php Vedi File

@@ -4,48 +4,33 @@ namespace Muzich\CoreBundle\Factory\Elements;
4 4
 
5 5
 use Muzich\CoreBundle\Factory\ElementFactory;
6 6
 use Muzich\CoreBundle\Entity\Element;
7
+use Muzich\CoreBundle\Factory\UrlMatchs;
8
+use Symfony\Component\DependencyInjection\Container;
9
+use Doctrine\ORM\EntityManager;
7 10
 
8
-/**
9
- * 
10
- *
11
- * @author bux
12
- */
13 11
 class Vimeocom extends ElementFactory
14 12
 {
15 13
   
16
-  public function retrieveDatas()
14
+  public function __construct(Element $element, Container $container, EntityManager $entity_manager)
17 15
   {
18
-    $url_clean = $this->getCleanedUrl();
19
-    $ref_id = null;
20
-    
21
-    // http://vimeo.com/43258820
22
-    if (preg_match("#\/([0-9]+)#", $url_clean, $chaines))
23
-    {
24
-      $ref_id = $chaines[1];
25
-    }
26
-    
27
-    if ($ref_id)
28
-    {
29
-      $this->element->setData(Element::DATA_REF_ID, $ref_id);
30
-      $this->getDataFromApi($ref_id);
31
-    }
16
+    $this->url_matchs = UrlMatchs::$vimeo;
17
+    parent::__construct($element, $container, $entity_manager);
32 18
   }
33 19
   
34
-  protected function getDataFromApi($ref_id)
20
+  public function proceedDatas()
35 21
   {
36
-    $data = $this->getJsonDataFromApiWithUrl('http://vimeo.com/api/v2/video/'.$ref_id.'.json');
37
-    
38
-    if (count($data))
39
-    {
40
-      if (array_key_exists('title', $data[0]))
41
-      {
42
-        $this->element->setData(Element::DATA_TITLE, $data[0]['title']);
43
-      }
44
-      if (array_key_exists('thumbnail_medium', $data[0]))
45
-      {
46
-        $this->element->setData(Element::DATA_THUMB_URL, $data[0]['thumbnail_medium']);
47
-      }
48
-    }
22
+    $this->setElementDatasWithApi();
23
+    $this->proceedEmbedCode();
24
+    $this->proceedThumbnailUrl();
25
+  }
26
+  
27
+  protected function setElementDatasWithApi()
28
+  {
29
+    $response = $this->getApiConnector()->getResponseForUrl('http://vimeo.com/api/v2/video/'.$this->url_analyzer->getRefId().'.json');
30
+    $this->getApiConnector()->setElementDatasWithResponse($response, array(
31
+      Element::DATA_TITLE       => array(0 => 'title'),
32
+      Element::DATA_THUMB_URL   => array(0 => 'thumbnail_medium')
33
+    ));
49 34
   }
50 35
   
51 36
   public function proceedEmbedCode()
@@ -61,4 +46,12 @@ class Vimeocom extends ElementFactory
61 46
       );
62 47
     }
63 48
   }
49
+  
50
+  public function proceedThumbnailUrl()
51
+  {
52
+    if (($thumb = $this->element->getData(Element::DATA_THUMB_URL)))
53
+    {
54
+      $this->element->setThumbnailUrl($thumb);
55
+    }
56
+  }
64 57
 }

+ 7 - 0
src/Muzich/CoreBundle/Factory/UrlMatchs.php Vedi File

@@ -76,4 +76,11 @@ class UrlMatchs
76 76
       "#^\/user\/([a-zA-Z0-9_-]+)\/playlist\/([a-zA-Z0-9]+)#" => 2
77 77
     )
78 78
   );
79
+  
80
+  public static $vimeo = array(
81
+    Element::TYPE_OTHER => array(
82
+      // http://vimeo.com/43258820
83
+      "#\/([0-9]+)#" => 1
84
+    )
85
+  );
79 86
 }

+ 2 - 1
src/Muzich/CoreBundle/Tests/ElementFactory/ElementFactoryTest.php Vedi File

@@ -568,7 +568,8 @@ class ElementFactoryTest extends UnitTest
568 568
     //$this->assertEquals(array(
569 569
     //  'data_ref_id' => '43258820',
570 570
     //  'data_title'  => 'Punish Yourself',
571
-    //  'data_thumb_url' => 'http://b.vimeocdn.com/ts/301/282/301282081_200.jpg'
571
+    //  'data_thumb_url' => 'http://b.vimeocdn.com/ts/301/282/301282081_200.jpg',
572
+    //  'data_type' => 'other'
572 573
     //),$this->proceed_element_datas_api(
573 574
     //  $bux, 
574 575
     //  'http://vimeo.com/43258820'