Abstract.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Client.php 17752 2009-08-22 15:49:54Z lars $
  21. */
  22. /**
  23. * Abstract XML generator adapter
  24. */
  25. abstract class Zend_XmlRpc_Generator_Abstract
  26. {
  27. /**
  28. * @var string
  29. */
  30. protected $_encoding;
  31. /**
  32. * Construct new instance of the generator
  33. *
  34. * @param string $encoding XML encoding, default UTF-8
  35. */
  36. public function __construct($encoding = 'UTF-8')
  37. {
  38. $this->_encoding = $encoding;
  39. $this->_init();
  40. }
  41. /**
  42. * Start XML element
  43. *
  44. * Method opens a new XML element with an element name and an optional value
  45. *
  46. * @param string $name
  47. * @param string $value
  48. * @return Zend_XmlRpc_Generator_Abstract Fluent interface
  49. */
  50. abstract public function startElement($name, $value = null);
  51. /**
  52. * End of an XML element
  53. *
  54. * Method marks the end of an XML element
  55. *
  56. * @param string $name
  57. * @return Zend_XmlRpc_Generator_Abstract Fluent interface
  58. */
  59. abstract public function endElement($name);
  60. /**
  61. * Returns XML as a string
  62. *
  63. * @return string
  64. */
  65. abstract public function saveXml();
  66. /**
  67. * Return encoding
  68. *
  69. * @return string
  70. */
  71. public function getEncoding()
  72. {
  73. return $this->_encoding;
  74. }
  75. /**
  76. * Returns the XML as a string and flushes all internal buffers
  77. *
  78. * @return string
  79. */
  80. public function flush()
  81. {
  82. $xml = $this->saveXml();
  83. $this->_init();
  84. return $xml;
  85. }
  86. /**
  87. * Returns XML without document declaration
  88. *
  89. * @return string
  90. */
  91. public function __toString()
  92. {
  93. return $this->stripDeclaration($this->saveXml());
  94. }
  95. /**
  96. * Removes XML declaration from a string
  97. *
  98. * @param string $xml
  99. * @return string
  100. */
  101. public function stripDeclaration($xml)
  102. {
  103. return preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
  104. }
  105. }