AbstractEntry.php in Zircon Profile 8.0
File
vendor/zendframework/zend-feed/src/Reader/Entry/AbstractEntry.php
View source
<?php
namespace Zend\Feed\Reader\Entry;
use DOMDocument;
use DOMElement;
use DOMXPath;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Exception;
abstract class AbstractEntry {
protected $data = [];
protected $domDocument = null;
protected $entry = null;
protected $entryKey = 0;
protected $xpath = null;
protected $extensions = [];
public function __construct(DOMElement $entry, $entryKey, $type = null) {
$this->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();
}
public function getDomDocument() {
return $this->domDocument;
}
public function getElement() {
return $this->entry;
}
public function getEncoding() {
$assumed = $this
->getDomDocument()->encoding;
if (empty($assumed)) {
$assumed = 'UTF-8';
}
return $assumed;
}
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();
}
public function getType() {
return $this->data['type'];
}
public function getXpath() {
if (!$this->xpath) {
$this
->setXpath(new DOMXPath($this
->getDomDocument()));
}
return $this->xpath;
}
public function setXpath(DOMXPath $xpath) {
$this->xpath = $xpath;
return $this;
}
public function getExtensions() {
return $this->extensions;
}
public function getExtension($name) {
if (array_key_exists($name . '\\Entry', $this->extensions)) {
return $this->extensions[$name . '\\Entry'];
}
return;
}
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));
}
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;
}
}
}