1 | <?php |
||
18 | class HTML5 |
||
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 | 74 | public function __construct(array $options = array()) |
|
37 | |||
38 | /** |
||
39 | * Get the default options. |
||
40 | * |
||
41 | * @return array The default options. |
||
42 | */ |
||
43 | 71 | 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|resource $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()) |
|
76 | |||
77 | /** |
||
78 | * Parse a HTML Document from a string. |
||
79 | * |
||
80 | * Take a string of HTML 5 (or earlier) and parse it into a |
||
81 | * DOMDocument. |
||
82 | * |
||
83 | * @param string $string |
||
84 | * A html5 document as a string. |
||
85 | * @param array $options |
||
86 | * Configuration options when parsing the HTML |
||
87 | * @return \DOMDocument A DOM document. DOM is part of libxml, which is included with |
||
88 | * almost all distribtions of PHP. |
||
89 | */ |
||
90 | 59 | public function loadHTML($string, array $options = array()) |
|
94 | |||
95 | /** |
||
96 | * Convenience function to load an HTML file. |
||
97 | * |
||
98 | * This is here to provide backwards compatibility with the |
||
99 | * PHP DOM implementation. It simply calls load(). |
||
100 | * |
||
101 | * @param string $file |
||
102 | * The path to the file to parse. If this is a resource, it is |
||
103 | * assumed to be an open stream whose pointer is set to the first |
||
104 | * byte of input. |
||
105 | * @param array $options |
||
106 | * Configuration options when parsing the HTML |
||
107 | * |
||
108 | * @return \DOMDocument A DOM document. These object type is defined by the libxml |
||
109 | * library, and should have been included with your version of PHP. |
||
110 | */ |
||
111 | 1 | public function loadHTMLFile($file, array $options = array()) |
|
115 | |||
116 | /** |
||
117 | * Parse a HTML fragment from a string. |
||
118 | * |
||
119 | * @param string $string The HTML5 fragment as a string. |
||
120 | * @param array $options Configuration options when parsing the HTML |
||
121 | * |
||
122 | * @return \DOMDocumentFragment A DOM fragment. The DOM is part of libxml, which is included with |
||
123 | * almost all distributions of PHP. |
||
124 | */ |
||
125 | 12 | public function loadHTMLFragment($string, array $options = array()) |
|
129 | |||
130 | /** |
||
131 | * Return all errors encountered into parsing phase |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | 13 | public function getErrors() |
|
139 | |||
140 | /** |
||
141 | * Return true it some errors were encountered into parsing phase |
||
142 | * |
||
143 | * @return bool |
||
144 | */ |
||
145 | 4 | public function hasErrors() |
|
149 | |||
150 | /** |
||
151 | * Parse an input stream. |
||
152 | * |
||
153 | * Lower-level loading function. This requires an input stream instead |
||
154 | * of a string, file, or resource. |
||
155 | * |
||
156 | * @param string $input |
||
157 | * @param array $options |
||
158 | * |
||
159 | * @return \DOMDocument |
||
160 | */ |
||
161 | 62 | public function parse($input, array $options = array()) |
|
174 | |||
175 | /** |
||
176 | * Parse an input stream where the stream is a fragment. |
||
177 | * |
||
178 | * Lower-level loading function. This requires an input stream instead |
||
179 | * of a string, file, or resource. |
||
180 | * |
||
181 | * @param string $input The input data to parse in the form of a string. |
||
182 | * @param array $options An array of options |
||
183 | * |
||
184 | * @return \DOMDocumentFragment |
||
185 | */ |
||
186 | 16 | public function parseFragment($input, array $options = array()) |
|
198 | |||
199 | /** |
||
200 | * Save a DOM into a given file as HTML5. |
||
201 | * |
||
202 | * @param mixed $dom |
||
203 | * The DOM to be serialized. |
||
204 | * @param string $file |
||
205 | * The filename to be written. |
||
206 | * @param array $options |
||
207 | * Configuration options when serializing the DOM. These include: |
||
208 | * - encode_entities: Text written to the output is escaped by default and not all |
||
209 | * entities are encoded. If this is set to true all entities will be encoded. |
||
210 | * Defaults to false. |
||
211 | */ |
||
212 | 17 | public function save($dom, $file, $options = array()) |
|
231 | |||
232 | /** |
||
233 | * Convert a DOM into an HTML5 string. |
||
234 | * |
||
235 | * @param mixed $dom |
||
236 | * The DOM to be serialized. |
||
237 | * @param array $options |
||
238 | * Configuration options when serializing the DOM. These include: |
||
239 | * - encode_entities: Text written to the output is escaped by default and not all |
||
240 | * entities are encoded. If this is set to true all entities will be encoded. |
||
241 | * Defaults to false. |
||
242 | * |
||
243 | * @return string A HTML5 documented generated from the DOM. |
||
244 | */ |
||
245 | 16 | public function saveHTML($dom, $options = array()) |
|
252 | } |
||
253 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: