Skip to content

Commit e2f86c7

Browse files
author
Martin Brecht-Precht
committed
Added the DebugHandler.
1 parent ea7719d commit e2f86c7

File tree

1 file changed

+367
-0
lines changed

1 file changed

+367
-0
lines changed

src/Handler/DebugHandler.php

Lines changed: 367 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,367 @@
1+
<?php
2+
3+
namespace Markdom\Handler;
4+
5+
/**
6+
* Class JsonHandler
7+
*
8+
* @package Markdom\Handler
9+
*/
10+
class DebugHandler extends PhpObjectHandler
11+
{
12+
13+
/**
14+
* @var int
15+
*/
16+
private $indentationLevel = 0;
17+
18+
/**
19+
* @var string[]
20+
*/
21+
private $output = array();
22+
23+
/**
24+
* @return void
25+
*/
26+
public function onDocumentBegin()
27+
{
28+
$this->output[] = $this->getIndentation() . __FUNCTION__;
29+
$this->indentationLevel++;
30+
}
31+
32+
/**
33+
* @return void
34+
*/
35+
public function onDocumentEnd()
36+
{
37+
$this->indentationLevel--;
38+
$this->output[] = $this->getIndentation() . __FUNCTION__;
39+
}
40+
41+
/**
42+
* @return void
43+
*/
44+
public function onBlocksBegin()
45+
{
46+
$this->output[] = $this->getIndentation() . __FUNCTION__;
47+
$this->indentationLevel++;
48+
}
49+
50+
/**
51+
* @param string $type
52+
* @return void
53+
*/
54+
public function onBlockBegin($type)
55+
{
56+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $type;
57+
$this->indentationLevel++;
58+
}
59+
60+
/**
61+
* @param string $code
62+
* @param string $hint
63+
* @return void
64+
*/
65+
public function onCodeBlock($code, $hint = null)
66+
{
67+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $hint . ' ~ ' . $code;
68+
}
69+
70+
/**
71+
* @return void
72+
*/
73+
public function onDivisionBlock()
74+
{
75+
$this->output[] = $this->getIndentation() . __FUNCTION__;
76+
}
77+
78+
/**
79+
* @param int $level
80+
* @return void
81+
*/
82+
public function onHeadingBlockBegin($level)
83+
{
84+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $level;
85+
}
86+
87+
/**
88+
* @param int $level
89+
* @return void
90+
*/
91+
public function onHeadingBlockEnd($level)
92+
{
93+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $level;
94+
}
95+
96+
/**
97+
* @return void
98+
*/
99+
public function onUnorderedListBlockBegin()
100+
{
101+
$this->output[] = $this->getIndentation() . __FUNCTION__;
102+
}
103+
104+
/**
105+
* @param int $startIndex
106+
* @return void
107+
*/
108+
public function onOrderedListBlockBegin($startIndex)
109+
{
110+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $startIndex;
111+
}
112+
113+
/**
114+
* @return void
115+
*/
116+
public function onListItemsBegin()
117+
{
118+
$this->output[] = $this->getIndentation() . __FUNCTION__;
119+
}
120+
121+
/**
122+
* @return void
123+
*/
124+
public function onListItemBegin()
125+
{
126+
$this->output[] = $this->getIndentation() . __FUNCTION__;
127+
}
128+
129+
/**
130+
* @return void
131+
*/
132+
public function onListItemEnd()
133+
{
134+
$this->output[] = $this->getIndentation() . __FUNCTION__;
135+
}
136+
137+
/**
138+
* @return void
139+
*/
140+
public function onNextListItem()
141+
{
142+
$this->output[] = $this->getIndentation() . __FUNCTION__;
143+
}
144+
145+
/**
146+
* @return void
147+
*/
148+
public function onListItemsEnd()
149+
{
150+
$this->output[] = $this->getIndentation() . __FUNCTION__;
151+
}
152+
153+
/**
154+
* @return void
155+
*/
156+
public function onUnorderedListBlockEnd()
157+
{
158+
$this->output[] = $this->getIndentation() . __FUNCTION__;
159+
}
160+
161+
/**
162+
* @param int
163+
* @return void
164+
*/
165+
public function onOrderedListBlockEnd($startIndex)
166+
{
167+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $startIndex;
168+
}
169+
170+
/**
171+
* @return void
172+
*/
173+
public function onParagraphBlockBegin()
174+
{
175+
$this->output[] = $this->getIndentation() . __FUNCTION__;
176+
}
177+
178+
/**
179+
* @return void
180+
*/
181+
public function onParagraphBlockEnd()
182+
{
183+
$this->output[] = $this->getIndentation() . __FUNCTION__;
184+
}
185+
186+
/**
187+
* @return void
188+
*/
189+
public function onQuoteBlockBegin()
190+
{
191+
$this->output[] = $this->getIndentation() . __FUNCTION__;
192+
}
193+
194+
/**
195+
* @return void
196+
*/
197+
public function onQuoteBlockEnd()
198+
{
199+
$this->output[] = $this->getIndentation() . __FUNCTION__;
200+
}
201+
202+
/**
203+
* @param string $type
204+
* @return void
205+
*/
206+
public function onBlockEnd($type)
207+
{
208+
$this->indentationLevel--;
209+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $type;
210+
}
211+
212+
/**
213+
* @return void
214+
*/
215+
public function onNextBlock()
216+
{
217+
$this->output[] = $this->getIndentation() . __FUNCTION__;
218+
}
219+
220+
/**
221+
* @return void
222+
*/
223+
public function onBlocksEnd()
224+
{
225+
$this->indentationLevel--;
226+
$this->output[] = $this->getIndentation() . __FUNCTION__;
227+
}
228+
229+
/**
230+
* @return void
231+
*/
232+
public function onContentsBegin()
233+
{
234+
$this->output[] = $this->getIndentation() . __FUNCTION__;
235+
$this->indentationLevel++;
236+
}
237+
238+
/**
239+
* @param string $type
240+
* @return void
241+
*/
242+
public function onContentBegin($type)
243+
{
244+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $type;
245+
$this->indentationLevel++;
246+
}
247+
248+
/**
249+
* @param string $code
250+
* @return void
251+
*/
252+
public function onCodeContent($code)
253+
{
254+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $code;
255+
}
256+
257+
/**
258+
* @param int $level
259+
* @return void
260+
*/
261+
public function onEmphasisContentBegin($level)
262+
{
263+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $level;
264+
}
265+
266+
/**
267+
* @param int $level
268+
* @return void
269+
*/
270+
public function onEmphasisContentEnd($level)
271+
{
272+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $level;
273+
}
274+
275+
/**
276+
* @param string $uri
277+
* @param string $title
278+
* @param string $alternative
279+
* @return void
280+
*/
281+
public function onImageContent($uri, $title = null, $alternative = null)
282+
{
283+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $uri . ' ~ ' . $title . ' ~ ' . $alternative;
284+
}
285+
286+
/**
287+
* @param bool $hard
288+
* @return void
289+
*/
290+
public function onLineBreakContent($hard)
291+
{
292+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $hard;
293+
}
294+
295+
/**
296+
* @param string $uri
297+
* @param string $title
298+
* @return void
299+
*/
300+
public function onLinkContentBegin($uri, $title = null)
301+
{
302+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $uri . ' ~ ' . $title;
303+
}
304+
305+
/**
306+
* @param string $uri
307+
* @param string $title
308+
* @return void
309+
*/
310+
public function onLinkContentEnd($uri, $title = null)
311+
{
312+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $uri . ' ~ ' . $title;
313+
}
314+
315+
/**
316+
* @param string $text
317+
* @return void
318+
*/
319+
public function onTextContent($text)
320+
{
321+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $text;
322+
}
323+
324+
/**
325+
* @param string $type
326+
* @return void
327+
*/
328+
public function onContentEnd($type)
329+
{
330+
$this->indentationLevel--;
331+
$this->output[] = $this->getIndentation() . __FUNCTION__ . ': ' . $type;
332+
}
333+
334+
/**
335+
* @return void
336+
*/
337+
public function onNextContent()
338+
{
339+
$this->output[] = $this->getIndentation() . __FUNCTION__;
340+
}
341+
342+
/**
343+
* @return void
344+
*/
345+
public function onContentsEnd()
346+
{
347+
$this->indentationLevel--;
348+
$this->output[] = $this->getIndentation() . __FUNCTION__;
349+
}
350+
351+
/**
352+
* @return string
353+
*/
354+
public function getResult()
355+
{
356+
return implode(PHP_EOL, $this->output);
357+
}
358+
359+
/**
360+
* @return string
361+
*/
362+
private function getIndentation()
363+
{
364+
return str_pad('', $this->indentationLevel * 4, ' ', STR_PAD_LEFT);
365+
}
366+
367+
}

0 commit comments

Comments
 (0)