Exemplo n.º 1
0
 private function extractFeed(\DOMElement $element)
 {
     $feed = new Feed();
     foreach (self::$feedPropertiesMapping as $nodeName => $methodName) {
         $feed->{$methodName}($this->getNodeValueByTagName($element, $nodeName));
     }
     if ($date = $this->getNodeValueByTagName($element, 'pubDate')) {
         $feed->setPublishedDate(\DateTime::createFromFormat(\DateTime::RSS, $date));
     }
     $feed->setLastFetched(new \DateTime());
     return $feed;
 }
Exemplo n.º 2
0
 /**
  * @param Feed $feed
  * @depends testSaveFeeds
  */
 public function testSaveSameFeed(Feed $feed)
 {
     $store = new PdoStore($this->dsn, null, null);
     // we should search for feed
     $feed->setId(null);
     $record = new Record();
     $record->setTitle('item 2');
     $record->setPublicationDate(new \DateTime('-10 hours'));
     $feed->addRecord($record);
     $store->save($feed);
     $loadedFeed = $store->loadFeed(1);
     $records = $store->loadItems($loadedFeed->getId());
     static::assertEquals($record->getTitle(), $records[2]->getTitle());
 }
Exemplo n.º 3
0
 private function extractFeed(\DOMElement $element)
 {
     $feed = new Feed();
     foreach (self::$feedPropertiesMapping as $nodeName => $methodName) {
         $feed->{$methodName}($this->getNodeValueByTagName($element, $nodeName));
     }
     if ($date = $this->getNodeValueByTagName($element, 'updated')) {
         $feed->setPublishedDate(\DateTime::createFromFormat(\DateTime::ATOM, $date));
     }
     $nodeList = $element->getElementsByTagName('link');
     foreach ($nodeList as $nodeResult) {
         /** @var \DomElement $nodeResult */
         if ($nodeResult->getAttribute('rel') === 'alternate') {
             $feed->setLink($nodeResult->getAttribute('href'));
             break;
         }
     }
     if (!$feed->getLink()) {
         $feed->setLink($this->getNodeValueByTagName($element, 'id'));
     }
     $feed->setLastFetched(new \DateTime());
     return $feed;
 }
Exemplo n.º 4
0
 private function hydrateFeed(array $row)
 {
     $feed = new Feed();
     $feed->setId($row['id']);
     $feed->setSource($row['source']);
     $feed->setLink($row['link']);
     $feed->setDescription($row['description']);
     $feed->setTitle($row['title']);
     $feed->setPublishedDate(new \DateTime($row['published_date']));
     $feed->setLastFetched(new \DateTime($row['last_fetched']));
     $feed->setLastModified(new \DateTime($row['last_modified']));
     return $feed;
 }