PageRenderTime 24ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/magento/zendframework1/library/Zend/Feed/Writer/Renderer/RendererAbstract.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 250 lines | 88 code | 24 blank | 138 comment | 3 complexity | e818b72ef7cccb7e411218194c4a90c2 MD5 | raw file
  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_Feed_Writer
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /** @see Zend_Feed_Writer */
  22. #require_once 'Zend/Feed/Writer.php';
  23. /** @see Zend_Version */
  24. #require_once 'Zend/Version.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Feed_Writer
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Feed_Writer_Renderer_RendererAbstract
  32. {
  33. /**
  34. * Extensions
  35. * @var array
  36. */
  37. protected $_extensions = array();
  38. /**
  39. * @var mixed
  40. */
  41. protected $_container = null;
  42. /**
  43. * @var DOMDocument
  44. */
  45. protected $_dom = null;
  46. /**
  47. * @var bool
  48. */
  49. protected $_ignoreExceptions = false;
  50. /**
  51. * @var array
  52. */
  53. protected $_exceptions = array();
  54. /**
  55. * Encoding of all text values
  56. *
  57. * @var string
  58. */
  59. protected $_encoding = 'UTF-8';
  60. /**
  61. * Holds the value "atom" or "rss" depending on the feed type set when
  62. * when last exported.
  63. *
  64. * @var string
  65. */
  66. protected $_type = null;
  67. /**
  68. * @var DOMElement
  69. */
  70. protected $_rootElement = null;
  71. /**
  72. * Constructor
  73. *
  74. * @param mixed $container
  75. * @return void
  76. */
  77. public function __construct($container)
  78. {
  79. $this->_container = $container;
  80. $this->setType($container->getType());
  81. $this->_loadExtensions();
  82. }
  83. /**
  84. * Save XML to string
  85. *
  86. * @return string
  87. */
  88. public function saveXml()
  89. {
  90. return $this->getDomDocument()->saveXml();
  91. }
  92. /**
  93. * Get DOM document
  94. *
  95. * @return DOMDocument
  96. */
  97. public function getDomDocument()
  98. {
  99. return $this->_dom;
  100. }
  101. /**
  102. * Get document element from DOM
  103. *
  104. * @return DOMElement
  105. */
  106. public function getElement()
  107. {
  108. return $this->getDomDocument()->documentElement;
  109. }
  110. /**
  111. * Get data container of items being rendered
  112. *
  113. * @return mixed
  114. */
  115. public function getDataContainer()
  116. {
  117. return $this->_container;
  118. }
  119. /**
  120. * Set feed encoding
  121. *
  122. * @param string $enc
  123. * @return Zend_Feed_Writer_Renderer_RendererAbstract
  124. */
  125. public function setEncoding($enc)
  126. {
  127. $this->_encoding = $enc;
  128. return $this;
  129. }
  130. /**
  131. * Get feed encoding
  132. *
  133. * @return string
  134. */
  135. public function getEncoding()
  136. {
  137. return $this->_encoding;
  138. }
  139. /**
  140. * Indicate whether or not to ignore exceptions
  141. *
  142. * @param bool $bool
  143. * @return Zend_Feed_Writer_Renderer_RendererAbstract
  144. */
  145. public function ignoreExceptions($bool = true)
  146. {
  147. if (!is_bool($bool)) {
  148. #require_once 'Zend/Feed/Exception.php';
  149. throw new Zend_Feed_Exception('Invalid parameter: $bool. Should be TRUE or FALSE (defaults to TRUE if null)');
  150. }
  151. $this->_ignoreExceptions = $bool;
  152. return $this;
  153. }
  154. /**
  155. * Get exception list
  156. *
  157. * @return array
  158. */
  159. public function getExceptions()
  160. {
  161. return $this->_exceptions;
  162. }
  163. /**
  164. * Set the current feed type being exported to "rss" or "atom". This allows
  165. * other objects to gracefully choose whether to execute or not, depending
  166. * on their appropriateness for the current type, e.g. renderers.
  167. *
  168. * @param string $type
  169. */
  170. public function setType($type)
  171. {
  172. $this->_type = $type;
  173. }
  174. /**
  175. * Retrieve the current or last feed type exported.
  176. *
  177. * @return string Value will be "rss" or "atom"
  178. */
  179. public function getType()
  180. {
  181. return $this->_type;
  182. }
  183. /**
  184. * Sets the absolute root element for the XML feed being generated. This
  185. * helps simplify the appending of namespace declarations, but also ensures
  186. * namespaces are added to the root element - not scattered across the entire
  187. * XML file - may assist namespace unsafe parsers and looks pretty ;).
  188. *
  189. * @param DOMElement $root
  190. */
  191. public function setRootElement(DOMElement $root)
  192. {
  193. $this->_rootElement = $root;
  194. }
  195. /**
  196. * Retrieve the absolute root element for the XML feed being generated.
  197. *
  198. * @return DOMElement
  199. */
  200. public function getRootElement()
  201. {
  202. return $this->_rootElement;
  203. }
  204. /**
  205. * Load extensions from Zend_Feed_Writer
  206. *
  207. * @return void
  208. */
  209. protected function _loadExtensions()
  210. {
  211. Zend_Feed_Writer::registerCoreExtensions();
  212. $all = Zend_Feed_Writer::getExtensions();
  213. if (stripos(get_class($this), 'entry')) {
  214. $exts = $all['entryRenderer'];
  215. } else {
  216. $exts = $all['feedRenderer'];
  217. }
  218. foreach ($exts as $extension) {
  219. $className = Zend_Feed_Writer::getPluginLoader()->getClassName($extension);
  220. $this->_extensions[$extension] = new $className(
  221. $this->getDataContainer()
  222. );
  223. $this->_extensions[$extension]->setEncoding($this->getEncoding());
  224. }
  225. }
  226. }