Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function map(ParameterBag $item)
 {
     $bag = new FeedItemBag($this->feed, call_user_func($this->originalIdCallback, $item), $item->all());
     $bag->setOriginalUrl(call_user_func($this->originalUrlCallback, $item));
     $bag->setDatetimeModified(call_user_func($this->modificationDateCallback, $item));
     return $bag;
 }
 /**
  * @dataProvider getModifiedItems
  */
 public function testModifiedItems(\DateTime $sourceDate, \DateTime $itemDate = null)
 {
     $this->source->setDatetimeModified($sourceDate);
     $item = new FeedItemBag(new FeedMock(1234), '123abc');
     $item->setDatetimeModified($itemDate);
     $filter = new ModifiedItemFilter($this->sourceManager);
     $filter->filter($item);
 }
Ejemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function handle(FeedItemBag $item)
 {
     // get source and set the data to it
     $source = $this->sourceManager->findSourceByFeedOrCreate($item->getFeed(), $item->getOriginalId(), $item->getOriginalUrl());
     // save data
     $source->setData($item->all());
     $source->setOriginalUrl($item->getOriginalUrl());
     try {
         $this->validate($source);
         $this->sourceManager->persist($source);
         $this->sourceManager->flush($source);
         return $source;
     } catch (\Exception $exception) {
         $this->sourceManager->detach($source);
         throw new FailedItemException($source, $exception->getMessage(), $exception->getCode(), $exception);
     }
 }
 /**
  * @param Feed   $feed
  * @param string $name
  * @param string $feedType
  *
  * @return FeedItemBag
  */
 protected function getExpectedItemFixture(Feed $feed, $name, $feedType)
 {
     $refl = new \ReflectionClass(get_class($this));
     $phpFile = sprintf('%s/fixtures/%s/%s.php', dirname($refl->getFilename()), $feedType, $name);
     /** @var array $expected */
     $expected = (include $phpFile);
     $item = new FeedItemBag($feed, $expected['id'], $expected['item']);
     if (isset($expected['url'])) {
         $item->setOriginalUrl($expected['url']);
     }
     if (isset($expected['date'])) {
         $item->setDatetimeModified($expected['date']);
     }
     return $item;
 }