예제 #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);
 }
예제 #2
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());
         $data = '';
         if ($subElement->getName() == 'link') {
             if (($routes = $item->getFeedRoutes()) == null) {
                 $routes = array();
             }
             $i = count($routes);
             foreach ($subElement->attributes() as $attrName => $attrValue) {
                 if ($attrName == 'href') {
                     $routes[$i]['url'] = $attrValue;
                 } else {
                     $routes[$i][$attrName] = $attrValue;
                 }
             }
             $data = $routes;
         } elseif ($subElement->getName() == 'published') {
             $data = \DateTime::createFromFormat(\DateTime::ATOM, (string) $subElement);
         } elseif (count($subElement) === 0 && $subElement->getName() != 'updated') {
             if ($subElement->getName() == 'content' || $subElement->getName() == 'title' || $subElement->getName() == 'summary') {
                 $typemethod = 'setAtom' . $subElement->getName() . 'Type';
                 $attributes = $subElement->attributes();
                 if (isset($attributes['type'])) {
                     $item->{$typemethod}($attributes['type']);
                 }
                 if (isset($attributes['xml:lang']) && $subElement->getName() == 'content') {
                     $item->setAtomContentLanguage($attributes['xml:lang']);
                 }
             }
             $data = (string) $subElement;
         } else {
             $data = $this->extractParam($subElement);
         }
         $reflection = new \ReflectionClass(get_class($item));
         if ($reflection->hasMethod($method)) {
             $item->{$method}($data);
         }
     }
     $feed->add($item);
 }