X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fzendframework%2Fzend-feed%2Fsrc%2FReader%2FEntry%2FAbstractEntry.php;fp=vendor%2Fzendframework%2Fzend-feed%2Fsrc%2FReader%2FEntry%2FAbstractEntry.php;h=f05803f0f5f78577cd72567bc89e5c6a93ffbac9;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/zendframework/zend-feed/src/Reader/Entry/AbstractEntry.php b/vendor/zendframework/zend-feed/src/Reader/Entry/AbstractEntry.php new file mode 100644 index 000000000..f05803f0f --- /dev/null +++ b/vendor/zendframework/zend-feed/src/Reader/Entry/AbstractEntry.php @@ -0,0 +1,233 @@ +entry = $entry; + $this->entryKey = $entryKey; + $this->domDocument = $entry->ownerDocument; + if ($type !== null) { + $this->data['type'] = $type; + } elseif ($this->domDocument !== null) { + $this->data['type'] = Reader\Reader::detectType($this->domDocument); + } else { + $this->data['type'] = Reader\Reader::TYPE_ANY; + } + $this->loadExtensions(); + } + + /** + * Get the DOM + * + * @return DOMDocument + */ + public function getDomDocument() + { + return $this->domDocument; + } + + /** + * Get the entry element + * + * @return DOMElement + */ + public function getElement() + { + return $this->entry; + } + + /** + * Get the Entry's encoding + * + * @return string + */ + public function getEncoding() + { + $assumed = $this->getDomDocument()->encoding; + if (empty($assumed)) { + $assumed = 'UTF-8'; + } + return $assumed; + } + + /** + * Get entry as xml + * + * @return string + */ + public function saveXml() + { + $dom = new DOMDocument('1.0', $this->getEncoding()); + $deep = version_compare(PHP_VERSION, '7', 'ge') ? 1 : true; + $entry = $dom->importNode($this->getElement(), $deep); + $dom->appendChild($entry); + return $dom->saveXml(); + } + + /** + * Get the entry type + * + * @return string + */ + public function getType() + { + return $this->data['type']; + } + + /** + * Get the XPath query object + * + * @return DOMXPath + */ + public function getXpath() + { + if (! $this->xpath) { + $this->setXpath(new DOMXPath($this->getDomDocument())); + } + return $this->xpath; + } + + /** + * Set the XPath query + * + * @param DOMXPath $xpath + * @return AbstractEntry + */ + public function setXpath(DOMXPath $xpath) + { + $this->xpath = $xpath; + return $this; + } + + /** + * Get registered extensions + * + * @return array + */ + public function getExtensions() + { + return $this->extensions; + } + + /** + * Return an Extension object with the matching name (postfixed with _Entry) + * + * @param string $name + * @return Reader\Extension\AbstractEntry + */ + public function getExtension($name) + { + if (array_key_exists($name . '\\Entry', $this->extensions)) { + return $this->extensions[$name . '\\Entry']; + } + return; + } + + /** + * Method overloading: call given method on first extension implementing it + * + * @param string $method + * @param array $args + * @return mixed + * @throws Exception\RuntimeException if no extensions implements the method + */ + public function __call($method, $args) + { + foreach ($this->extensions as $extension) { + if (method_exists($extension, $method)) { + return call_user_func_array([$extension, $method], $args); + } + } + throw new Exception\RuntimeException(sprintf( + 'Method: %s does not exist and could not be located on a registered Extension', + $method + )); + } + + /** + * Load extensions from Zend\Feed\Reader\Reader + * + * @return void + */ + protected function loadExtensions() + { + $all = Reader\Reader::getExtensions(); + $manager = Reader\Reader::getExtensionManager(); + $feed = $all['entry']; + foreach ($feed as $extension) { + if (in_array($extension, $all['core'])) { + continue; + } + $plugin = $manager->get($extension); + $plugin->setEntryElement($this->getElement()); + $plugin->setEntryKey($this->entryKey); + $plugin->setType($this->data['type']); + $this->extensions[$extension] = $plugin; + } + } +}