/**
  * @inheritdoc
  */
 public function addCustomModifiers(FeedBuilderInterface $builder, array $options)
 {
     $builder->addTransformer(new CallbackTransformer(function ($value) {
         return $value['@href'];
     }), 'itunes:image', 50);
     $builder->addTransformer(new CallbackTransformer(function ($value) {
         return $value['@url'];
     }), 'enclosure', 51);
     $this->addModifierBetween($builder, new CallbackFilter(function (FeedItemBag $item) {
         if ($item->get('itunesexplicit') === 'yes') {
             throw new FilterException('Explicit content');
         }
     }), 2000, 2500);
     $this->addTransformerBetween($builder, new HtmlToMarkdownTransformer(new ConverterExtra(), new \HTMLPurifier($this->getPurifierConfig())), 'body', 3000, 3500);
     $this->addTransformerBetween($builder, new CallbackTransformer(function ($value) {
         if (strpos($value, ':') === false) {
             throw new TransformationFailedException('Invalid duration');
         }
         list($hours, $minutes, $seconds) = explode(':', $value);
         return 3600 * $hours + 60 * $minutes + $seconds;
     }), 'duration', 3000, 3500);
     $this->addTransformerBetween($builder, new CallbackTransformer(function ($value) {
         $repo = $this->doctrine->getRepository('TreeHouseIoIntegrationBundle:Author');
         if (null === ($author = $repo->findOneBy(['name' => $value]))) {
             $author = new Author();
             $author->setName($value);
             $this->doctrine->getManager()->persist($author);
             $this->doctrine->getManager()->flush($author);
         }
         return $author;
     }), 'author', 3000, 3500);
     $this->addModifierBetween($builder, new CallbackItemTransformer(function (FeedItemBag $item) {
         preg_match('~^(\\d+):~', $item->get('title'), $matches);
         $item->set('number', $matches[1]);
     }), 3000, 3500);
 }
Exemplo n.º 2
0
 /**
  * Adds the given modifier between the start and end index, if there is a vacant position.
  *
  * @param FeedBuilderInterface $builder
  * @param ModifierInterface    $modifier
  * @param int                  $startIndex
  * @param int                  $endIndex
  * @param bool                 $continue
  *
  * @throws \OutOfBoundsException
  */
 protected function addModifierBetween(FeedBuilderInterface $builder, ModifierInterface $modifier, $startIndex, $endIndex, $continue = null)
 {
     for ($position = $startIndex; $position <= $endIndex; ++$position) {
         if (!$builder->hasModifierAt($position)) {
             $builder->addModifier($modifier, $position, $continue);
             return;
         }
     }
     throw new \OutOfBoundsException(sprintf('No position left between %d and %d', $startIndex, $endIndex));
 }