Security update for Core, with self-updated composer
[yaffs-website] / vendor / zendframework / zend-feed / src / Writer / Renderer / AbstractRenderer.php
1 <?php
2 /**
3  * Zend Framework (http://framework.zend.com/)
4  *
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
8  */
9
10 namespace Zend\Feed\Writer\Renderer;
11
12 use DOMDocument;
13 use DOMElement;
14 use Zend\Feed\Writer;
15
16 /**
17 */
18 class AbstractRenderer
19 {
20     /**
21      * Extensions
22      * @var array
23      */
24     protected $extensions = [];
25
26     /**
27      * @var Writer\AbstractFeed
28      */
29     protected $container = null;
30
31     /**
32      * @var DOMDocument
33      */
34     protected $dom = null;
35
36     /**
37      * @var bool
38      */
39     protected $ignoreExceptions = false;
40
41     /**
42      * @var array
43      */
44     protected $exceptions = [];
45
46     /**
47      * Encoding of all text values
48      *
49      * @var string
50      */
51     protected $encoding = 'UTF-8';
52
53     /**
54      * Holds the value "atom" or "rss" depending on the feed type set when
55      * when last exported.
56      *
57      * @var string
58      */
59     protected $type = null;
60
61     /**
62      * @var DOMElement
63      */
64     protected $rootElement = null;
65
66     /**
67      * Constructor
68      *
69      * @param Writer\AbstractFeed $container
70      */
71     public function __construct($container)
72     {
73         $this->container = $container;
74         $this->setType($container->getType());
75         $this->_loadExtensions();
76     }
77
78     /**
79      * Save XML to string
80      *
81      * @return string
82      */
83     public function saveXml()
84     {
85         return $this->getDomDocument()->saveXML();
86     }
87
88     /**
89      * Get DOM document
90      *
91      * @return DOMDocument
92      */
93     public function getDomDocument()
94     {
95         return $this->dom;
96     }
97
98     /**
99      * Get document element from DOM
100      *
101      * @return DOMElement
102      */
103     public function getElement()
104     {
105         return $this->getDomDocument()->documentElement;
106     }
107
108     /**
109      * Get data container of items being rendered
110      *
111      * @return Writer\AbstractFeed
112      */
113     public function getDataContainer()
114     {
115         return $this->container;
116     }
117
118     /**
119      * Set feed encoding
120      *
121      * @param  string $enc
122      * @return AbstractRenderer
123      */
124     public function setEncoding($enc)
125     {
126         $this->encoding = $enc;
127         return $this;
128     }
129
130     /**
131      * Get feed encoding
132      *
133      * @return string
134      */
135     public function getEncoding()
136     {
137         return $this->encoding;
138     }
139
140     /**
141      * Indicate whether or not to ignore exceptions
142      *
143      * @param  bool $bool
144      * @return AbstractRenderer
145      * @throws Writer\Exception\InvalidArgumentException
146      */
147     public function ignoreExceptions($bool = true)
148     {
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)'
152             );
153         }
154         $this->ignoreExceptions = $bool;
155         return $this;
156     }
157
158     /**
159      * Get exception list
160      *
161      * @return array
162      */
163     public function getExceptions()
164     {
165         return $this->exceptions;
166     }
167
168     /**
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.
172      *
173      * @param string $type
174      */
175     public function setType($type)
176     {
177         $this->type = $type;
178     }
179
180     /**
181      * Retrieve the current or last feed type exported.
182      *
183      * @return string Value will be "rss" or "atom"
184      */
185     public function getType()
186     {
187         return $this->type;
188     }
189
190     /**
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 ;).
195      *
196      * @param DOMElement $root
197      */
198     public function setRootElement(DOMElement $root)
199     {
200         $this->rootElement = $root;
201     }
202
203     /**
204      * Retrieve the absolute root element for the XML feed being generated.
205      *
206      * @return DOMElement
207      */
208     public function getRootElement()
209     {
210         return $this->rootElement;
211     }
212
213     /**
214      * Load extensions from Zend\Feed\Writer\Writer
215      *
216      * @return void
217      */
218     // @codingStandardsIgnoreStart
219     protected function _loadExtensions()
220     {
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'];
227         } else {
228             $exts = $all['feedRenderer'];
229         }
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;
235         }
236     }
237 }