1 | <?php |
||
13 | class Traverser |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * Namespaces that should be treated as "local" to HTML5. |
||
18 | */ |
||
19 | static $local_ns = array( |
||
20 | 'http://www.w3.org/1999/xhtml' => 'html', |
||
21 | 'http://www.w3.org/1998/Math/MathML' => 'math', |
||
22 | 'http://www.w3.org/2000/svg' => 'svg' |
||
23 | ); |
||
24 | |||
25 | protected $dom; |
||
26 | |||
27 | protected $options; |
||
28 | |||
29 | protected $encode = false; |
||
30 | |||
31 | protected $rules; |
||
32 | |||
33 | protected $out; |
||
34 | |||
35 | /** |
||
36 | * Create a traverser. |
||
37 | * |
||
38 | * @param DOMNode|DOMNodeList $dom |
||
39 | * The document or node to traverse. |
||
40 | * @param resource $out |
||
41 | * A stream that allows writing. The traverser will output into this |
||
42 | * stream. |
||
43 | * @param array $options |
||
44 | * An array or options for the traverser as key/value pairs. These include: |
||
45 | * - encode_entities: A bool to specify if full encding should happen for all named |
||
46 | * charachter references. Defaults to false which escapes &'<>". |
||
47 | * - output_rules: The path to the class handling the output rules. |
||
48 | */ |
||
49 | 64 | public function __construct($dom, $out, RulesInterface $rules, $options = array()) |
|
58 | |||
59 | /** |
||
60 | * Tell the traverser to walk the DOM. |
||
61 | * |
||
62 | * @return resource $out |
||
63 | * Returns the output stream. |
||
64 | */ |
||
65 | 22 | public function walk() |
|
86 | |||
87 | /** |
||
88 | * Process a node in the DOM. |
||
89 | * |
||
90 | * @param mixed $node |
||
91 | * A node implementing \DOMNode. |
||
92 | */ |
||
93 | 27 | public function node($node) |
|
118 | |||
119 | /** |
||
120 | * Walk through all the nodes on a node list. |
||
121 | * |
||
122 | * @param \DOMNodeList $nl |
||
123 | * A list of child elements to walk through. |
||
124 | */ |
||
125 | 27 | public function children($nl) |
|
131 | |||
132 | /** |
||
133 | * Is an element local? |
||
134 | * |
||
135 | * @param mixed $ele |
||
136 | * An element that implement \DOMNode. |
||
137 | * |
||
138 | * @return bool True if local and false otherwise. |
||
139 | */ |
||
140 | 28 | public function isLocalElement($ele) |
|
149 | } |
||
150 |