1<?php 2 3/* 4 * This file is part of the league/commonmark package. 5 * 6 * (c) Colin O'Dell <colinodell@gmail.com> 7 * 8 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) 9 * - (c) John MacFarlane 10 * 11 * For the full copyright and license information, please view the LICENSE 12 * file that was distributed with this source code. 13 */ 14 15namespace League\CommonMark\Delimiter; 16 17use League\CommonMark\Inline\Element\AbstractStringContainer; 18 19final class Delimiter implements DelimiterInterface 20{ 21 /** @var string */ 22 private $char; 23 24 /** @var int */ 25 private $length; 26 27 /** @var int */ 28 private $originalLength; 29 30 /** @var AbstractStringContainer */ 31 private $inlineNode; 32 33 /** @var DelimiterInterface|null */ 34 private $previous; 35 36 /** @var DelimiterInterface|null */ 37 private $next; 38 39 /** @var bool */ 40 private $canOpen; 41 42 /** @var bool */ 43 private $canClose; 44 45 /** @var bool */ 46 private $active; 47 48 /** @var int|null */ 49 private $index; 50 51 /** 52 * @param string $char 53 * @param int $numDelims 54 * @param AbstractStringContainer $node 55 * @param bool $canOpen 56 * @param bool $canClose 57 * @param int|null $index 58 */ 59 public function __construct(string $char, int $numDelims, AbstractStringContainer $node, bool $canOpen, bool $canClose, ?int $index = null) 60 { 61 $this->char = $char; 62 $this->length = $numDelims; 63 $this->originalLength = $numDelims; 64 $this->inlineNode = $node; 65 $this->canOpen = $canOpen; 66 $this->canClose = $canClose; 67 $this->active = true; 68 $this->index = $index; 69 } 70 71 public function canClose(): bool 72 { 73 return $this->canClose; 74 } 75 76 /** 77 * @param bool $canClose 78 * 79 * @return void 80 */ 81 public function setCanClose(bool $canClose) 82 { 83 $this->canClose = $canClose; 84 } 85 86 public function canOpen(): bool 87 { 88 return $this->canOpen; 89 } 90 91 public function isActive(): bool 92 { 93 return $this->active; 94 } 95 96 public function setActive(bool $active) 97 { 98 $this->active = $active; 99 } 100 101 public function getChar(): string 102 { 103 return $this->char; 104 } 105 106 public function getIndex(): ?int 107 { 108 return $this->index; 109 } 110 111 public function getNext(): ?DelimiterInterface 112 { 113 return $this->next; 114 } 115 116 public function setNext(?DelimiterInterface $next) 117 { 118 $this->next = $next; 119 } 120 121 public function getLength(): int 122 { 123 return $this->length; 124 } 125 126 public function setLength(int $length) 127 { 128 $this->length = $length; 129 } 130 131 public function getOriginalLength(): int 132 { 133 return $this->originalLength; 134 } 135 136 public function getInlineNode(): AbstractStringContainer 137 { 138 return $this->inlineNode; 139 } 140 141 public function getPrevious(): ?DelimiterInterface 142 { 143 return $this->previous; 144 } 145 146 public function setPrevious(?DelimiterInterface $previous): DelimiterInterface 147 { 148 $this->previous = $previous; 149 150 return $this; 151 } 152} 153