Update to PEAR 1.7.2, Image_Canvas 0.3.1, Image_Color 1.0.3, Image_Graph 0.7.2, XML_Parser 1.3.1.

Removed PHP_Compat, and references to it.
Removed ionCube/Zend/mmCache compatibility checks in test.php script.
Changed minimum PHP requirement to 5.0 in test.php script.
This commit is contained in:
anubis
2009-01-04 19:22:54 -05:00
parent 60b674c776
commit fae6352bf2
384 changed files with 34150 additions and 44524 deletions

View File

@@ -1,36 +1,52 @@
<?php
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Stig Bakken <ssb@fast.no> |
// | Tomas V.V.Cox <cox@idecnet.com> |
// | Stephan Schmidt <schst@php-tools.net> |
// +----------------------------------------------------------------------+
//
// $Id: Parser.php,v 1.26 2005/09/23 11:51:10 schst Exp $
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* XML Parser class.
* XML_Parser
*
* This is an XML parser based on PHP's "xml" extension,
* based on the bundled expat library.
* XML Parser package
*
* @category XML
* @package XML_Parser
* @author Stig Bakken <ssb@fast.no>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Stephan Schmidt <schst@php-tools.net>
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 2002-2008 The PHP Group
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category XML
* @package XML_Parser
* @author Stig Bakken <ssb@fast.no>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Stephan Schmidt <schst@php.net>
* @copyright 2002-2008 The PHP Group
* @license http://opensource.org/licenses/bsd-license New BSD License
* @version CVS: $Id: Parser.php,v 1.29 2008/08/24 21:48:21 ashnazg Exp $
* @link http://pear.php.net/package/XML_Parser
*/
/**
@@ -79,25 +95,29 @@ define('XML_PARSER_ERROR_REMOTE', 205);
* - From revision 1.17, the function names used by the 'func' mode
* are in the format "xmltag_$elem", for example: use "xmltag_name"
* to handle the <name></name> tags of your xml file.
*
* @category XML
* @package XML_Parser
* @author Stig Bakken <ssb@fast.no>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Stephan Schmidt <schst@php-tools.net>
* @todo create XML_Parser_Namespace to parse documents with namespaces
* @todo create XML_Parser_Pull
* @todo Tests that need to be made:
* - mixing character encodings
* - a test using all expat handlers
* - options (folding, output charset)
* - different parsing modes
*
* @category XML
* @package XML_Parser
* @author Stig Bakken <ssb@fast.no>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Stephan Schmidt <schst@php.net>
* @copyright 2002-2008 The PHP Group
* @license http://opensource.org/licenses/bsd-license New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/XML_Parser
* @todo create XML_Parser_Namespace to parse documents with namespaces
* @todo create XML_Parser_Pull
* @todo Tests that need to be made:
* - mixing character encodings
* - a test using all expat handlers
* - options (folding, output charset)
*/
class XML_Parser extends PEAR
{
// {{{ properties
/**
/**
* XML parser handle
*
* @var resource
@@ -164,8 +184,15 @@ class XML_Parser extends PEAR
*/
var $_handlerObj;
/**
* valid encodings
*
* @var array
*/
var $_validEncodings = array('ISO-8859-1', 'UTF-8', 'US-ASCII');
// }}}
// {{{ constructor
// {{{ php4 constructor
/**
* Creates an XML parser.
@@ -178,13 +205,14 @@ class XML_Parser extends PEAR
* @param string $mode how this parser object should work, "event" for
* startelement/endelement-type events, "func"
* to have it call functions named after elements
* @param string $tgenc a valid target encoding
* @param string $tgtenc a valid target encoding
*/
function XML_Parser($srcenc = null, $mode = 'event', $tgtenc = null)
{
XML_Parser::__construct($srcenc, $mode, $tgtenc);
}
// }}}
// {{{ php5 constructor
/**
* PHP5 constructor
@@ -194,7 +222,7 @@ class XML_Parser extends PEAR
* @param string $mode how this parser object should work, "event" for
* startelement/endelement-type events, "func"
* to have it call functions named after elements
* @param string $tgenc a valid target encoding
* @param string $tgtenc a valid target encoding
*/
function __construct($srcenc = null, $mode = 'event', $tgtenc = null)
{
@@ -219,14 +247,16 @@ class XML_Parser extends PEAR
* This method is only needed, when switching to a new
* mode at a later point.
*
* @access public
* @param string mode, either 'func' or 'event'
* @return boolean|object true on success, PEAR_Error otherwise
* @param string $mode mode, either 'func' or 'event'
*
* @return boolean|object true on success, PEAR_Error otherwise
* @access public
*/
function setMode($mode)
{
if ($mode != 'func' && $mode != 'event') {
$this->raiseError('Unsupported mode given', XML_PARSER_ERROR_UNSUPPORTED_MODE);
$this->raiseError('Unsupported mode given',
XML_PARSER_ERROR_UNSUPPORTED_MODE);
}
$this->mode = $mode;
@@ -243,10 +273,11 @@ class XML_Parser extends PEAR
* If no object will be set, XML_Parser assumes that you
* extend this class and handle the events in $this.
*
* @access public
* @param object object to handle the events
* @return boolean will always return true
* @since v1.2.0beta3
* @param object &$obj object to handle the events
*
* @return boolean will always return true
* @access public
* @since v1.2.0beta3
*/
function setHandlerObj(&$obj)
{
@@ -257,7 +288,8 @@ class XML_Parser extends PEAR
/**
* Init the element handlers
*
* @access private
* @return mixed
* @access private
*/
function _initHandlers()
{
@@ -270,21 +302,22 @@ class XML_Parser extends PEAR
}
switch ($this->mode) {
case 'func':
xml_set_object($this->parser, $this->_handlerObj);
xml_set_element_handler($this->parser, array(&$this, 'funcStartHandler'), array(&$this, 'funcEndHandler'));
break;
case 'func':
xml_set_object($this->parser, $this->_handlerObj);
xml_set_element_handler($this->parser,
array(&$this, 'funcStartHandler'), array(&$this, 'funcEndHandler'));
break;
case 'event':
xml_set_object($this->parser, $this->_handlerObj);
xml_set_element_handler($this->parser, 'startHandler', 'endHandler');
break;
default:
return $this->raiseError('Unsupported mode given', XML_PARSER_ERROR_UNSUPPORTED_MODE);
break;
case 'event':
xml_set_object($this->parser, $this->_handlerObj);
xml_set_element_handler($this->parser, 'startHandler', 'endHandler');
break;
default:
return $this->raiseError('Unsupported mode given',
XML_PARSER_ERROR_UNSUPPORTED_MODE);
break;
}
/**
* set additional handlers for character data, entities, etc.
*/
@@ -293,7 +326,7 @@ class XML_Parser extends PEAR
$xml_func = 'xml_set_' . $xml_func;
$xml_func($this->parser, $method);
}
}
}
}
// {{{ _create()
@@ -307,9 +340,10 @@ class XML_Parser extends PEAR
* Furthermore it allows us returning an error
* if something fails.
*
* @access private
* @return boolean|object true on success, PEAR_Error otherwise
* NOTE: uses '@' error suppresion in this method
*
* @return bool|PEAR_Error true on success, PEAR_Error otherwise
* @access private
* @see xml_parser_create
*/
function _create()
@@ -321,21 +355,27 @@ class XML_Parser extends PEAR
}
if (is_resource($xp)) {
if ($this->tgtenc !== null) {
if (!@xml_parser_set_option($xp, XML_OPTION_TARGET_ENCODING,
$this->tgtenc)) {
return $this->raiseError('invalid target encoding', XML_PARSER_ERROR_INVALID_ENCODING);
if (!@xml_parser_set_option($xp, XML_OPTION_TARGET_ENCODING,
$this->tgtenc)
) {
return $this->raiseError('invalid target encoding',
XML_PARSER_ERROR_INVALID_ENCODING);
}
}
$this->parser = $xp;
$result = $this->_initHandlers($this->mode);
$result = $this->_initHandlers($this->mode);
if ($this->isError($result)) {
return $result;
}
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, $this->folding);
return true;
}
return $this->raiseError('Unable to create XML parser resource.', XML_PARSER_ERROR_NO_RESOURCE);
if (!in_array(strtoupper($this->srcenc), $this->_validEncodings)) {
return $this->raiseError('invalid source encoding',
XML_PARSER_ERROR_INVALID_ENCODING);
}
return $this->raiseError('Unable to create XML parser resource.',
XML_PARSER_ERROR_NO_RESOURCE);
}
// }}}
@@ -353,7 +393,7 @@ class XML_Parser extends PEAR
function reset()
{
$result = $this->_create();
if ($this->isError( $result )) {
if ($this->isError($result)) {
return $result;
}
return true;
@@ -365,11 +405,12 @@ class XML_Parser extends PEAR
/**
* Sets the input xml file to be parsed
*
* @param string Filename (full path)
* @return resource fopen handle of the given file
* @throws XML_Parser_Error
* @see setInput(), setInputString(), parse()
* @access public
* @param string $file Filename (full path)
*
* @return resource fopen handle of the given file
* @access public
* @throws XML_Parser_Error
* @see setInput(), setInputString(), parse()
*/
function setInputFile($file)
{
@@ -378,35 +419,39 @@ class XML_Parser extends PEAR
*/
if (eregi('^(http|ftp)://', substr($file, 0, 10))) {
if (!ini_get('allow_url_fopen')) {
return $this->raiseError('Remote files cannot be parsed, as safe mode is enabled.', XML_PARSER_ERROR_REMOTE);
return $this->
raiseError('Remote files cannot be parsed, as safe mode is enabled.',
XML_PARSER_ERROR_REMOTE);
}
}
$fp = @fopen($file, 'rb');
if (is_resource($fp)) {
$this->fp = $fp;
return $fp;
}
return $this->raiseError('File could not be opened.', XML_PARSER_ERROR_FILE_NOT_READABLE);
return $this->raiseError('File could not be opened.',
XML_PARSER_ERROR_FILE_NOT_READABLE);
}
// }}}
// {{{ setInputString()
/**
* XML_Parser::setInputString()
*
*
* Sets the xml input from a string
*
*
* @param string $data a string containing the XML document
*
* @return null
**/
*/
function setInputString($data)
{
$this->fp = $data;
return null;
}
// }}}
// {{{ setInput()
@@ -414,35 +459,35 @@ class XML_Parser extends PEAR
* Sets the file handle to use with parse().
*
* You should use setInputFile() or setInputString() if you
* pass a string
* pass a string
*
* @param mixed $fp Can be either a resource returned from fopen(),
* a URL, a local filename or a string.
* @access public
* @see parse()
* @uses setInputString(), setInputFile()
* @param mixed $fp Can be either a resource returned from fopen(),
* a URL, a local filename or a string.
*
* @return mixed
* @access public
* @see parse()
* @uses setInputString(), setInputFile()
*/
function setInput($fp)
{
if (is_resource($fp)) {
$this->fp = $fp;
return true;
}
// see if it's an absolute URL (has a scheme at the beginning)
elseif (eregi('^[a-z]+://', substr($fp, 0, 10))) {
} elseif (eregi('^[a-z]+://', substr($fp, 0, 10))) {
// see if it's an absolute URL (has a scheme at the beginning)
return $this->setInputFile($fp);
}
// see if it's a local file
elseif (file_exists($fp)) {
} elseif (file_exists($fp)) {
// see if it's a local file
return $this->setInputFile($fp);
}
// it must be a string
else {
} else {
// it must be a string
$this->fp = $fp;
return true;
}
return $this->raiseError('Illegal input format', XML_PARSER_ERROR_INVALID_INPUT);
return $this->raiseError('Illegal input format',
XML_PARSER_ERROR_INVALID_INPUT);
}
// }}}
@@ -451,8 +496,8 @@ class XML_Parser extends PEAR
/**
* Central parsing function.
*
* @return true|object PEAR error returns true on success, or a PEAR_Error otherwise
* @access public
* @return bool|PEAR_Error returns true on success, or a PEAR_Error otherwise
* @access public
*/
function parse()
{
@@ -465,7 +510,7 @@ class XML_Parser extends PEAR
}
// if $this->fp was fopened previously
if (is_resource($this->fp)) {
while ($data = fread($this->fp, 4096)) {
if (!$this->_parseString($data, feof($this->fp))) {
$error = &$this->raiseError();
@@ -473,8 +518,8 @@ class XML_Parser extends PEAR
return $error;
}
}
// otherwise, $this->fp must be a string
} else {
// otherwise, $this->fp must be a string
if (!$this->_parseString($this->fp, true)) {
$error = &$this->raiseError();
$this->free();
@@ -488,9 +533,10 @@ class XML_Parser extends PEAR
/**
* XML_Parser::_parseString()
*
* @param string $data
* @param boolean $eof
*
* @param string $data data
* @param bool $eof end-of-file flag
*
* @return bool
* @access private
* @see parseString()
@@ -499,31 +545,33 @@ class XML_Parser extends PEAR
{
return xml_parse($this->parser, $data, $eof);
}
// }}}
// {{{ parseString()
/**
* XML_Parser::parseString()
*
*
* Parses a string.
*
* @param string $data XML data
* @param boolean $eof If set and TRUE, data is the last piece of data sent in this parser
* @throws XML_Parser_Error
* @return Pear Error|true true on success or a PEAR Error
* @see _parseString()
* @param string $data XML data
* @param boolean $eof If set and TRUE, data is the last piece
* of data sent in this parser
*
* @return bool|PEAR_Error true on success or a PEAR Error
* @throws XML_Parser_Error
* @see _parseString()
*/
function parseString($data, $eof = false)
{
if (!isset($this->parser) || !is_resource($this->parser)) {
$this->reset();
}
if (!$this->_parseString($data, $eof)) {
$error = &$this->raiseError();
$this->free();
return $error;
$error = &$this->raiseError();
$this->free();
return $error;
}
if ($eof === true) {
@@ -531,12 +579,12 @@ class XML_Parser extends PEAR
}
return true;
}
/**
* XML_Parser::free()
*
*
* Free the internal resources associated with the parser
*
*
* @return null
**/
function free()
@@ -551,15 +599,16 @@ class XML_Parser extends PEAR
unset($this->fp);
return null;
}
/**
* XML_Parser::raiseError()
*
*
* Throws a XML_Parser_Error
*
*
* @param string $msg the error message
* @param integer $ecode the error message code
* @return XML_Parser_Error
*
* @return XML_Parser_Error
**/
function raiseError($msg = null, $ecode = 0)
{
@@ -567,32 +616,46 @@ class XML_Parser extends PEAR
$err = &new XML_Parser_Error($msg, $ecode);
return parent::raiseError($err);
}
// }}}
// {{{ funcStartHandler()
/**
* derives and calls the Start Handler function
*
* @param mixed $xp ??
* @param mixed $elem ??
* @param mixed $attribs ??
*
* @return void
*/
function funcStartHandler($xp, $elem, $attribs)
{
$func = 'xmltag_' . $elem;
if (strchr($func, '.')) {
$func = str_replace('.', '_', $func);
}
$func = str_replace(array('.', '-', ':'), '_', $func);
if (method_exists($this->_handlerObj, $func)) {
call_user_func(array(&$this->_handlerObj, $func), $xp, $elem, $attribs);
} elseif (method_exists($this->_handlerObj, 'xmltag')) {
call_user_func(array(&$this->_handlerObj, 'xmltag'), $xp, $elem, $attribs);
call_user_func(array(&$this->_handlerObj, 'xmltag'),
$xp, $elem, $attribs);
}
}
// }}}
// {{{ funcEndHandler()
/**
* derives and calls the End Handler function
*
* @param mixed $xp ??
* @param mixed $elem ??
*
* @return void
*/
function funcEndHandler($xp, $elem)
{
$func = 'xmltag_' . $elem . '_';
if (strchr($func, '.')) {
$func = str_replace('.', '_', $func);
}
$func = str_replace(array('.', '-', ':'), '_', $func);
if (method_exists($this->_handlerObj, $func)) {
call_user_func(array(&$this->_handlerObj, $func), $xp, $elem);
} elseif (method_exists($this->_handlerObj, 'xmltag_')) {
@@ -604,24 +667,35 @@ class XML_Parser extends PEAR
// {{{ startHandler()
/**
* abstract method signature for Start Handler
*
* @param mixed $xp ??
* @param mixed $elem ??
* @param mixed &$attribs ??
*
* @return null
* @abstract
*/
function startHandler($xp, $elem, &$attribs)
{
return NULL;
return null;
}
// }}}
// {{{ endHandler()
/**
* abstract method signature for End Handler
*
* @param mixed $xp ??
* @param mixed $elem ??
*
* @return null
* @abstract
*/
function endHandler($xp, $elem)
{
return NULL;
return null;
}
@@ -639,47 +713,56 @@ class XML_Parser extends PEAR
* - check for XML_Parser error, using is_a( $error, 'XML_Parser_Error' )
* - messages can be generated from the xml_parser resource
*
* @package XML_Parser
* @access public
* @see PEAR_Error
* @category XML
* @package XML_Parser
* @author Stig Bakken <ssb@fast.no>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Stephan Schmidt <schst@php.net>
* @copyright 2002-2008 The PHP Group
* @license http://opensource.org/licenses/bsd-license New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/XML_Parser
* @see PEAR_Error
*/
class XML_Parser_Error extends PEAR_Error
{
// {{{ properties
/**
/**
* prefix for all messages
*
* @var string
*/
*/
var $error_message_prefix = 'XML_Parser: ';
// }}}
// {{{ constructor()
/**
/**
* construct a new error instance
*
* You may either pass a message or an xml_parser resource as first
* parameter. If a resource has been passed, the last error that
* happened will be retrieved and returned.
*
* @param string|resource $msgorparser message or parser resource
* @param integer $code error code
* @param integer $mode error handling
* @param integer $level error level
*
* @access public
* @param string|resource message or parser resource
* @param integer error code
* @param integer error handling
* @param integer error level
*/
* @todo PEAR CS - can't meet 85char line limit without arg refactoring
*/
function XML_Parser_Error($msgorparser = 'unknown error', $code = 0, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE)
{
if (is_resource($msgorparser)) {
$code = xml_get_error_code($msgorparser);
$code = xml_get_error_code($msgorparser);
$msgorparser = sprintf('%s at XML input line %d:%d',
xml_error_string($code),
xml_get_current_line_number($msgorparser),
xml_get_current_column_number($msgorparser));
xml_error_string($code),
xml_get_current_line_number($msgorparser),
xml_get_current_column_number($msgorparser));
}
$this->PEAR_Error($msgorparser, $code, $mode, $level);
}
// }}}
}
?>
?>

View File

@@ -1,37 +1,50 @@
<?php
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Stephan Schmidt <schst@php-tools.net> |
// +----------------------------------------------------------------------+
//
// $Id: Simple.php,v 1.6 2005/03/25 17:13:10 schst Exp $
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Simple XML parser class.
* XML_Parser
*
* This class is a simplified version of XML_Parser.
* In most XML applications the real action is executed,
* when a closing tag is found.
* XML Parser's Simple parser class
*
* XML_Parser_Simple allows you to just implement one callback
* for each tag that will receive the tag with its attributes
* and CData
* PHP versions 4 and 5
*
* @category XML
* @package XML_Parser
* @author Stephan Schmidt <schst@php-tools.net>
* LICENSE:
*
* Copyright (c) 2002-2008 The PHP Group
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category XML
* @package XML_Parser
* @author Stephan Schmidt <schst@php.net>
* @copyright 2004-2008 Stephan Schmidt <schst@php.net>
* @license http://opensource.org/licenses/bsd-license New BSD License
* @version CVS: $Id: Simple.php,v 1.7 2008/08/24 21:48:21 ashnazg Exp $
* @link http://pear.php.net/package/XML_Parser
*/
/**
@@ -72,34 +85,38 @@ require_once 'XML/Parser.php';
* $result = $p->parse();
* </code>
*
* @category XML
* @package XML_Parser
* @author Stephan Schmidt <schst@php-tools.net>
* @category XML
* @package XML_Parser
* @author Stephan Schmidt <schst@php.net>
* @copyright 2004-2008 The PHP Group
* @license http://opensource.org/licenses/bsd-license New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/XML_Parser
*/
class XML_Parser_Simple extends XML_Parser
{
/**
* element stack
*
* @access private
* @var array
*/
/**
* element stack
*
* @access private
* @var array
*/
var $_elStack = array();
/**
* all character data
*
* @access private
* @var array
*/
/**
* all character data
*
* @access private
* @var array
*/
var $_data = array();
/**
* element depth
*
* @access private
* @var integer
*/
/**
* element depth
*
* @access private
* @var integer
*/
var $_depth = 0;
/**
@@ -126,7 +143,7 @@ class XML_Parser_Simple extends XML_Parser
* @param string $mode how this parser object should work, "event" for
* handleElement(), "func" to have it call functions
* named after elements (handleElement_$name())
* @param string $tgenc a valid target encoding
* @param string $tgtenc a valid target encoding
*/
function XML_Parser_Simple($srcenc = null, $mode = 'event', $tgtenc = null)
{
@@ -136,7 +153,8 @@ class XML_Parser_Simple extends XML_Parser
/**
* inits the handlers
*
* @access private
* @return mixed
* @access private
*/
function _initHandlers()
{
@@ -145,11 +163,13 @@ class XML_Parser_Simple extends XML_Parser
}
if ($this->mode != 'func' && $this->mode != 'event') {
return $this->raiseError('Unsupported mode given', XML_PARSER_ERROR_UNSUPPORTED_MODE);
return $this->raiseError('Unsupported mode given',
XML_PARSER_ERROR_UNSUPPORTED_MODE);
}
xml_set_object($this->parser, $this->_handlerObj);
xml_set_element_handler($this->parser, array(&$this, 'startHandler'), array(&$this, 'endHandler'));
xml_set_element_handler($this->parser, array(&$this, 'startHandler'),
array(&$this, 'endHandler'));
xml_set_character_data_handler($this->parser, array(&$this, 'cdataHandler'));
/**
@@ -160,7 +180,7 @@ class XML_Parser_Simple extends XML_Parser
$xml_func = 'xml_set_' . $xml_func;
$xml_func($this->parser, $method);
}
}
}
}
/**
@@ -179,44 +199,47 @@ class XML_Parser_Simple extends XML_Parser
$this->_depth = 0;
$result = $this->_create();
if ($this->isError( $result )) {
if ($this->isError($result)) {
return $result;
}
return true;
}
/**
* start handler
*
* Pushes attributes and tagname onto a stack
*
* @access private
* @final
* @param resource xml parser resource
* @param string element name
* @param array attributes
*/
/**
* start handler
*
* Pushes attributes and tagname onto a stack
*
* @param resource $xp xml parser resource
* @param string $elem element name
* @param array &$attribs attributes
*
* @return mixed
* @access private
* @final
*/
function startHandler($xp, $elem, &$attribs)
{
array_push($this->_elStack, array(
'name' => $elem,
'attribs' => $attribs
)
);
'name' => $elem,
'attribs' => $attribs
));
$this->_depth++;
$this->_data[$this->_depth] = '';
}
/**
* end handler
*
* Pulls attributes and tagname from a stack
*
* @access private
* @final
* @param resource xml parser resource
* @param string element name
*/
/**
* end handler
*
* Pulls attributes and tagname from a stack
*
* @param resource $xp xml parser resource
* @param string $elem element name
*
* @return mixed
* @access private
* @final
*/
function endHandler($xp, $elem)
{
$el = array_pop($this->_elStack);
@@ -224,72 +247,78 @@ class XML_Parser_Simple extends XML_Parser
$this->_depth--;
switch ($this->mode) {
case 'event':
$this->_handlerObj->handleElement($el['name'], $el['attribs'], $data);
break;
case 'func':
$func = 'handleElement_' . $elem;
if (strchr($func, '.')) {
$func = str_replace('.', '_', $func);
}
if (method_exists($this->_handlerObj, $func)) {
call_user_func(array(&$this->_handlerObj, $func), $el['name'], $el['attribs'], $data);
}
break;
case 'event':
$this->_handlerObj->handleElement($el['name'], $el['attribs'], $data);
break;
case 'func':
$func = 'handleElement_' . $elem;
if (strchr($func, '.')) {
$func = str_replace('.', '_', $func);
}
if (method_exists($this->_handlerObj, $func)) {
call_user_func(array(&$this->_handlerObj, $func),
$el['name'], $el['attribs'], $data);
}
break;
}
}
/**
* handle character data
*
* @access private
* @final
* @param resource xml parser resource
* @param string data
*/
/**
* handle character data
*
* @param resource $xp xml parser resource
* @param string $data data
*
* @return void
* @access private
* @final
*/
function cdataHandler($xp, $data)
{
$this->_data[$this->_depth] .= $data;
}
/**
* handle a tag
*
* Implement this in your parser
*
* @access public
* @abstract
* @param string element name
* @param array attributes
* @param string character data
*/
/**
* handle a tag
*
* Implement this in your parser
*
* @param string $name element name
* @param array $attribs attributes
* @param string $data character data
*
* @return void
* @access public
* @abstract
*/
function handleElement($name, $attribs, $data)
{
}
/**
* get the current tag depth
*
* The root tag is in depth 0.
*
* @access public
* @return integer
*/
/**
* get the current tag depth
*
* The root tag is in depth 0.
*
* @access public
* @return integer
*/
function getCurrentDepth()
{
return $this->_depth;
}
/**
* add some string to the current ddata.
*
* This is commonly needed, when a document is parsed recursively.
*
* @access public
* @param string data to add
* @return void
*/
function addToData( $data )
/**
* add some string to the current ddata.
*
* This is commonly needed, when a document is parsed recursively.
*
* @param string $data data to add
*
* @return void
* @access public
*/
function addToData($data)
{
$this->_data[$this->_depth] .= $data;
}