XML_Transformer
[ class tree: XML_Transformer ] [ index: XML_Transformer ] [ all elements ]

Source for file CallbackRegistry.php

Documentation is available at CallbackRegistry.php

  1. <?php
  2. //
  3. // +---------------------------------------------------------------------------+
  4. // | PEAR :: XML :: Transformer                                                |
  5. // +---------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> and |
  7. // +---------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,           |
  9. // | that is available at http://www.php.net/license/3_0.txt.                  |
  10. // | If you did not receive a copy of the PHP license and are unable to        |
  11. // | obtain it through the world-wide-web, please send a note to               |
  12. // | license@php.net so we can mail you a copy immediately.                    |
  13. // +---------------------------------------------------------------------------+
  14. //
  15. // $Id$
  16. //
  17.  
  18.  /**
  19.  * Callback Registry.
  20.  *
  21.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  22.  * @author
  23.  * @copyright
  24.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  25.  * @category    XML
  26.  * @package     XML_Transformer
  27.  */
  28.     // {{{ Members
  29.  
  30.     /**
  31.     * @var    array 
  32.     * @access public
  33.     */
  34.     var $overloadedNamespaces = array();
  35.  
  36.     /**
  37.     * @var    boolean 
  38.     * @access private
  39.     */
  40.     var $_locked = FALSE;
  41.  
  42.     /**
  43.     * If TRUE, the transformation will continue recursively
  44.     * until the XML contains no more overloaded elements.
  45.     * Can be overrided on a per-element basis.
  46.     *
  47.     * @var    boolean 
  48.     * @access private
  49.     */
  50.     var $_recursiveOperation = TRUE;
  51.  
  52.     // }}}
  53.     // {{{ function XML_Transformer_CallbackRegistry($recursiveOperation)
  54.  
  55.     /**
  56.     * Constructor.
  57.     *
  58.     * @param  boolean 
  59.     * @access public
  60.     */
  61.     function XML_Transformer_CallbackRegistry($recursiveOperation{
  62.         $this->_recursiveOperation $recursiveOperation;
  63.     }
  64.  
  65.     // }}}
  66.     // {{{ function overloadNamespace($namespacePrefix, &$object, $recursiveOperation = '')
  67.  
  68.     /**
  69.     * Overloads an XML Namespace.
  70.     *
  71.     * @param  string 
  72.     * @param  object 
  73.     * @param  boolean 
  74.     * @return mixed 
  75.     * @access public
  76.     */
  77.     function overloadNamespace($namespacePrefix&$object$recursiveOperation ''{
  78.         if (!is_object($object)) {
  79.             return sprintf(
  80.               'Cannot overload namespace "%s", ' .
  81.               'second parameter is not an object.',
  82.  
  83.               $namespacePrefix
  84.             );
  85.         }
  86.  
  87.         if (!is_subclass_of($object'XML_Transformer_Namespace')) {
  88.             return sprintf(
  89.               'Cannot overload namespace "%s", ' .
  90.               'provided object was not instantiated from ' .
  91.               'a class that inherits XML_Transformer_Namespace.',
  92.  
  93.               $namespacePrefix
  94.             );
  95.         }
  96.  
  97.         if (!method_exists($object'startElement'||
  98.             !method_exists($object'endElement')) {
  99.             return sprintf(
  100.               'Cannot overload namespace "%s", ' .
  101.               'method(s) "startElement" and/or "endElement" ' .
  102.               'are missing on given object.',
  103.  
  104.               $namespacePrefix
  105.             );
  106.         }
  107.  
  108.         $this->overloadedNamespaces[$namespacePrefix]['active']             = TRUE;
  109.         $this->overloadedNamespaces[$namespacePrefix]['object']             &$object;
  110.         $this->overloadedNamespaces[$namespacePrefix]['recursiveOperation'is_bool($recursiveOperation$recursiveOperation $this->_recursiveOperation;
  111.  
  112.         return TRUE;
  113.     }
  114.  
  115.     // }}}
  116.     // {{{ function unOverloadNamespace($namespacePrefix)
  117.  
  118.     /**
  119.     * Reverts overloading of a given XML Namespace.
  120.     *
  121.     * @param  string 
  122.     * @access public
  123.     */
  124.     function unOverloadNamespace($namespacePrefix{
  125.         if (isset($this->overloadedNamespaces[$namespacePrefix])) {
  126.             unset($this->overloadedNamespaces[$namespacePrefix]);
  127.         }
  128.     }
  129.  
  130.     // }}}
  131.     // {{{ function isOverloadedNamespace($namespacePrefix)
  132.  
  133.     /**
  134.     * Returns TRUE if a given namespace is overloaded,
  135.     * FALSE otherwise.
  136.     *
  137.     * @param  string 
  138.     * @return boolean 
  139.     * @access public
  140.     */
  141.     function isOverloadedNamespace($namespacePrefix{
  142.         return isset(
  143.           $this->overloadedNamespaces[$namespacePrefix]
  144.         );
  145.     }
  146.  
  147.     // }}}
  148.     // {{{ function setRecursiveOperation($recursiveOperation)
  149.  
  150.     /**
  151.     * Enables or disables the recursive operation.
  152.     *
  153.     * @param  boolean 
  154.     * @access public
  155.     */
  156.     function setRecursiveOperation($recursiveOperation{
  157.         if (is_bool($recursiveOperation)) {
  158.             $this->_recursiveOperation $recursiveOperation;
  159.         }
  160.     }
  161.  
  162.     // }}}
  163.     // {{{ function function getLock($namespace)
  164.  
  165.     /**
  166.     * Lock all namespace handlers except a given one.
  167.     *
  168.     * @string namespace
  169.     * @return boolean 
  170.     * @access public
  171.     * @see    releaseLock()
  172.     */
  173.     function getLock($namespace{
  174.         if (!$this->_locked{
  175.             $namespacePrefixes array_keys($this->overloadedNamespaces);
  176.  
  177.             foreach ($namespacePrefixes as $namespacePrefix{
  178.                 if ($namespacePrefix != $namespace{
  179.                     unset($this->overloadedNamespaces[$namespacePrefix]['active']);
  180.                 }
  181.             }
  182.  
  183.             $this->_locked = TRUE;
  184.  
  185.             return TRUE;
  186.         }
  187.  
  188.         return FALSE;
  189.     }
  190.  
  191.     // }}}
  192.     // {{{ function releaseLock()
  193.  
  194.     /**
  195.     * Releases a lock.
  196.     *
  197.     * @access public
  198.     * @see    getLock()
  199.     */
  200.     function releaseLock({
  201.         $namespacePrefixes array_keys($this->overloadedNamespaces);
  202.  
  203.         foreach ($namespacePrefixes as $namespacePrefix{
  204.             $this->overloadedNamespaces[$namespacePrefix]['active'= TRUE;
  205.         }
  206.  
  207.         $this->_locked = FALSE;
  208.     }
  209.  
  210.     // }}}
  211. }
  212.  
  213. /*
  214.  * vim600:  et sw=2 ts=2 fdm=marker
  215.  * vim<600: et sw=2 ts=2
  216.  */
  217. ?>

Documentation generated on Mon, 11 Mar 2019 15:48:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.