⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transformer.php

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php//// +---------------------------------------------------------------------------+// | PEAR :: XML :: Transformer                                                |// +---------------------------------------------------------------------------+// | Copyright (c) 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de> and |// |                         Kristian K鰄ntopp <kris@koehntopp.de>.            |// +---------------------------------------------------------------------------+// | This source file is subject to version 3.00 of the PHP License,           |// | that is available 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.                    |// +---------------------------------------------------------------------------+//// $Id: Transformer.php,v 1.137 2004/11/20 08:23:51 sebastian Exp $//require_once 'XML/Transformer/CallbackRegistry.php';require_once 'XML/Util.php';/** * XML Transformations in PHP. * * With this class one can easily bind PHP functionality to XML tags, * thus transforming an XML input tree into another XML tree without * the need for XSLT. * * @author      Sebastian Bergmann <sb@sebastian-bergmann.de> * @author      Kristian K鰄ntopp <kris@koehntopp.de> * @copyright   Copyright &copy; 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de> and Kristian K鰄ntopp <kris@koehntopp.de> * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category    XML * @package     XML_Transformer */class XML_Transformer {    // {{{ Members    /**    * @var    object    * @access private    */    var $_callbackRegistry = NULL;    /**    * If TRUE, XML attribute and element names will be    * case-folded.    *     * @var    boolean    * @access private    * @see    $_caseFoldingTo    */    var $_caseFolding = FALSE;    /**    * Can be set to either CASE_UPPER or CASE_LOWER    * and sets the target case for the case-folding.    *    * @var    integer    * @access private    * @see    $_caseFolding    */    var $_caseFoldingTo = CASE_UPPER;    /**    * When set to TRUE empty XML tags (<foo></foo>) are    * collapsed to their short-tag (<foo/>) equivalent.    *    * @var    boolean    * @access private    */    var $_collapseEmptyTags = FALSE;    /**    * Collapse mode    *    * @var    int    * @access private    */    var $_collapseEmptyTagsMode = XML_UTIL_COLLAPSE_ALL;    /**    * If TRUE, debugging information will be sent to    * the error.log.    *    * @var    boolean    * @access private    * @see    $_debugFilter    */    var $_debug = FALSE;    /**    * If not empty, debugging information will only be generated    * for XML elements whose names are in this array.    *    * @var    array    * @access private    * @see    $_debug    */    var $_debugFilter = array();    /**    * Specifies the target to which error messages and    * debugging messages are sent.    *    * @var    string    * @access private    * @see    $_debug    */    var $_logTarget = 'error_log';    /**    * @var    array    * @access private    */    var $_attributesStack = array();    /**    * @var    array    * @access private    */    var $_cdataStack = array('');    /**    * @var    array    * @access private    */    var $_elementStack = array();    /**    * @var    integer    * @access private    */    var $_level = 0;    /**    * @var    string    * @access private    */    var $_lastProcessed = '';    /**    * @var    boolean    * @access public    */    var $_secondPassRequired = FALSE;    /**    * @var    integer    * @access private    */    var $_depth = 0;    // }}}    // {{{ function XML_Transformer($parameters = array())    /**    * Constructor.    *    * @param  array    * @access public    */    function XML_Transformer($parameters = array()) {        // Parse parameters array.        if (isset($parameters['debug'])) {            $this->setDebug($parameters['debug']);        }        $this->_caseFolding           = isset($parameters['caseFolding'])           ? $parameters['caseFolding']           : FALSE;        $this->_collapseEmptyTags     = isset($parameters['collapseEmptyTags'])     ? $parameters['collapseEmptyTags']     : FALSE;        $this->_collapseEmptyTagsMode = isset($parameters['collapseEmptyTagsMode']) ? $parameters['collapseEmptyTagsMode'] : XML_UTIL_COLLAPSE_ALL;        $this->_caseFoldingTo         = isset($parameters['caseFoldingTo'])         ? $parameters['caseFoldingTo']         : CASE_UPPER;        $this->_lastProcessed         = isset($parameters['lastProcessed'])         ? $parameters['lastProcessed']         : '';        $this->_logTarget             = isset($parameters['logTarget'])             ? $parameters['logTarget']             : 'error_log';        $autoload                     = isset($parameters['autoload'])              ? $parameters['autoload']              : FALSE;        $overloadedNamespaces         = isset($parameters['overloadedNamespaces'])  ? $parameters['overloadedNamespaces']  : array();        $recursiveOperation           = isset($parameters['recursiveOperation'])    ? $parameters['recursiveOperation']    : TRUE;        // Initialize callback registry.        if (!isset($parameters['callbackRegistry'])) {            $this->_callbackRegistry = new XML_Transformer_CallbackRegistry($recursiveOperation);        } else {            $this->_callbackRegistry = &$parameters['callbackRegistry'];        }        foreach ($overloadedNamespaces as $namespacePrefix => $object) {            $this->overloadNamespace(              $namespacePrefix,              $object            );        }        if ($autoload !== FALSE) {            $this->_autoload($autoload);        }    }    // }}}    // {{{ function canonicalize($target)    /**    * Canonicalizes a given attributes array or element name.    *    * @param  mixed    * @return mixed    * @access public    */    function canonicalize($target) {        if ($this->_caseFolding) {            if (is_string($target)) {                return ($this->_caseFoldingTo == CASE_UPPER) ? strtoupper($target) : strtolower($target);            } else {                return array_change_key_case(                  $target,                  $this->_caseFoldingTo                );            }        }        return $target;    }    // }}}    // {{{ function overloadNamespace($namespacePrefix, &$object, $recursiveOperation = '')    /**    * Overloads an XML Namespace.    *    * @param  string    * @param  object    * @param  boolean    * @access public    */    function overloadNamespace($namespacePrefix, &$object, $recursiveOperation = '') {        if (empty($namespacePrefix) ||            $namespacePrefix == '&MAIN') {            $namespacePrefix = '&MAIN';        } else {            $namespacePrefix = $this->canonicalize($namespacePrefix);        }        $result = $this->_callbackRegistry->overloadNamespace(          $namespacePrefix,          $object,          $recursiveOperation        );        if ($result === TRUE) {            if ($object->secondPassRequired) {                $this->_secondPassRequired = TRUE;            }            // Call initObserver() on the object, if it exists.            if (method_exists($object, 'initObserver')) {                $object->initObserver(                  $namespacePrefix,                  $this                );            }        } else {            $this->sendMessage(              $result,              $this->_logTarget            );        }    }    // }}}    // {{{ function unOverloadNamespace($namespacePrefix)    /**    * Reverts overloading of a given XML Namespace.    *    * @param  string    * @access public    */    function unOverloadNamespace($namespacePrefix) {        $this->_callbackRegistry->unOverloadNamespace($namespacePrefix);    }    // }}}    // {{{ function isOverloadedNamespace($namespacePrefix)    /**    * Returns TRUE if a given namespace is overloaded,    * FALSE otherwise.    *    * @param  string    * @return boolean    * @access public    */    function isOverloadedNamespace($namespacePrefix) {        return $this->_callbackRegistry->isOverloadedNamespace(          $this->canonicalize($namespacePrefix)        );    }    // }}}    // {{{ function sendMessage($message, $target = 'error_log')    /**    * Sends a message to a given target.    *    * @param  string    * @param  string    * @access public    */    function sendMessage($message, $target = 'error_log') {        switch ($target) {            case 'echo':            case 'print': {                print $message;            }            break;            default: {                error_log($message);            }        }    }    // }}}    // {{{ function setCaseFolding($caseFolding)    /**    * Sets the XML parser's case-folding option.    *    * @param  boolean    * @param  integer    * @access public    */    function setCaseFolding($caseFolding, $caseFoldingTo = CASE_UPPER) {        if (is_bool($caseFolding) &&            ($caseFoldingTo == CASE_LOWER || $caseFoldingTo == CASE_UPPER)) {            $this->_caseFolding   = $caseFolding;            $this->_caseFoldingTo = $caseFoldingTo;        }    }    // }}}    // {{{ function setCollapsingOfEmptyTags($collapseEmptyTags, $mode = XML_UTIL_COLLAPSE_ALL)    /**    * Sets the collapsing of empty tags.    *    * @param  boolean    * @param  integer    * @access public    */    function setCollapsingOfEmptyTags($collapseEmptyTags, $mode = XML_UTIL_COLLAPSE_ALL) {        if (is_bool($collapseEmptyTags) &&            ($mode == XML_UTIL_COLLAPSE_ALL || $mode == XML_UTIL_COLLAPSE_XHTML_ONLY)) {            $this->_collapseEmptyTags     = $collapseEmptyTags;            $this->_collapseEmptyTagsMode = $mode;        }    }    // }}}    // {{{ function setDebug($debug)    /**    * Enables or disables debugging information.    *    * @param  mixed    * @access public    */    function setDebug($debug) {        if (is_array($debug)) {            $this->_debug       = TRUE;            $this->_debugFilter = array_flip($debug);        }        else if (is_bool($debug)) {            $this->_debug = $debug;        }    }    // }}}    // {{{ function setLogTarget($logTarget)    /**    * Sets the target to which error messages and    * debugging messages are sent.    *    * @param  string    * @access public    */    function setLogTarget($logTarget) {        $this->_logTarget = $logTarget;    }    // }}}    // {{{ function setRecursiveOperation($recursiveOperation)    /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -