private function processIteration($text, ProcessorContext $context, ProcessedShortcode $parent = null)
 {
     if (null !== $this->recursionDepth && $context->recursionLevel > $this->recursionDepth) {
         return $text;
     }
     $context->parent = $parent;
     $context->text = $text;
     $filterEvent = new FilterShortcodesEvent($this->parser->parse($text), $parent);
     $this->dispatchEvent(Events::FILTER_SHORTCODES, $filterEvent);
     $shortcodes = $filterEvent->getShortcodes();
     $replaces = array();
     $baseOffset = $parent && $shortcodes ? mb_strpos($parent->getShortcodeText(), $shortcodes[0]->getText(), null, 'utf-8') - $shortcodes[0]->getOffset() + $parent->getOffset() : 0;
     foreach ($shortcodes as $shortcode) {
         $hasNamePosition = array_key_exists($shortcode->getName(), $context->namePosition);
         $context->baseOffset = $baseOffset + $shortcode->getOffset();
         $context->position++;
         $context->namePosition[$shortcode->getName()] = $hasNamePosition ? $context->namePosition[$shortcode->getName()] + 1 : 1;
         $context->shortcodeText = $shortcode->getText();
         $context->offset = $shortcode->getOffset();
         $context->shortcode = $shortcode;
         $context->textContent = $shortcode->getContent();
         $handler = $this->handlers->get($shortcode->getName());
         $replace = $this->processHandler($shortcode, $context, $handler);
         $replaces[] = new ReplacedShortcode($shortcode, $replace);
     }
     $replaces = array_filter($replaces);
     $applyEvent = new ReplaceShortcodesEvent($text, $replaces, $parent);
     $this->dispatchEvent(Events::REPLACE_SHORTCODES, $applyEvent);
     return $applyEvent->hasResult() ? $applyEvent->getResult() : $this->applyReplaces($text, $replaces);
 }
Ejemplo n.º 2
0
 private function processIteration($text, ProcessorContext $context, ShortcodeInterface $parent = null)
 {
     if (null !== $this->recursionDepth && $context->recursionLevel > $this->recursionDepth) {
         return $text;
     }
     $context->parent = $parent;
     $context->text = $text;
     $filterEvent = new FilterShortcodesEvent($this->parser->parse($text), $parent);
     $this->dispatchEvent(Events::FILTER_SHORTCODES, $filterEvent);
     $shortcodes = $filterEvent->getShortcodes();
     $replaces = array();
     foreach ($shortcodes as $shortcode) {
         $this->prepareHandlerContext($shortcode, $context);
         $handler = $this->handlers->get($shortcode->getName());
         $replace = $this->processHandler($shortcode, $context, $handler);
         $replaces[] = new ReplacedShortcode($shortcode, $replace);
     }
     $replaces = array_filter($replaces);
     $applyEvent = new ReplaceShortcodesEvent($text, $replaces, $parent);
     $this->dispatchEvent(Events::REPLACE_SHORTCODES, $applyEvent);
     return $applyEvent->hasResult() ? $applyEvent->getResult() : $this->applyReplaces($text, $replaces);
 }