Chris@0
|
1 <?php
|
Chris@0
|
2 namespace Masterminds\HTML5\Parser;
|
Chris@0
|
3
|
Chris@0
|
4 /**
|
Chris@0
|
5 * Standard events for HTML5.
|
Chris@0
|
6 *
|
Chris@0
|
7 * This is roughly analogous to a SAX2 or expat-style interface.
|
Chris@0
|
8 * However, it is tuned specifically for HTML5, according to section 8
|
Chris@0
|
9 * of the HTML5 specification.
|
Chris@0
|
10 *
|
Chris@0
|
11 * An event handler receives parser events. For a concrete
|
Chris@0
|
12 * implementation, see DOMTreeBuilder.
|
Chris@0
|
13 *
|
Chris@0
|
14 * Quirks support in the parser is limited to close-in syntax (malformed
|
Chris@0
|
15 * tags or attributes). Higher order syntax and semantic issues with a
|
Chris@0
|
16 * document (e.g. mismatched tags, illegal nesting, etc.) are the
|
Chris@0
|
17 * responsibility of the event handler implementation.
|
Chris@0
|
18 *
|
Chris@0
|
19 * See HTML5 spec section 8.2.4
|
Chris@0
|
20 */
|
Chris@0
|
21 interface EventHandler
|
Chris@0
|
22 {
|
Chris@0
|
23
|
Chris@0
|
24 const DOCTYPE_NONE = 0;
|
Chris@0
|
25
|
Chris@0
|
26 const DOCTYPE_PUBLIC = 1;
|
Chris@0
|
27
|
Chris@0
|
28 const DOCTYPE_SYSTEM = 2;
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * A doctype declaration.
|
Chris@0
|
32 *
|
Chris@0
|
33 * @param string $name
|
Chris@0
|
34 * The name of the root element.
|
Chris@0
|
35 * @param int $idType
|
Chris@0
|
36 * One of DOCTYPE_NONE, DOCTYPE_PUBLIC, or DOCTYPE_SYSTEM.
|
Chris@0
|
37 * @param string $id
|
Chris@0
|
38 * The identifier. For DOCTYPE_PUBLIC, this is the public ID. If DOCTYPE_SYSTEM,
|
Chris@0
|
39 * then this is a system ID.
|
Chris@0
|
40 * @param boolean $quirks
|
Chris@0
|
41 * Indicates whether the builder should enter quirks mode.
|
Chris@0
|
42 */
|
Chris@0
|
43 public function doctype($name, $idType = 0, $id = null, $quirks = false);
|
Chris@0
|
44
|
Chris@0
|
45 /**
|
Chris@0
|
46 * A start tag.
|
Chris@0
|
47 *
|
Chris@0
|
48 * IMPORTANT: The parser watches the return value of this event. If this returns
|
Chris@0
|
49 * an integer, the parser will switch TEXTMODE patters according to the int.
|
Chris@0
|
50 *
|
Chris@0
|
51 * This is how the Tree Builder can tell the Tokenizer when a certain tag should
|
Chris@0
|
52 * cause the parser to go into RAW text mode.
|
Chris@0
|
53 *
|
Chris@0
|
54 * The HTML5 standard requires that the builder is the one that initiates this
|
Chris@0
|
55 * step, and this is the only way short of a circular reference that we can
|
Chris@0
|
56 * do that.
|
Chris@0
|
57 *
|
Chris@0
|
58 * Example: if a startTag even for a `script` name is fired, and the startTag()
|
Chris@0
|
59 * implementation returns Tokenizer::TEXTMODE_RAW, then the tokenizer will
|
Chris@0
|
60 * switch into RAW text mode and consume data until it reaches a closing
|
Chris@0
|
61 * `script` tag.
|
Chris@0
|
62 *
|
Chris@0
|
63 * The textmode is automatically reset to Tokenizer::TEXTMODE_NORMAL when the
|
Chris@0
|
64 * closing tag is encounter. **This behavior may change.**
|
Chris@0
|
65 *
|
Chris@0
|
66 * @param string $name
|
Chris@0
|
67 * The tag name.
|
Chris@0
|
68 * @param array $attributes
|
Chris@0
|
69 * An array with all of the tag's attributes.
|
Chris@0
|
70 * @param boolean $selfClosing
|
Chris@0
|
71 * An indicator of whether or not this tag is self-closing (<foo/>)
|
Chris@0
|
72 * @return int One of the Tokenizer::TEXTMODE_* constants.
|
Chris@0
|
73 */
|
Chris@0
|
74 public function startTag($name, $attributes = array(), $selfClosing = false);
|
Chris@0
|
75
|
Chris@0
|
76 /**
|
Chris@0
|
77 * An end-tag.
|
Chris@0
|
78 */
|
Chris@0
|
79 public function endTag($name);
|
Chris@0
|
80
|
Chris@0
|
81 /**
|
Chris@0
|
82 * A comment section (unparsed character data).
|
Chris@0
|
83 */
|
Chris@0
|
84 public function comment($cdata);
|
Chris@0
|
85
|
Chris@0
|
86 /**
|
Chris@0
|
87 * A unit of parsed character data.
|
Chris@0
|
88 *
|
Chris@0
|
89 * Entities in this text are *already decoded*.
|
Chris@0
|
90 */
|
Chris@0
|
91 public function text($cdata);
|
Chris@0
|
92
|
Chris@0
|
93 /**
|
Chris@0
|
94 * Indicates that the document has been entirely processed.
|
Chris@0
|
95 */
|
Chris@0
|
96 public function eof();
|
Chris@0
|
97
|
Chris@0
|
98 /**
|
Chris@0
|
99 * Emitted when the parser encounters an error condition.
|
Chris@0
|
100 */
|
Chris@0
|
101 public function parseError($msg, $line, $col);
|
Chris@0
|
102
|
Chris@0
|
103 /**
|
Chris@0
|
104 * A CDATA section.
|
Chris@0
|
105 *
|
Chris@0
|
106 * @param string $data
|
Chris@0
|
107 * The unparsed character data.
|
Chris@0
|
108 */
|
Chris@0
|
109 public function cdata($data);
|
Chris@0
|
110
|
Chris@0
|
111 /**
|
Chris@0
|
112 * This is a holdover from the XML spec.
|
Chris@0
|
113 *
|
Chris@0
|
114 * While user agents don't get PIs, server-side does.
|
Chris@0
|
115 *
|
Chris@0
|
116 * @param string $name
|
Chris@0
|
117 * The name of the processor (e.g. 'php').
|
Chris@0
|
118 * @param string $data
|
Chris@0
|
119 * The unparsed data.
|
Chris@0
|
120 */
|
Chris@0
|
121 public function processingInstruction($name, $data = null);
|
Chris@0
|
122 }
|