1 | <?php |
||
19 | class HtmlTokenizer |
||
20 | { |
||
21 | /** |
||
22 | * Current tokenizer position. Tokenizer is a linear processor (no regular expression is |
||
23 | * involved). This slows it down, but the results are much more reliable. |
||
24 | */ |
||
25 | const POSITION_PLAIN_TEXT = 0x001; |
||
26 | const POSITION_IN_TAG = 0x002; |
||
27 | const POSITION_IN_QUOTAS = 0x003; |
||
28 | |||
29 | /** |
||
30 | * Token types detected and processed by tokenizer. |
||
31 | */ |
||
32 | const PLAIN_TEXT = 'plain'; |
||
33 | const TAG_OPEN = 'open'; |
||
34 | const TAG_CLOSE = 'close'; |
||
35 | const TAG_SHORT = 'short'; |
||
36 | const TAG_VOID = 'void'; |
||
37 | |||
38 | /** |
||
39 | * Token fields. There are a lot of tokens in HTML (up to 10,000 different ones). We better to |
||
40 | * use numeric keys for array than any text fields or even objects. |
||
41 | */ |
||
42 | const TOKEN_NAME = 0; |
||
43 | const TOKEN_TYPE = 1; |
||
44 | const TOKEN_CONTENT = 2; |
||
45 | const TOKEN_ATTRIBUTES = 3; |
||
46 | |||
47 | /** |
||
48 | * List of void tags. |
||
49 | * |
||
50 | * @link http://www.w3.org/TR/html5/syntax.html#void-elements |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $voidTags = [ |
||
54 | 'area', |
||
55 | 'base', |
||
56 | 'br', |
||
57 | 'col', |
||
58 | 'embed', |
||
59 | 'hr', |
||
60 | 'img', |
||
61 | 'input', |
||
62 | 'keygen', |
||
63 | 'link', |
||
64 | 'meta', |
||
65 | 'param', |
||
66 | 'source', |
||
67 | 'track', |
||
68 | 'wbr' |
||
69 | ]; |
||
70 | |||
71 | /** |
||
72 | * Array of parsed tokens. Every token has fields name, type, content and arguments. |
||
73 | * |
||
74 | * @var array |
||
75 | */ |
||
76 | protected $tokens = []; |
||
77 | |||
78 | /** |
||
79 | * PHP block should be isolated while parsing, Keep enabled. |
||
80 | * |
||
81 | * @var bool |
||
82 | */ |
||
83 | protected $isolatePHP = false; |
||
84 | |||
85 | /** |
||
86 | * PHP Blocks isolator, which holds all existing PHP blocks and restores them in output. |
||
87 | * |
||
88 | * @var Isolator|null |
||
89 | */ |
||
90 | protected $isolator = null; |
||
91 | |||
92 | /** |
||
93 | * @param bool $isolatePHP PHP block should be isolated and enabled by default |
||
94 | * @param Isolator $isolator |
||
95 | */ |
||
96 | public function __construct($isolatePHP = true, Isolator $isolator = null) |
||
101 | |||
102 | /** |
||
103 | * Parse HTML content and return it's tokens. |
||
104 | * |
||
105 | * @param string $source HTML source. |
||
106 | * @return array |
||
107 | */ |
||
108 | public function parse($source) |
||
183 | |||
184 | /** |
||
185 | * Compile token and all it's attributes into string. |
||
186 | * |
||
187 | * @param array $token |
||
188 | * @return string |
||
189 | */ |
||
190 | public function compile(array $token) |
||
218 | |||
219 | /** |
||
220 | * Parses tag body for arguments, name, etc. |
||
221 | * |
||
222 | * @param string $content Tag content to be parsed (from < till >). |
||
223 | * @return array |
||
224 | */ |
||
225 | protected function parseToken($content) |
||
298 | |||
299 | /** |
||
300 | * Handles single token and passes it to a callback function if specified. |
||
301 | * |
||
302 | * @param int $tokenType Token type. |
||
303 | * @param string $content Non parsed token content. |
||
304 | */ |
||
305 | protected function handleToken($tokenType, $content) |
||
322 | |||
323 | /** |
||
324 | * Will restore all existing PHP blocks to their original content. |
||
325 | * |
||
326 | * @param string $source |
||
327 | * @return string |
||
328 | */ |
||
329 | protected function repairPHP($source) |
||
337 | } |
||
338 |
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: