1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19

20
/**
21
 * The abstract SAX parser class.
22
 *
23
 * This class represents a SAX parser. It is a abstract calss that must be
24
 * implemented by the real parser that must extend this class
25
 *
26
 * @author    Andreas Aderhold <andi@binarycloud.com>
27
 * @author    Hans Lellelid <hans@xmpl.org>
28
 * @copyright 2001,2002 THYRELL. All rights reserved
29
 * @package   phing.parser
30
 */
31
abstract class AbstractSAXParser
32
{
33

34
    /**
35
     * @var AbstractHandler
36
     */
37
    protected $handler;
38

39
    /**
40
     * Sets options for PHP interal parser. Must be implemented by the parser
41
     * class if it should be used.
42
     *
43
     * @param  $opt
44
     * @param  $val
45
     * @return
46
     */
47
    abstract public function parserSetOption($opt, $val);
48

49
    /**
50
     * Sets the current element handler object for this parser. Usually this
51
     * is an object using extending "AbstractHandler".
52
     *
53
     * @param AbstractHandler $obj The handler object.
54
     */
55 1
    public function setHandler(AbstractHandler $obj)
56
    {
57 1
        $this->handler = $obj;
58
    }
59

60
    /**
61
     * Method that gets invoked when the parser runs over a XML start element.
62
     *
63
     * This method is called by PHP's internal parser functions and registered
64
     * in the actual parser implementation.
65
     * It gives control to the current active handler object by calling the
66
     * <code>startElement()</code> method.
67
     *
68
     * @param  object $parser the php's internal parser handle
69
     * @param  string $name the open tag name
70
     * @param  array $attribs the tag's attributes if any
71
     * @throws Exception - Exceptions may be thrown by the Handler
72
     */
73 1
    public function startElement($parser, $name, $attribs)
74
    {
75 1
        $this->handler->startElement($name, $attribs);
76
    }
77

78
    /**
79
     * Method that gets invoked when the parser runs over a XML close element.
80
     *
81
     * This method is called by PHP's internal parser funcitons and registered
82
     * in the actual parser implementation.
83
     *
84
     * It gives control to the current active handler object by calling the
85
     * <code>endElement()</code> method.
86
     *
87
     * @param  object $parser the php's internal parser handle
88
     * @param  string $name the closing tag name
89
     * @throws Exception - Exceptions may be thrown by the Handler
90
     */
91 1
    public function endElement($parser, $name)
92
    {
93 1
        $this->handler->endElement($name);
94
    }
95

96
    /**
97
     * Method that gets invoked when the parser runs over CDATA.
98
     *
99
     * This method is called by PHP's internal parser functions and registered
100
     * in the actual parser implementation.
101
     *
102
     * It gives control to the current active handler object by calling the
103
     * <code>characters()</code> method. That processes the given CDATA.
104
     *
105
     * @param  resource $parser php's internal parser handle.
106
     * @param  string $data the CDATA
107
     * @throws Exception - Exceptions may be thrown by the Handler
108
     */
109 1
    public function characters($parser, $data)
110
    {
111 1
        $this->handler->characters($data);
112
    }
113

114
    /**
115
     * Entrypoint for parser. This method needs to be implemented by the
116
     * child classt that utilizes the concrete parser
117
     */
118
    abstract public function parse();
119
}

Read our documentation on viewing source code .

Loading