Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added loaders handling

  • Loading branch information...
commit 434c9bb3e99ffc78b8662dd9d31422d085dae743 1 parent 05b0db5
Yohan Giarelli authored August 23, 2011
41  Factory/FeedFactory.php
@@ -7,6 +7,7 @@
7 7
 
8 8
 use Nekland\FeedBundle\Feed;
9 9
 use Nekland\FeedBundle\Renderer\RendererInterface;
  10
+use Nekland\FeedBundle\Loader\LoaderInterface;
10 11
 
11 12
 /**
12 13
  * This class represent an agnostic feed, Atom, Rss, etc..
@@ -46,14 +47,37 @@ public function has($feed)
46 47
         return isset($this->config['feeds'][$feed]);
47 48
     }
48 49
 
49  
-    public function render($feed, $renderer)
  50
+    /**
  51
+     * Renders a feed
  52
+     *
  53
+     * @param $feed
  54
+     * @param $renderer
  55
+     * @return
  56
+     */
  57
+    public function render($feed, $rendererName)
50 58
     {
51  
-        $renderer = $this->getRenderer($renderer);
  59
+        $renderer = $this->getRenderer($rendererName);
52 60
 
53 61
         return $renderer->render($this->get($feed));
54 62
     }
55 63
 
56 64
     /**
  65
+     * Loads a feed
  66
+     *
  67
+     * @param $feedName
  68
+     * @param $loader
  69
+     * @return Feed
  70
+     */
  71
+    public function load($feedName, $loaderName)
  72
+    {
  73
+        $loader = $this->getLoader($loaderName);
  74
+        $feed = $this->get($feedName);
  75
+        $loadedFeed = $loader->load($feed->getFilename($loader->getFormat()));
  76
+
  77
+        return $feed->merge($loadedFeed);
  78
+    }
  79
+
  80
+    /**
57 81
      * @throws \InvalidArgumentException
58 82
      * @param $feed
59 83
      * @return Feed
@@ -84,4 +108,17 @@ protected function getRenderer($name)
84 108
         throw new \InvalidArgumentException('Renderer '.$name.' doesn\'t exists');
85 109
     }
86 110
 
  111
+    /**
  112
+     * @param $name
  113
+     * @return LoaderInterface
  114
+     */
  115
+    protected function getLoader($name)
  116
+    {
  117
+        if (isset($this->config['loaders'][$name])) {
  118
+            return $this->container->get($this->config['loaders'][$name]['id']);
  119
+        }
  120
+
  121
+        throw new \InvalidArgumentException('Loader '.$name.' doesn\'t exists');
  122
+    }
  123
+
87 124
 }
11  Feed.php
@@ -117,6 +117,17 @@ public function get($param, $default = null)
117 117
         return isset($this->config[$param]) ? $this->config[$param] : $default;
118 118
     }
119 119
 
  120
+    public function merge(Feed $feed)
  121
+    {
  122
+        $this->items = array();
  123
+
  124
+        foreach ($feed as $item) {
  125
+            $this->add($item);
  126
+        }
  127
+
  128
+        return $this;
  129
+    }
  130
+
120 131
     /**
121 132
      * Retrieve an external iterator
122 133
      * @return Iterator
6  Loader/LoaderInterface.php
@@ -12,4 +12,10 @@
12 12
      * @return Feed
13 13
      */
14 14
     public function load($feedContent);
  15
+
  16
+    /**
  17
+     * @abstract
  18
+     * @return string (ex: "rss")
  19
+     */
  20
+    public function getFormat();
15 21
 }

0 notes on commit 434c9bb

Please sign in to comment.
Something went wrong with that request. Please try again.