Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / XmlRpc / Generator / AbstractGenerator.php
blob3fb78c8292cd41fe683225de2354051be3c3543b
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\XmlRpc\Generator;
12 /**
13 * Abstract XML generator adapter
15 abstract class AbstractGenerator implements GeneratorInterface
17 /**
18 * XML encoding string
20 * @var string
22 protected $encoding;
24 /**
25 * Construct new instance of the generator
27 * @param string $encoding XML encoding, default UTF-8
29 public function __construct($encoding = 'UTF-8')
31 $this->setEncoding($encoding);
32 $this->_init();
35 /**
36 * Initialize internal objects
38 * @return void
40 abstract protected function _init();
42 /**
43 * Start XML element
45 * Method opens a new XML element with an element name and an optional value
47 * @param string $name XML tag name
48 * @param string $value Optional value of the XML tag
49 * @return AbstractGenerator Fluent interface
51 public function openElement($name, $value = null)
53 $this->_openElement($name);
54 if ($value !== null) {
55 $this->_writeTextData($value);
58 return $this;
61 /**
62 * End of an XML element
64 * Method marks the end of an XML element
66 * @param string $name XML tag name
67 * @return AbstractGenerator Fluent interface
69 public function closeElement($name)
71 $this->_closeElement($name);
73 return $this;
76 /**
77 * Return encoding
79 * @return string
81 public function getEncoding()
83 return $this->encoding;
86 /**
87 * Set XML encoding
89 * @param string $encoding
90 * @return AbstractGenerator
92 public function setEncoding($encoding)
94 $this->encoding = $encoding;
95 return $this;
98 /**
99 * Returns the XML as a string and flushes all internal buffers
101 * @return string
103 public function flush()
105 $xml = $this->saveXml();
106 $this->_init();
107 return $xml;
111 * Returns XML without document declaration
113 * @return string
115 public function __toString()
117 return $this->stripDeclaration($this->saveXml());
121 * Removes XML declaration from a string
123 * @param string $xml
124 * @return string
126 public function stripDeclaration($xml)
128 return preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
132 * Start XML element
134 * @param string $name XML element name
136 abstract protected function _openElement($name);
139 * Write XML text data into the currently opened XML element
141 * @param string $text
143 abstract protected function _writeTextData($text);
146 * End XML element
148 * @param string $name
150 abstract protected function _closeElement($name);