vendor/sulu/sulu/src/Sulu/Bundle/MarkupBundle/Markup/HtmlMarkupParser.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\MarkupBundle\Markup;
  11. use Sulu\Bundle\MarkupBundle\Tag\TagRegistryInterface;
  12. /**
  13.  * Parses html content and replaces special tags.
  14.  */
  15. class HtmlMarkupParser implements MarkupParserInterface
  16. {
  17.     /**
  18.      * @var TagRegistryInterface
  19.      */
  20.     private $tagRegistry;
  21.     /**
  22.      * @var TagExtractorInterface
  23.      */
  24.     private $tagExtractor;
  25.     public function __construct(TagRegistryInterface $tagRegistryTagExtractorInterface $tagExtractor)
  26.     {
  27.         $this->tagRegistry $tagRegistry;
  28.         $this->tagExtractor $tagExtractor;
  29.     }
  30.     public function parse($content$locale)
  31.     {
  32.         if (=== $this->tagExtractor->count($content)) {
  33.             return $content;
  34.         }
  35.         $tagMatchGroups $this->tagExtractor->extract($content);
  36.         foreach ($tagMatchGroups as $tagMatchGroup) {
  37.             $tags $this->tagRegistry->getTag($tagMatchGroup->getTagName(), 'html'$tagMatchGroup->getNamespace())
  38.                 ->parseAll($tagMatchGroup->getTags(), $locale);
  39.             $content \str_replace(\array_keys($tags), \array_values($tags), $content);
  40.         }
  41.         return $this->parse($content$locale);
  42.     }
  43.     public function validate($content$locale)
  44.     {
  45.         if (=== $this->tagExtractor->count($content)) {
  46.             return [];
  47.         }
  48.         $result = [];
  49.         $tagMatchGroups $this->tagExtractor->extract($content);
  50.         foreach ($tagMatchGroups as $tagMatchGroup) {
  51.             $tags $this->tagRegistry->getTag($tagMatchGroup->getTagName(), 'html'$tagMatchGroup->getNamespace())
  52.                 ->validateAll($tagMatchGroup->getTags(), $locale);
  53.             $result \array_merge($result$tags);
  54.         }
  55.         return $result;
  56.     }
  57. }