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

Source for file Namespace.php

Documentation is available at Namespace.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. require_once 'XML/Util.php';
  19.  
  20.  /**
  21.  * Convenience Base Class for Namespace Transformers.
  22.  *
  23.  * Example
  24.  *
  25.  * <code>
  26.  * <?php
  27.  * require_once 'XML/Transformer.php';
  28.  * require_once 'XML/Transformer/Namespace.php';
  29.  *
  30.  * class Image extends XML_Transformer_Namespace {
  31.  *     var $imageAttributes = array();
  32.  *
  33.  *     function truePath($path) {
  34.  *         if (php_sapi_name() == 'apache') {
  35.  *             $r    = apache_lookup_uri($path);
  36.  *             $path = $r->filename;
  37.  *         } else {
  38.  *             $path = $_SERVER['DOCUMENT_ROOT'] . "/$path";
  39.  *         }
  40.  *
  41.  *         return $path;
  42.  *     }
  43.  *
  44.  *     function start_img($attributes) {
  45.  *         $this->imageAttributes = $attributes;
  46.  *         return '';
  47.  *     }
  48.  *
  49.  *     function end_img($cdata) {
  50.  *         $src = $this->truePath($this->imageAttributes['src']);
  51.  *         list($w, $h, $t, $whs) = getimagesize($src);
  52.  *
  53.  *         $this->imageAttributes['height'] = $w;
  54.  *         $this->imageAttributes['width']  = $h;
  55.  *
  56.  *         return sprintf(
  57.  *           '<img %s/>',
  58.  *           XML_Transformer::attributesToString($this->imageAttributes)
  59.  *         );
  60.  *     }
  61.  * }
  62.  * ?>
  63.  * </code>
  64.  *
  65.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  66.  * @author
  67.  * @copyright
  68.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  69.  * @category    XML
  70.  * @package     XML_Transformer
  71.  */
  72.     // {{{ Members
  73.  
  74.     /**
  75.     * @var    string 
  76.     * @access public
  77.     */
  78.     var $defaultNamespacePrefix = '';
  79.  
  80.     /**
  81.     * @var    boolean 
  82.     * @access public
  83.     */
  84.     var $secondPassRequired = FALSE;
  85.  
  86.     /**
  87.     * @var    array 
  88.     * @access private
  89.     */
  90.     var $_prefix = array();
  91.  
  92.     /**
  93.     * @var    string 
  94.     * @access private
  95.     */
  96.     var $_transformer '';
  97.  
  98.     // }}}
  99.     // {{{ function initObserver($prefix, &$object)
  100.  
  101.     /**
  102.     * Called by XML_Transformer at initialization time.
  103.     * We use this to remember our namespace prefixes
  104.     * (there can be multiple) and a pointer to the
  105.     * Transformer object.
  106.     *
  107.     * @param  string 
  108.     * @param  object 
  109.     * @access public
  110.     */
  111.     function initObserver($prefix&$object{
  112.       $this->_prefix[]    $prefix;
  113.       $this->_transformer $object;
  114.     }
  115.  
  116.     // }}}
  117.     // {{{ function startElement($element, $attributes)
  118.  
  119.     /**
  120.     * Wrapper for startElement handler.
  121.     *
  122.     * @param  string 
  123.     * @param  array 
  124.     * @return string 
  125.     * @access public
  126.     */
  127.     function startElement($element$attributes{
  128.         $do 'start_' $element;
  129.  
  130.         if (method_exists($this$do)) {
  131.             return $this->$do($attributes);
  132.         }
  133.  
  134.         return sprintf(
  135.           "<%s%s>",
  136.  
  137.           $element,
  138.           XML_Util::attributesToString($attributes)
  139.         );
  140.     }
  141.  
  142.     // }}}
  143.     // {{{ function endElement($element, $cdata)
  144.  
  145.     /**
  146.     * Wrapper for endElement handler.
  147.     *
  148.     * @param  string 
  149.     * @param  string 
  150.     * @return array 
  151.     * @access public
  152.     */
  153.     function endElement($element$cdata{
  154.         $do 'end_' $element;
  155.  
  156.         if (method_exists($this$do)) {
  157.             return $this->$do($cdata);
  158.         }
  159.  
  160.         return array(
  161.           sprintf(
  162.             '%s</%s>',
  163.  
  164.             $cdata,
  165.             $element
  166.           ),
  167.           FALSE
  168.         );
  169.     }
  170.  
  171.     // }}}
  172.     // {{{ function function getLock()
  173.  
  174.     /**
  175.     * Lock all other namespace handlers.
  176.     *
  177.     * @return boolean 
  178.     * @access public
  179.     * @see    releaseLock()
  180.     */
  181.     function getLock({
  182.         return $this->_transformer->_callbackRegistry->getLock($this->_prefix[0]);
  183.     }
  184.  
  185.     // }}}
  186.     // {{{ function releaseLock()
  187.  
  188.     /**
  189.     * Releases a lock.
  190.     *
  191.     * @access public
  192.     * @see    getLock()
  193.     */
  194.     function releaseLock({
  195.         $this->_transformer->_callbackRegistry->releaseLock();
  196.     }
  197.  
  198.     // }}}
  199. }
  200.  
  201. /*
  202.  * vim600:  et sw=2 ts=2 fdm=marker
  203.  * vim<600: et sw=2 ts=2
  204.  */
  205. ?>

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