1 | <?php |
||
25 | abstract class AbstractBlock extends Node |
||
26 | { |
||
27 | /** |
||
28 | * Used for storage of arbitrary data. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | public $data = []; |
||
33 | |||
34 | /** |
||
35 | * @var ArrayCollection|string[] |
||
36 | */ |
||
37 | protected $strings; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $finalStringContents = ''; |
||
43 | |||
44 | /** |
||
45 | * @var bool |
||
46 | */ |
||
47 | protected $open = true; |
||
48 | |||
49 | /** |
||
50 | * @var bool |
||
51 | */ |
||
52 | protected $lastLineBlank = false; |
||
53 | |||
54 | /** |
||
55 | * @var int |
||
56 | */ |
||
57 | protected $startLine; |
||
58 | |||
59 | /** |
||
60 | * @var int |
||
61 | */ |
||
62 | protected $endLine; |
||
63 | |||
64 | /** |
||
65 | * Constructor |
||
66 | */ |
||
67 | 1971 | public function __construct() |
|
71 | |||
72 | /** |
||
73 | * @param Node|null $node |
||
74 | */ |
||
75 | 1863 | protected function setParent(Node $node = null) |
|
83 | |||
84 | /** |
||
85 | * @return bool |
||
86 | */ |
||
87 | 1863 | public function isContainer() |
|
91 | |||
92 | /** |
||
93 | * @return bool |
||
94 | */ |
||
95 | 1863 | public function hasChildren() |
|
99 | |||
100 | /** |
||
101 | * Returns true if this block can contain the given block as a child node |
||
102 | * |
||
103 | * @param AbstractBlock $block |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | abstract public function canContain(AbstractBlock $block); |
||
108 | |||
109 | /** |
||
110 | * Returns true if block type can accept lines of text |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | abstract public function acceptsLines(); |
||
115 | |||
116 | /** |
||
117 | * Whether this is a code block |
||
118 | * |
||
119 | * @return bool |
||
120 | */ |
||
121 | abstract public function isCode(); |
||
122 | |||
123 | /** |
||
124 | * @param Cursor $cursor |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | abstract public function matchesNextLine(Cursor $cursor); |
||
129 | |||
130 | /** |
||
131 | * @param ContextInterface $context |
||
132 | * @param Cursor $cursor |
||
133 | */ |
||
134 | public function handleRemainingContents(ContextInterface $context, Cursor $cursor) |
||
141 | |||
142 | /** |
||
143 | * @param int $startLine |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | 1869 | public function setStartLine($startLine) |
|
156 | |||
157 | /** |
||
158 | * @return int |
||
159 | */ |
||
160 | public function getStartLine() |
||
164 | |||
165 | public function setEndLine($endLine) |
||
171 | |||
172 | /** |
||
173 | * @return int |
||
174 | */ |
||
175 | public function getEndLine() |
||
179 | |||
180 | /** |
||
181 | * Whether the block ends with a blank line |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | 642 | public function endsWithBlankLine() |
|
189 | |||
190 | /** |
||
191 | * @param bool $blank |
||
192 | */ |
||
193 | 1863 | public function setLastLineBlank($blank) |
|
197 | |||
198 | /** |
||
199 | * Determines whether the last line should be marked as blank |
||
200 | * |
||
201 | * @param Cursor $cursor |
||
202 | * @param int $currentLineNumber |
||
203 | * |
||
204 | * @return bool |
||
205 | */ |
||
206 | 1638 | public function shouldLastLineBeBlank(Cursor $cursor, $currentLineNumber) |
|
210 | |||
211 | /** |
||
212 | * @return string[] |
||
213 | */ |
||
214 | 1758 | public function getStrings() |
|
218 | |||
219 | /** |
||
220 | * @param string $line |
||
221 | */ |
||
222 | 1851 | public function addLine($line) |
|
230 | |||
231 | /** |
||
232 | * Whether the block is open for modifications |
||
233 | * |
||
234 | * @return bool |
||
235 | */ |
||
236 | 1032 | public function isOpen() |
|
240 | |||
241 | /** |
||
242 | * Finalize the block; mark it closed for modification |
||
243 | * |
||
244 | * @param ContextInterface $context |
||
245 | * @param int $endLineNumber |
||
246 | */ |
||
247 | 1863 | public function finalize(ContextInterface $context, $endLineNumber) |
|
258 | |||
259 | /** |
||
260 | * @return string |
||
261 | */ |
||
262 | 1833 | public function getStringContent() |
|
266 | |||
267 | /** |
||
268 | * @param string $key |
||
269 | * @param mixed $default |
||
270 | * |
||
271 | * @return mixed |
||
272 | */ |
||
273 | 1830 | public function getData($key, $default = null) |
|
277 | } |
||
278 |