1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
15
|
|
|
* |
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
17
|
|
|
* and is licensed under the LGPL. For more information please see |
18
|
|
|
* <http://phing.info>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Phing\Parser; |
22
|
|
|
|
23
|
|
|
use Exception; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The abstract SAX parser class. |
27
|
|
|
* |
28
|
|
|
* This class represents a SAX parser. It is a abstract calss that must be |
29
|
|
|
* implemented by the real parser that must extend this class |
30
|
|
|
* |
31
|
|
|
* @author Andreas Aderhold <[email protected]> |
32
|
|
|
* @author Hans Lellelid <[email protected]> |
33
|
|
|
* @copyright 2001,2002 THYRELL. All rights reserved |
34
|
|
|
*/ |
35
|
|
|
abstract class AbstractSAXParser |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var AbstractHandler |
39
|
|
|
*/ |
40
|
|
|
protected $handler; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Sets options for PHP interal parser. Must be implemented by the parser |
44
|
|
|
* class if it should be used. |
45
|
|
|
* |
46
|
|
|
* @param $opt |
47
|
|
|
* @param $val |
48
|
|
|
* |
49
|
|
|
* @return |
50
|
|
|
*/ |
51
|
|
|
abstract public function parserSetOption($opt, $val); |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Sets the current element handler object for this parser. Usually this |
55
|
|
|
* is an object using extending "AbstractHandler". |
56
|
|
|
* |
57
|
|
|
* @param AbstractHandler $obj the handler object |
58
|
|
|
*/ |
59
|
827 |
|
public function setHandler(AbstractHandler $obj) |
60
|
|
|
{ |
61
|
827 |
|
$this->handler = $obj; |
62
|
827 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Method that gets invoked when the parser runs over a XML start element. |
66
|
|
|
* |
67
|
|
|
* This method is called by PHP's internal parser functions and registered |
68
|
|
|
* in the actual parser implementation. |
69
|
|
|
* It gives control to the current active handler object by calling the |
70
|
|
|
* <code>startElement()</code> method. |
71
|
|
|
* |
72
|
|
|
* @param object $parser the php's internal parser handle |
73
|
|
|
* @param string $name the open tag name |
74
|
|
|
* @param array $attribs the tag's attributes if any |
75
|
|
|
* |
76
|
|
|
* @throws Exception - Exceptions may be thrown by the Handler |
77
|
|
|
*/ |
78
|
827 |
|
public function startElement($parser, $name, $attribs) |
79
|
|
|
{ |
80
|
827 |
|
$this->handler->startElement($name, $attribs); |
81
|
827 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Method that gets invoked when the parser runs over a XML close element. |
85
|
|
|
* |
86
|
|
|
* This method is called by PHP's internal parser funcitons and registered |
87
|
|
|
* in the actual parser implementation. |
88
|
|
|
* |
89
|
|
|
* It gives control to the current active handler object by calling the |
90
|
|
|
* <code>endElement()</code> method. |
91
|
|
|
* |
92
|
|
|
* @param object $parser the php's internal parser handle |
93
|
|
|
* @param string $name the closing tag name |
94
|
|
|
* |
95
|
|
|
* @throws Exception - Exceptions may be thrown by the Handler |
96
|
|
|
*/ |
97
|
827 |
|
public function endElement($parser, $name) |
98
|
|
|
{ |
99
|
827 |
|
$this->handler->endElement($name); |
100
|
827 |
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Method that gets invoked when the parser runs over CDATA. |
104
|
|
|
* |
105
|
|
|
* This method is called by PHP's internal parser functions and registered |
106
|
|
|
* in the actual parser implementation. |
107
|
|
|
* |
108
|
|
|
* It gives control to the current active handler object by calling the |
109
|
|
|
* <code>characters()</code> method. That processes the given CDATA. |
110
|
|
|
* |
111
|
|
|
* @param resource $parser php's internal parser handle |
112
|
|
|
* @param string $data the CDATA |
113
|
|
|
* |
114
|
|
|
* @throws Exception - Exceptions may be thrown by the Handler |
115
|
|
|
*/ |
116
|
827 |
|
public function characters($parser, $data) |
117
|
|
|
{ |
118
|
827 |
|
$this->handler->characters($data); |
119
|
827 |
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Entrypoint for parser. This method needs to be implemented by the |
123
|
|
|
* child classt that utilizes the concrete parser. |
124
|
|
|
*/ |
125
|
|
|
abstract public function parse(); |
126
|
|
|
} |
127
|
|
|
|