FakeInlineParser.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the league/commonmark package.
  5. *
  6. * (c) Colin O'Dell <colinodell@gmail.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace League\CommonMark\Tests\Unit\Parser\Inline;
  12. use League\CommonMark\Node\Inline\Text;
  13. use League\CommonMark\Parser\Inline\InlineParserInterface;
  14. use League\CommonMark\Parser\Inline\InlineParserMatch;
  15. use League\CommonMark\Parser\InlineParserContext;
  16. final class FakeInlineParser implements InlineParserInterface
  17. {
  18. /** @var string[] */
  19. private array $matches = [];
  20. private InlineParserMatch $start;
  21. public function __construct(InlineParserMatch $start)
  22. {
  23. $this->start = $start;
  24. }
  25. public function getMatchDefinition(): InlineParserMatch
  26. {
  27. return $this->start;
  28. }
  29. public function parse(InlineParserContext $inlineContext): bool
  30. {
  31. $match = $inlineContext->getFullMatch();
  32. $this->matches[] = $match;
  33. $inlineContext->getCursor()->advanceBy(\mb_strlen($match));
  34. $inlineContext->getContainer()->appendChild(new Text($match));
  35. return true;
  36. }
  37. /**
  38. * @return string[]
  39. */
  40. public function getMatches(): array
  41. {
  42. return $this->matches;
  43. }
  44. }