[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/XmlRpc/Generator/ -> GeneratorAbstract.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_XmlRpc
  17   * @subpackage Generator
  18   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20   * @version    $Id$
  21   */
  22  
  23  /**
  24   * Abstract XML generator adapter
  25   */
  26  abstract class Zend_XmlRpc_Generator_GeneratorAbstract
  27  {
  28      /**
  29       * XML encoding string
  30       *
  31       * @var string
  32       */
  33      protected $_encoding;
  34  
  35      /**
  36       * Construct new instance of the generator
  37       *
  38       * @param string $encoding XML encoding, default UTF-8
  39       */
  40      public function __construct($encoding = 'UTF-8')
  41      {
  42          $this->_encoding = $encoding;
  43          $this->_init();
  44      }
  45  
  46      /**
  47       * Start XML element
  48       *
  49       * Method opens a new XML element with an element name and an optional value
  50       * 
  51       * @param string $name XML tag name
  52       * @param string $value Optional value of the XML tag
  53       * @return Zend_XmlRpc_Generator_Abstract Fluent interface
  54       */
  55      public function openElement($name, $value = null)
  56      {
  57          $this->_openElement($name);
  58          if ($value !== null) {
  59              $this->_writeTextData($value);
  60          }
  61  
  62          return $this;
  63      }
  64  
  65      /**
  66       * End of an XML element
  67       *
  68       * Method marks the end of an XML element
  69       *
  70       * @param string $name XML tag name
  71       * @return Zend_XmlRpc_Generator_Abstract Fluent interface
  72       */
  73      public function closeElement($name)
  74      {
  75          $this->_closeElement($name);
  76  
  77          return $this;
  78      }
  79  
  80      /**
  81       * Return XML as a string
  82       *
  83       * @return string
  84       */
  85      abstract public function saveXml();
  86  
  87      /**
  88       * Return encoding
  89       * 
  90       * @return string
  91       */
  92      public function getEncoding()
  93      {
  94          return $this->_encoding;
  95      }
  96  
  97      /**
  98       * Returns the XML as a string and flushes all internal buffers
  99       *
 100       * @return string
 101       */
 102      public function flush()
 103      {
 104          $xml = $this->saveXml();
 105          $this->_init();
 106          return $xml;
 107      }
 108  
 109      /**
 110       * Returns XML without document declaration
 111       *
 112       * @return string
 113       */
 114      public function __toString()
 115      {
 116          return $this->stripDeclaration($this->saveXml());
 117      }
 118  
 119      /**
 120       * Removes XML declaration from a string
 121       *
 122       * @param string $xml
 123       * @return string
 124       */
 125      public function stripDeclaration($xml)
 126      {
 127          return preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
 128      }
 129  
 130      /**
 131       * Start XML element
 132       *
 133       * @param string $name XML element name
 134       */
 135      abstract protected function _openElement($name);
 136  
 137      /**
 138       * Write XML text data into the currently opened XML element
 139       *
 140       * @param string $text
 141       */
 142      abstract protected function _writeTextData($text);
 143  
 144      /**
 145       * End XML element
 146       * 
 147       * @param string $name
 148       */
 149      abstract protected function _closeElement($name);
 150  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1