1 | <?php |
||
18 | abstract class AbstractHtml5 |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Global options for the parser and serializer. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $options = array( |
||
27 | // If the serializer should encode all entities. |
||
28 | 'encode_entities' => false |
||
29 | ); |
||
30 | |||
31 | protected $errors = array(); |
||
32 | |||
33 | 68 | public function __construct(array $options = array()) |
|
37 | |||
38 | /** |
||
39 | * Get the default options. |
||
40 | * |
||
41 | * @return array The default options. |
||
42 | */ |
||
43 | 65 | public function getOptions() |
|
47 | |||
48 | /** |
||
49 | * Load and parse an HTML file. |
||
50 | * |
||
51 | * This will apply the HTML5 parser, which is tolerant of many |
||
52 | * varieties of HTML, including XHTML 1, HTML 4, and well-formed HTML |
||
53 | * 3. Note that in these cases, not all of the old data will be |
||
54 | * preserved. For example, XHTML's XML declaration will be removed. |
||
55 | * |
||
56 | * The rules governing parsing are set out in the HTML 5 spec. |
||
57 | * |
||
58 | * @param string $file |
||
59 | * The path to the file to parse. If this is a resource, it is |
||
60 | * assumed to be an open stream whose pointer is set to the first |
||
61 | * byte of input. |
||
62 | * @param array $options |
||
63 | * Configuration options when parsing the HTML |
||
64 | * @return \DOMDocument A DOM document. These object type is defined by the libxml |
||
65 | * library, and should have been included with your version of PHP. |
||
66 | */ |
||
67 | 4 | public function load($file, array $options = array()) |
|
79 | |||
80 | /** |
||
81 | * Parse a HTML Document from a string. |
||
82 | * |
||
83 | * Take a string of HTML 5 (or earlier) and parse it into a |
||
84 | * DOMDocument. |
||
85 | * |
||
86 | * @param string $string |
||
87 | * A html5 document as a string. |
||
88 | * @param array $options |
||
89 | * Configuration options when parsing the HTML |
||
90 | * @return \DOMDocument A DOM document. DOM is part of libxml, which is included with |
||
91 | * almost all distribtions of PHP. |
||
92 | */ |
||
93 | 56 | public function loadHTML($string, array $options = array()) |
|
99 | |||
100 | /** |
||
101 | * Convenience function to load an HTML file. |
||
102 | * |
||
103 | * This is here to provide backwards compatibility with the |
||
104 | * PHP DOM implementation. It simply calls load(). |
||
105 | * |
||
106 | * @param string $file |
||
107 | * The path to the file to parse. If this is a resource, it is |
||
108 | * assumed to be an open stream whose pointer is set to the first |
||
109 | * byte of input. |
||
110 | * @param array $options |
||
111 | * Configuration options when parsing the HTML |
||
112 | * |
||
113 | * @return \DOMDocument A DOM document. These object type is defined by the libxml |
||
114 | * library, and should have been included with your version of PHP. |
||
115 | */ |
||
116 | 1 | public function loadHTMLFile($file, array $options = array()) |
|
120 | |||
121 | /** |
||
122 | * Parse a HTML fragment from a string. |
||
123 | * |
||
124 | * @param string $string |
||
125 | * The html5 fragment as a string. |
||
126 | * @param array $options |
||
127 | * Configuration options when parsing the HTML |
||
128 | * |
||
129 | * @return \DOMDocumentFragment A DOM fragment. The DOM is part of libxml, which is included with |
||
130 | * almost all distributions of PHP. |
||
131 | */ |
||
132 | 12 | public function loadHTMLFragment($string, array $options = array()) |
|
138 | |||
139 | /** |
||
140 | * Return all errors encountered into parsing phase |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | 12 | public function getErrors() |
|
148 | |||
149 | /** |
||
150 | * Return true it some errors were encountered into parsing phase |
||
151 | * |
||
152 | * @return bool |
||
153 | */ |
||
154 | 4 | public function hasErrors() |
|
158 | |||
159 | /** |
||
160 | * Parse an input stream. |
||
161 | * |
||
162 | * Lower-level loading function. This requires an input stream instead |
||
163 | * of a string, file, or resource. |
||
164 | */ |
||
165 | 58 | public function parse(\Masterminds\Html5\Parser\InputStream $input, array $options = array()) |
|
177 | |||
178 | /** |
||
179 | * Parse an input stream where the stream is a fragment. |
||
180 | * |
||
181 | * Lower-level loading function. This requires an input stream instead |
||
182 | * of a string, file, or resource. |
||
183 | */ |
||
184 | 14 | public function parseFragment(\Masterminds\Html5\Parser\InputStream $input, array $options = array()) |
|
195 | |||
196 | /** |
||
197 | * Save a DOM into a given file as HTML5. |
||
198 | * |
||
199 | * @param mixed $dom |
||
200 | * The DOM to be serialized. |
||
201 | * @param string|resource $file |
||
202 | * The filename to be written or resource to write to. |
||
203 | * @param array $options |
||
204 | * Configuration options when serializing the DOM. These include: |
||
205 | * - encode_entities: Text written to the output is escaped by default and not all |
||
206 | * entities are encoded. If this is set to true all entities will be encoded. |
||
207 | * Defaults to false. |
||
208 | */ |
||
209 | 15 | public function save($dom, $file, $options = array()) |
|
228 | |||
229 | /** |
||
230 | * Convert a DOM into an HTML5 string. |
||
231 | * |
||
232 | * @param mixed $dom |
||
233 | * The DOM to be serialized. |
||
234 | * @param array $options |
||
235 | * Configuration options when serializing the DOM. These include: |
||
236 | * - encode_entities: Text written to the output is escaped by default and not all |
||
237 | * entities are encoded. If this is set to true all entities will be encoded. |
||
238 | * Defaults to false. |
||
239 | * |
||
240 | * @return string A HTML5 documented generated from the DOM. |
||
241 | */ |
||
242 | 14 | public function saveHTML($dom, $options = array()) |
|
249 | } |
||
250 |