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;
16 abstract class AbstractEntry
30 protected $domDocument = null;
37 protected $entry = null;
40 * Pointer to the current entry
44 protected $entryKey = 0;
51 protected $xpath = null;
54 * Registered extensions
58 protected $extensions = [];
63 * @param DOMElement $entry
64 * @param int $entryKey
65 * @param null|string $type
67 public function __construct(DOMElement $entry, $entryKey, $type = null)
69 $this->entry = $entry;
70 $this->entryKey = $entryKey;
71 $this->domDocument = $entry->ownerDocument;
73 $this->data['type'] = $type;
75 $this->data['type'] = Reader::detectType($entry);
77 $this->_loadExtensions();
85 public function getDomDocument()
87 return $this->domDocument;
91 * Get the entry element
95 public function getElement()
101 * Get the Entry's encoding
105 public function getEncoding()
107 $assumed = $this->getDomDocument()->encoding;
108 if (empty($assumed)) {
119 public function saveXml()
121 $dom = new DOMDocument('1.0', $this->getEncoding());
122 $entry = $dom->importNode($this->getElement(), true);
123 $dom->appendChild($entry);
124 return $dom->saveXML();
132 public function getType()
134 return $this->data['type'];
138 * Get the XPath query object
142 public function getXpath()
144 if (! $this->xpath) {
145 $this->setXpath(new DOMXPath($this->getDomDocument()));
151 * Set the XPath query
153 * @param DOMXPath $xpath
154 * @return \Zend\Feed\Reader\AbstractEntry
156 public function setXpath(DOMXPath $xpath)
158 $this->xpath = $xpath;
163 * Get registered extensions
167 public function getExtensions()
169 return $this->extensions;
173 * Return an Extension object with the matching name (postfixed with _Entry)
175 * @param string $name
176 * @return \Zend\Feed\Reader\Extension\AbstractEntry
178 public function getExtension($name)
180 if (array_key_exists($name . '\Entry', $this->extensions)) {
181 return $this->extensions[$name . '\Entry'];
187 * Method overloading: call given method on first extension implementing it
189 * @param string $method
192 * @throws Exception\BadMethodCallException if no extensions implements the method
194 public function __call($method, $args)
196 foreach ($this->extensions as $extension) {
197 if (method_exists($extension, $method)) {
198 return call_user_func_array([$extension, $method], $args);
201 throw new Exception\BadMethodCallException('Method: ' . $method
202 . 'does not exist and could not be located on a registered Extension');
206 * Load extensions from Zend\Feed\Reader\Reader
210 // @codingStandardsIgnoreStart
211 protected function _loadExtensions()
213 // @codingStandardsIgnoreEnd
214 $all = Reader::getExtensions();
215 $feed = $all['entry'];
216 foreach ($feed as $extension) {
217 if (in_array($extension, $all['core'])) {
220 $className = Reader::getPluginLoader()->getClassName($extension);
221 $this->extensions[$extension] = new $className(
222 $this->getElement(), $this->entryKey, $this->data['type']