Example #1
0
 /**
  * Adds an Item to the feed
  *
  * @param \SimpleXMLElement        $element
  * @param \Nekland\Bundle\FeedBundle\Feed $feed
  * @return void
  */
 protected function addItem(\SimpleXMLElement $element, Feed $feed)
 {
     $item = new GenericItem();
     foreach ($element as $subElement) {
         $method = isset(self::$methodMapping[$subElement->getName()]) ? self::$methodMapping[$subElement->getName()] : 'setFeed' . ucfirst($subElement->getName());
         if ($subElement->getName() == 'author') {
             $item->setFeedAuthor(array('name' => (string) $subElement));
         } else {
             if ($subElement->getName() == 'pubDate') {
                 $date = \DateTime::createFromFormat(\DateTime::RSS, (string) $subElement);
                 $item->setFeedDate($date);
             } else {
                 if ($subElement->getName() == 'link') {
                     $routes = array();
                     $routes[0] = array('url' => (string) $subElement);
                     $item->setFeedRoutes($routes);
                 } elseif (count($subElement) === 0) {
                     $item->{$method}((string) $subElement);
                 } else {
                     $item->{$method}($this->extractParam($subElement));
                 }
             }
         }
     }
     $feed->add($item);
 }