TestDelimiterProcessor.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java)
  9. * - (c) Atlassian Pty Ltd
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. namespace League\CommonMark\Tests\Functional\Delimiter;
  15. use League\CommonMark\Delimiter\DelimiterInterface;
  16. use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
  17. use League\CommonMark\Node\Inline\AbstractStringContainer;
  18. use League\CommonMark\Node\Inline\Text;
  19. final class TestDelimiterProcessor implements DelimiterProcessorInterface
  20. {
  21. private string $char;
  22. private int $length;
  23. public function __construct(string $char, int $length)
  24. {
  25. $this->char = $char;
  26. $this->length = $length;
  27. }
  28. public function getOpeningCharacter(): string
  29. {
  30. return $this->char;
  31. }
  32. public function getClosingCharacter(): string
  33. {
  34. return $this->char;
  35. }
  36. public function getMinLength(): int
  37. {
  38. return $this->length;
  39. }
  40. public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int
  41. {
  42. return $this->length;
  43. }
  44. public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse): void
  45. {
  46. $opener->insertAfter(new Text('(' . $this->length . ')'));
  47. $closer->insertBefore(new Text('(/' . $this->length . ')'));
  48. }
  49. }