db backup prior to drupal security update
[yaffs-website] / vendor / zendframework / zend-feed / src / Reader / Extension / AbstractEntry.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\Reader\Extension;
11
12 use DOMDocument;
13 use DOMElement;
14 use DOMXPath;
15 use Zend\Feed\Reader;
16
17 abstract class AbstractEntry
18 {
19     /**
20      * Feed entry data
21      *
22      * @var array
23      */
24     protected $data = [];
25
26     /**
27      * DOM document object
28      *
29      * @var DOMDocument
30      */
31     protected $domDocument = null;
32
33     /**
34      * Entry instance
35      *
36      * @var DOMElement
37      */
38     protected $entry = null;
39
40     /**
41      * Pointer to the current entry
42      *
43      * @var int
44      */
45     protected $entryKey = 0;
46
47     /**
48      * XPath object
49      *
50      * @var DOMXPath
51      */
52     protected $xpath = null;
53
54     /**
55      * XPath query
56      *
57      * @var string
58      */
59     protected $xpathPrefix = '';
60
61     /**
62      * Set the entry DOMElement
63      *
64      * Has side effect of setting the DOMDocument for the entry.
65      *
66      * @param  DOMElement $entry
67      * @return AbstractEntry
68      */
69     public function setEntryElement(DOMElement $entry)
70     {
71         $this->entry = $entry;
72         $this->domDocument = $entry->ownerDocument;
73         return $this;
74     }
75
76     /**
77      * Get the entry DOMElement
78      *
79      * @return DOMElement
80      */
81     public function getEntryElement()
82     {
83         return $this->entry;
84     }
85
86     /**
87      * Set the entry key
88      *
89      * @param  string $entryKey
90      * @return AbstractEntry
91      */
92     public function setEntryKey($entryKey)
93     {
94         $this->entryKey = $entryKey;
95         return $this;
96     }
97
98     /**
99      * Get the DOM
100      *
101      * @return DOMDocument
102      */
103     public function getDomDocument()
104     {
105         return $this->domDocument;
106     }
107
108     /**
109      * Get the Entry's encoding
110      *
111      * @return string
112      */
113     public function getEncoding()
114     {
115         $assumed = $this->getDomDocument()->encoding;
116         return $assumed;
117     }
118
119     /**
120      * Set the entry type
121      *
122      * Has side effect of setting xpath prefix
123      *
124      * @param  string $type
125      * @return AbstractEntry
126      */
127     public function setType($type)
128     {
129         if (null === $type) {
130             $this->data['type'] = null;
131             return $this;
132         }
133
134         $this->data['type'] = $type;
135         if ($type === Reader\Reader::TYPE_RSS_10
136             || $type === Reader\Reader::TYPE_RSS_090
137         ) {
138             $this->setXpathPrefix('//rss:item[' . ((int)$this->entryKey + 1) . ']');
139             return $this;
140         }
141
142         if ($type === Reader\Reader::TYPE_ATOM_10
143             || $type === Reader\Reader::TYPE_ATOM_03
144         ) {
145             $this->setXpathPrefix('//atom:entry[' . ((int)$this->entryKey + 1) . ']');
146             return $this;
147         }
148
149         $this->setXpathPrefix('//item[' . ((int)$this->entryKey + 1) . ']');
150         return $this;
151     }
152
153     /**
154      * Get the entry type
155      *
156      * @return string
157      */
158     public function getType()
159     {
160         $type = $this->data['type'];
161         if ($type === null) {
162             $type = Reader\Reader::detectType($this->getEntryElement(), true);
163             $this->setType($type);
164         }
165
166         return $type;
167     }
168
169     /**
170      * Set the XPath query
171      *
172      * @param  DOMXPath $xpath
173      * @return AbstractEntry
174      */
175     public function setXpath(DOMXPath $xpath)
176     {
177         $this->xpath = $xpath;
178         $this->registerNamespaces();
179         return $this;
180     }
181
182     /**
183      * Get the XPath query object
184      *
185      * @return DOMXPath
186      */
187     public function getXpath()
188     {
189         if (! $this->xpath) {
190             $this->setXpath(new DOMXPath($this->getDomDocument()));
191         }
192         return $this->xpath;
193     }
194
195     /**
196      * Serialize the entry to an array
197      *
198      * @return array
199      */
200     public function toArray()
201     {
202         return $this->data;
203     }
204
205     /**
206      * Get the XPath prefix
207      *
208      * @return string
209      */
210     public function getXpathPrefix()
211     {
212         return $this->xpathPrefix;
213     }
214
215     /**
216      * Set the XPath prefix
217      *
218      * @param  string $prefix
219      * @return AbstractEntry
220      */
221     public function setXpathPrefix($prefix)
222     {
223         $this->xpathPrefix = $prefix;
224         return $this;
225     }
226
227     /**
228      * Register XML namespaces
229      *
230      * @return void
231      */
232     abstract protected function registerNamespaces();
233 }