示例#1
0
 /**
  * @inheritdoc
  */
 public function parse(ScrapedItemBag $item)
 {
     $crawler = $this->getDomCrawler($item->getOriginalData(), $item->getOriginalUrl());
     foreach ($this->modifiers as $position => $modifier) {
         // set crawler if needed
         if ($modifier instanceof CrawlerAwareInterface) {
             $modifier->setCrawler($crawler);
         }
         try {
             if ($modifier instanceof FilterInterface) {
                 $modifier->filter($item);
             }
             if ($modifier instanceof MapperInterface) {
                 $item = $modifier->map($item);
             }
             if ($modifier instanceof TransformerInterface) {
                 $modifier->transform($item);
             }
             if ($modifier instanceof ValidatorInterface) {
                 $modifier->validate($item);
             }
         } catch (FilterException $e) {
             // filter exceptions don't get to continue
             throw $e;
         } catch (ValidationException $e) {
             // validation exceptions don't get to continue
             throw $e;
         } catch (ModificationException $e) {
             // notify listeners of this failure, give them the option to stop propagation
             $event = new FailedItemModificationEvent($item, $modifier, $e);
             $event->setContinue($this->continues[$position]);
             $this->eventDispatcher->dispatch(FeedEvents::ITEM_MODIFICATION_FAILED, $event);
             if (!$event->getContinue()) {
                 throw $e;
             }
         }
     }
 }