1 | <?php |
||
24 | abstract class AbstractBlock extends Node |
||
25 | { |
||
26 | /** |
||
27 | * Used for storage of arbitrary data. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | public $data = []; |
||
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | protected $open = true; |
||
37 | |||
38 | /** |
||
39 | * @var bool |
||
40 | */ |
||
41 | protected $lastLineBlank = false; |
||
42 | |||
43 | /** |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $startLine; |
||
47 | |||
48 | /** |
||
49 | * @var int |
||
50 | */ |
||
51 | protected $endLine; |
||
52 | |||
53 | /** |
||
54 | * @param Node|null $node |
||
55 | */ |
||
56 | 2043 | protected function setParent(Node $node = null) |
|
57 | { |
||
58 | 2043 | if ($node && !$node instanceof self) { |
|
59 | 3 | throw new \InvalidArgumentException('Parent of block must also be block (can not be inline)'); |
|
60 | } |
||
61 | |||
62 | 2040 | parent::setParent($node); |
|
63 | 2040 | } |
|
64 | |||
65 | /** |
||
66 | * @return bool |
||
67 | */ |
||
68 | 2031 | public function isContainer(): bool |
|
72 | |||
73 | /** |
||
74 | * @return bool |
||
75 | */ |
||
76 | 30 | public function hasChildren(): bool |
|
80 | |||
81 | /** |
||
82 | * Returns true if this block can contain the given block as a child node |
||
83 | * |
||
84 | * @param AbstractBlock $block |
||
85 | * |
||
86 | * @return bool |
||
87 | */ |
||
88 | abstract public function canContain(AbstractBlock $block): bool; |
||
89 | |||
90 | /** |
||
91 | * Whether this is a code block |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | abstract public function isCode(): bool; |
||
96 | |||
97 | /** |
||
98 | * @param Cursor $cursor |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | abstract public function matchesNextLine(Cursor $cursor): bool; |
||
103 | |||
104 | /** |
||
105 | * @param int $startLine |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | 2058 | public function setStartLine(int $startLine) |
|
118 | |||
119 | /** |
||
120 | * @return int |
||
121 | */ |
||
122 | 3 | public function getStartLine(): int |
|
123 | { |
||
124 | 3 | return $this->startLine; |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * @param int $endLine |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | 3 | public function setEndLine(int $endLine) |
|
133 | { |
||
134 | 3 | $this->endLine = $endLine; |
|
135 | |||
136 | 3 | return $this; |
|
137 | } |
||
138 | |||
139 | /** |
||
140 | * @return int |
||
141 | */ |
||
142 | 3 | public function getEndLine(): int |
|
143 | { |
||
144 | 3 | return $this->endLine; |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * Whether the block ends with a blank line |
||
149 | * |
||
150 | * @return bool |
||
151 | */ |
||
152 | 246 | public function endsWithBlankLine(): bool |
|
156 | |||
157 | /** |
||
158 | * @param bool $blank |
||
159 | */ |
||
160 | 2028 | public function setLastLineBlank(bool $blank) |
|
164 | |||
165 | /** |
||
166 | * Determines whether the last line should be marked as blank |
||
167 | * |
||
168 | * @param Cursor $cursor |
||
169 | * @param int $currentLineNumber |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | 1779 | public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool |
|
177 | |||
178 | /** |
||
179 | * Whether the block is open for modifications |
||
180 | * |
||
181 | * @return bool |
||
182 | */ |
||
183 | 1125 | public function isOpen(): bool |
|
187 | |||
188 | /** |
||
189 | * Finalize the block; mark it closed for modification |
||
190 | * |
||
191 | * @param ContextInterface $context |
||
192 | * @param int $endLineNumber |
||
193 | */ |
||
194 | 2040 | public function finalize(ContextInterface $context, int $endLineNumber) |
|
205 | |||
206 | /** |
||
207 | * @param string $key |
||
208 | * @param mixed $default |
||
209 | * |
||
210 | * @return mixed |
||
211 | */ |
||
212 | 1992 | public function getData(string $key, $default = null) |
|
216 | } |
||
217 |