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