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