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\Reader\Extension;
17 abstract class AbstractEntry
31 protected $domDocument = null;
38 protected $entry = null;
41 * Pointer to the current entry
45 protected $entryKey = 0;
52 protected $xpath = null;
59 protected $xpathPrefix = '';
62 * Set the entry DOMElement
64 * Has side effect of setting the DOMDocument for the entry.
66 * @param DOMElement $entry
67 * @return AbstractEntry
69 public function setEntryElement(DOMElement $entry)
71 $this->entry = $entry;
72 $this->domDocument = $entry->ownerDocument;
77 * Get the entry DOMElement
81 public function getEntryElement()
89 * @param string $entryKey
90 * @return AbstractEntry
92 public function setEntryKey($entryKey)
94 $this->entryKey = $entryKey;
101 * @return DOMDocument
103 public function getDomDocument()
105 return $this->domDocument;
109 * Get the Entry's encoding
113 public function getEncoding()
115 $assumed = $this->getDomDocument()->encoding;
122 * Has side effect of setting xpath prefix
124 * @param string $type
125 * @return AbstractEntry
127 public function setType($type)
129 if (null === $type) {
130 $this->data['type'] = null;
134 $this->data['type'] = $type;
135 if ($type === Reader\Reader::TYPE_RSS_10
136 || $type === Reader\Reader::TYPE_RSS_090
138 $this->setXpathPrefix('//rss:item[' . ((int)$this->entryKey + 1) . ']');
142 if ($type === Reader\Reader::TYPE_ATOM_10
143 || $type === Reader\Reader::TYPE_ATOM_03
145 $this->setXpathPrefix('//atom:entry[' . ((int)$this->entryKey + 1) . ']');
149 $this->setXpathPrefix('//item[' . ((int)$this->entryKey + 1) . ']');
158 public function getType()
160 $type = $this->data['type'];
161 if ($type === null) {
162 $type = Reader\Reader::detectType($this->getEntryElement(), true);
163 $this->setType($type);
170 * Set the XPath query
172 * @param DOMXPath $xpath
173 * @return AbstractEntry
175 public function setXpath(DOMXPath $xpath)
177 $this->xpath = $xpath;
178 $this->registerNamespaces();
183 * Get the XPath query object
187 public function getXpath()
189 if (! $this->xpath) {
190 $this->setXpath(new DOMXPath($this->getDomDocument()));
196 * Serialize the entry to an array
200 public function toArray()
206 * Get the XPath prefix
210 public function getXpathPrefix()
212 return $this->xpathPrefix;
216 * Set the XPath prefix
218 * @param string $prefix
219 * @return AbstractEntry
221 public function setXpathPrefix($prefix)
223 $this->xpathPrefix = $prefix;
228 * Register XML namespaces
232 abstract protected function registerNamespaces();