1 | <?php |
||
23 | abstract class AbstractSaxHandler implements SaxHandlerInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $options; |
||
29 | |||
30 | /** |
||
31 | * AbstractSaxHandler constructor. |
||
32 | * |
||
33 | * @param array $options |
||
34 | */ |
||
35 | 5 | public function __construct(array $options = array()) |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 5 | final public function parse(StreamInterface $stream) |
|
69 | |||
70 | /** |
||
71 | * Document start handler, executed when parsing process started. |
||
72 | * |
||
73 | * @param resource $parser Parser handler. |
||
74 | * @param StreamInterface $stream XML stream. |
||
75 | */ |
||
76 | abstract protected function onDocumentStart($parser, $stream); |
||
77 | |||
78 | /** |
||
79 | * Element start handler, executed when XML tag is entered. |
||
80 | * |
||
81 | * @param resource $parser Parser handler. |
||
82 | * @param string $name Tag name. |
||
83 | * @param array $attributes Element attributes. |
||
84 | */ |
||
85 | abstract protected function onElementStart($parser, $name, $attributes); |
||
86 | |||
87 | /** |
||
88 | * Element CDATA handler, executed when XML tag CDATA is parsed. |
||
89 | * |
||
90 | * @param resource $parser Parser handler. |
||
91 | * @param string $data Element CDATA. |
||
92 | */ |
||
93 | abstract protected function onElementData($parser, $data); |
||
94 | |||
95 | /** |
||
96 | * Element end handler, executed when XML tag is leaved. |
||
97 | * |
||
98 | * @param resource $parser Parser handler. |
||
99 | * @param string $name Tag name. |
||
100 | */ |
||
101 | abstract protected function onElementEnd($parser, $name); |
||
102 | |||
103 | /** |
||
104 | * Document end handler, executed when parsing process ended. |
||
105 | * |
||
106 | * @param resource $parser Parser handler. |
||
107 | * @param StreamInterface $stream XML stream. |
||
108 | */ |
||
109 | abstract protected function onDocumentEnd($parser, $stream); |
||
110 | |||
111 | /** |
||
112 | * Parsing error handler. |
||
113 | * |
||
114 | * @param string $message Parsing error message. |
||
115 | * @param int $code Error code. |
||
116 | * @param int $lineno XML line number which caused error. |
||
117 | */ |
||
118 | abstract protected function onParseError($message, $code, $lineno); |
||
119 | |||
120 | /** |
||
121 | * Get parsing result. |
||
122 | * |
||
123 | * Considering that your handler processed XML document, this method will collect |
||
124 | * parsing result. This method is called last and it will provide parsing result to invoker. |
||
125 | * |
||
126 | * @return mixed Parsing result |
||
127 | */ |
||
128 | abstract protected function getResult(); |
||
129 | |||
130 | /** |
||
131 | * Parse path to XML document/string content. |
||
132 | * |
||
133 | * @param resource $parser Parser. |
||
134 | * @param StreamInterface $stream XML document stream. |
||
135 | * @return AbstractSaxHandler $this Fluent interface. |
||
136 | * |
||
137 | * @throws \RuntimeException |
||
138 | */ |
||
139 | 5 | private function process($parser, StreamInterface $stream) |
|
151 | |||
152 | /** |
||
153 | * Attach handlers. |
||
154 | * |
||
155 | * @param resource $parser XML parser. |
||
156 | * @return AbstractSaxHandler $this Fluent interface. |
||
157 | */ |
||
158 | 5 | private function attachHandlers($parser) |
|
178 | } |
||
179 |