Ejemplo n.º 1
0
 /**
  * Write an ItemInterface into the feed
  *
  * @param \Nekland\FeedBundle\XML\XMLManager $xml
  * @param \Nekland\FeedBundle\Item\ItemInterface $item
  * @return void
  */
 private function writeItem(XMLManager $xml, ItemInterface $item)
 {
     $nodeItem = $this->createItem($xml);
     $xml->addTextNode('title', $item->getFeedTitle(), $nodeItem);
     $type = $this->itemHas($item, 'getAtomContentType') ? $item->getAtomContentType() : null;
     $content = $xml->addTextNode('content', $type === 'xhtml' ? $item->getFeedDescription() : htmlentities($item->getFeedDescription(), ENT_COMPAT, 'UTF-8'), $nodeItem);
     if (!empty($type)) {
         $content->setAttribute('type', $type);
     }
     if ($this->itemHas($item, 'getAtomContentLanguage')) {
         $content->setAttribute('xml:lang', $item->getAtomContentLanguage());
     }
     $id = $item->getFeedId();
     if (empty($id)) {
         throw new \InvalidArgumentException('The method « getFeedId » CAN\'T return an empty value.');
     }
     $xml->addTextNode('id', $id, $nodeItem);
     $xml->addTextNode('published', $item->getFeedDate()->format(\DateTime::ATOM), $nodeItem);
     $date = new \DateTime();
     $xml->addTextNode('updated', $item->getFeedDate()->format(\DateTime::ATOM), $nodeItem);
     if ($this->itemHas($item, 'getFeedAuthor')) {
         if ($author = $item->getFeedAuthor()) {
             $authorNode = $this->createAuthor($xml, $author);
             $nodeItem->appendChild($authorNode);
         }
     }
     if ($this->itemHas($item, 'getSummary')) {
         $type = $this->itemHas($item, 'getAtomSummaryType') ? $item->getAtomSummaryType() : null;
         $summary = $xml->addTextNode('category', $type === 'xhtml' ? $item->getFeedDescription() : htmlentities($item->getFeedSummary(), ENT_COMPAT, 'UTF-8'), $nodeItem);
         if (!empty($type)) {
             $summary->setAttribute('type', $type);
         }
     }
     if ($this->itemHas($item, 'getAtomContributors')) {
         if ($contributors = $item->getAtomContributors($item)) {
             foreach ($contributors as $contributor) {
                 $contribNode = $this->createContributor($xml, $contributor);
                 $nodeItem->appendChild($contribNode);
             }
         }
     }
     $routes = $item->getFeedRoutes();
     foreach ($routes as $route) {
         $linkNode = $this->createLink($xml, $route);
         $nodeItem->appendChild($linkNode);
     }
 }
Ejemplo n.º 2
0
 private function getRoute(ItemInterface $item)
 {
     $route = $item->getFeedRoutes();
     //var_dump($item); exit();
     //var_dump($route); exit();
     if (!isset($route[0]) || !is_array($route[0])) {
         throw new \InvalidArgumentException('The « getFeedRoutes » method have to return an array of routes.');
     }
     $route = $route[0];
     if (!empty($route['route']) && is_array($route['route'])) {
         return $this->router->generate($route['route'][0], $route['route'][1], true);
     } else {
         if (!empty($route['url'])) {
             return $route['url'];
         } else {
             return null;
         }
     }
 }