Magento file: lib/Zend/XmlRpc/Generator/GeneratorAbstract.php

Please LogIn to Reply!

Post By: admin | 26-01-2012 06:35 Reply

Magento folder: lib/Zend/XmlRpc/Generator/
Magento file: lib/Zend/XmlRpc/Generator/GeneratorAbstract.php

  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 license@zend.com 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: GeneratorAbstract.php 20785 2010-01-31 09:43:03Z mikaelkael $
  21. */
  22. /**
  23. * Abstract XML generator adapter
  24. */
  25. abstract class Zend_XmlRpc_Generator_GeneratorAbstract
  26. {
  27. /**
  28. * XML encoding string
  29. *
  30. * @var string
  31. */
  32. protected $_encoding;
  33. /**
  34. * Construct new instance of the generator
  35. *
  36. * @param string $encoding XML encoding, default UTF-8
  37. */
  38. public function __construct($encoding = 'UTF-8')
  39. {
  40. $this->_encoding = $encoding;
  41. $this->_init();
  42. }
  43. /**
  44. * Start XML element
  45. *
  46. * Method opens a new XML element with an element name and an optional value
  47. *
  48. * @param string $name XML tag name
  49. * @param string $value Optional value of the XML tag
  50. * @return Zend_XmlRpc_Generator_Abstract Fluent interface
  51. */
  52. public function openElement($name, $value = null)
  53. {
  54. $this->_openElement($name);
  55. if ($value !== null) {
  56. $this->_writeTextData($value);
  57. }
  58. return $this;
  59. }
  60. /**
  61. * End of an XML element
  62. *
  63. * Method marks the end of an XML element
  64. *
  65. * @param string $name XML tag name
  66. * @return Zend_XmlRpc_Generator_Abstract Fluent interface
  67. */
  68. public function closeElement($name)
  69. {
  70. $this->_closeElement($name);
  71. return $this;
  72. }
  73. /**
  74. * Return XML as a string
  75. *
  76. * @return string
  77. */
  78. abstract public function saveXml();
  79. /**
  80. * Return encoding
  81. *
  82. * @return string
  83. */
  84. public function getEncoding()
  85. {
  86. return $this->_encoding;
  87. }
  88. /**
  89. * Returns the XML as a string and flushes all internal buffers
  90. *
  91. * @return string
  92. */
  93. public function flush()
  94. {
  95. $xml = $this->saveXml();
  96. $this->_init();
  97. return $xml;
  98. }
  99. /**
  100. * Returns XML without document declaration
  101. *
  102. * @return string
  103. */
  104. public function __toString()
  105. {
  106. return $this->stripDeclaration($this->saveXml());
  107. }
  108. /**
  109. * Removes XML declaration from a string
  110. *
  111. * @param string $xml
  112. * @return string
  113. */
  114. public function stripDeclaration($xml)
  115. {
  116. return preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
  117. }
  118. /**
  119. * Start XML element
  120. *
  121. * @param string $name XML element name
  122. */
  123. abstract protected function _openElement($name);
  124. /**
  125. * Write XML text data into the currently opened XML element
  126. *
  127. * @param string $text
  128. */
  129. abstract protected function _writeTextData($text);
  130. /**
  131. * End XML element
  132. *
  133. * @param string $name
  134. */
  135. abstract protected function _closeElement($name);
  136. }
`Reply Or Comment!
Please LogIn to Reply!