3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Feed\Writer\Renderer;
18 class AbstractRenderer
24 protected $extensions = [];
27 * @var Writer\AbstractFeed
29 protected $container = null;
34 protected $dom = null;
39 protected $ignoreExceptions = false;
44 protected $exceptions = [];
47 * Encoding of all text values
51 protected $encoding = 'UTF-8';
54 * Holds the value "atom" or "rss" depending on the feed type set when
59 protected $type = null;
64 protected $rootElement = null;
69 * @param Writer\AbstractFeed $container
71 public function __construct($container)
73 $this->container = $container;
74 $this->setType($container->getType());
75 $this->_loadExtensions();
83 public function saveXml()
85 return $this->getDomDocument()->saveXML();
93 public function getDomDocument()
99 * Get document element from DOM
103 public function getElement()
105 return $this->getDomDocument()->documentElement;
109 * Get data container of items being rendered
111 * @return Writer\AbstractFeed
113 public function getDataContainer()
115 return $this->container;
122 * @return AbstractRenderer
124 public function setEncoding($enc)
126 $this->encoding = $enc;
135 public function getEncoding()
137 return $this->encoding;
141 * Indicate whether or not to ignore exceptions
144 * @return AbstractRenderer
145 * @throws Writer\Exception\InvalidArgumentException
147 public function ignoreExceptions($bool = true)
149 if (! is_bool($bool)) {
150 throw new Writer\Exception\InvalidArgumentException(
151 'Invalid parameter: $bool. Should be TRUE or FALSE (defaults to TRUE if null)'
154 $this->ignoreExceptions = $bool;
163 public function getExceptions()
165 return $this->exceptions;
169 * Set the current feed type being exported to "rss" or "atom". This allows
170 * other objects to gracefully choose whether to execute or not, depending
171 * on their appropriateness for the current type, e.g. renderers.
173 * @param string $type
175 public function setType($type)
181 * Retrieve the current or last feed type exported.
183 * @return string Value will be "rss" or "atom"
185 public function getType()
191 * Sets the absolute root element for the XML feed being generated. This
192 * helps simplify the appending of namespace declarations, but also ensures
193 * namespaces are added to the root element - not scattered across the entire
194 * XML file - may assist namespace unsafe parsers and looks pretty ;).
196 * @param DOMElement $root
198 public function setRootElement(DOMElement $root)
200 $this->rootElement = $root;
204 * Retrieve the absolute root element for the XML feed being generated.
208 public function getRootElement()
210 return $this->rootElement;
214 * Load extensions from Zend\Feed\Writer\Writer
218 // @codingStandardsIgnoreStart
219 protected function _loadExtensions()
221 // @codingStandardsIgnoreEnd
222 Writer\Writer::registerCoreExtensions();
223 $manager = Writer\Writer::getExtensionManager();
224 $all = Writer\Writer::getExtensions();
225 if (stripos(get_class($this), 'entry')) {
226 $exts = $all['entryRenderer'];
228 $exts = $all['feedRenderer'];
230 foreach ($exts as $extension) {
231 $plugin = $manager->get($extension);
232 $plugin->setDataContainer($this->getDataContainer());
233 $plugin->setEncoding($this->getEncoding());
234 $this->extensions[$extension] = $plugin;