home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / OutputBuffer.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  3.1 KB  |  122 lines

  1. <?php
  2. //
  3. // +---------------------------------------------------------------------------+
  4. // | PEAR :: XML :: Transformer :: Driver :: OutputBuffer                      |
  5. // +---------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de> and |
  7. // |                         Kristian K÷hntopp <kris@koehntopp.de>.            |
  8. // +---------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,           |
  10. // | that is available at http://www.php.net/license/3_0.txt.                  |
  11. // | If you did not receive a copy of the PHP license and are unable to        |
  12. // | obtain it through the world-wide-web, please send a note to               |
  13. // | license@php.net so we can mail you a copy immediately.                    |
  14. // +---------------------------------------------------------------------------+
  15. //
  16. // $Id: OutputBuffer.php,v 1.9 2004/01/01 10:31:54 sebastian Exp $
  17. //
  18.  
  19. require_once 'XML/Transformer.php';
  20.  
  21. /**
  22. * Uses PHP's Output Buffering mechanism to catch the
  23. * output of a script, transforms it, and outputs the
  24. * result.
  25. *
  26. * Example
  27. *
  28. *   <?php
  29. *   require_once 'XML/Transformer/Driver/OutputBuffer.php';
  30. *   require_once 'XML/Transformer/Namespace.php';
  31. *
  32. *   class Main extends XML_Transformer_Namespace {
  33. *       function start_bold($attributes) {
  34. *           return '<b>';
  35. *       }
  36. *
  37. *       function end_bold($cdata) {
  38. *           return $cdata . '</b>';
  39. *       }
  40. *   }
  41. *
  42. *   $t = new XML_Transformer_Driver_OutputBuffer(
  43. *     array(
  44. *       'overloadedNamespaces' => array(
  45. *         '&MAIN' => new Main
  46. *       )
  47. *     )
  48. *   );
  49. *   ?>
  50. *   <bold>text</bold>
  51. *
  52. * Output
  53. *
  54. *   <b>text</b>
  55. *
  56. * @author  Sebastian Bergmann <sb@sebastian-bergmann.de>
  57. * @author  Kristian K÷hntopp <kris@koehntopp.de>
  58. * @version $Revision: 1.9 $
  59. * @access  public
  60. */
  61. class XML_Transformer_Driver_OutputBuffer extends XML_Transformer {
  62.     // {{{ Members
  63.  
  64.     /**
  65.     * @var    boolean
  66.     * @access private
  67.     */
  68.     var $_started = false;
  69.  
  70.     // }}}
  71.     // {{{ function XML_Transformer_Driver_OutputBuffer($parameters = array())
  72.  
  73.     /**
  74.     * Constructor.
  75.     *
  76.     * @param  array
  77.     * @access public
  78.     */
  79.     function XML_Transformer_Driver_OutputBuffer($parameters = array()) {
  80.         $this->XML_Transformer($parameters);
  81.  
  82.         if (!empty($this->_callbackRegistry->overloadedNamespaces)) {
  83.             $this->start();
  84.         }
  85.     }
  86.  
  87.     // }}}
  88.     // {{{ function start()
  89.  
  90.     /**
  91.     * Starts the output-buffering,
  92.     * and thus the transformation.
  93.     *
  94.     * @access public
  95.     */
  96.     function start() {
  97.         if (!$this->_started) {
  98.             ob_start(
  99.               array(
  100.                 $this, 'transform'
  101.               )
  102.             );
  103.  
  104.             $this->_started = true;
  105.  
  106.             if ($this->_checkDebug()) {
  107.                 $this->sendMessage(
  108.                   'start: ' . serialize($this)
  109.                 );
  110.             }
  111.         }
  112.     }
  113.  
  114.     // }}}
  115. }
  116.  
  117. /*
  118.  * vim600:  et sw=2 ts=2 fdm=marker
  119.  * vim<600: et sw=2 ts=2
  120.  */
  121. ?>
  122.