AbstractFeed.php in Zircon Profile 8.0
File
vendor/zendframework/zend-feed/src/Reader/Feed/AbstractFeed.php
View source
<?php
namespace Zend\Feed\Reader\Feed;
use DOMDocument;
use DOMElement;
use DOMXPath;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Exception;
abstract class AbstractFeed implements FeedInterface {
protected $data = [];
protected $domDocument = null;
protected $entries = [];
protected $entriesKey = 0;
protected $xpath = null;
protected $extensions = [];
protected $originalSourceUri = null;
public function __construct(DOMDocument $domDocument, $type = null) {
$this->domDocument = $domDocument;
$this->xpath = new DOMXPath($this->domDocument);
if ($type !== null) {
$this->data['type'] = $type;
}
else {
$this->data['type'] = Reader\Reader::detectType($this->domDocument);
}
$this
->registerNamespaces();
$this
->indexEntries();
$this
->loadExtensions();
}
public function setOriginalSourceUri($uri) {
$this->originalSourceUri = $uri;
}
public function getOriginalSourceUri() {
return $this->originalSourceUri;
}
public function count() {
return count($this->entries);
}
public function current() {
if (substr($this
->getType(), 0, 3) == 'rss') {
$reader = new Reader\Entry\Rss($this->entries[$this
->key()], $this
->key(), $this
->getType());
}
else {
$reader = new Reader\Entry\Atom($this->entries[$this
->key()], $this
->key(), $this
->getType());
}
$reader
->setXpath($this->xpath);
return $reader;
}
public function getDomDocument() {
return $this->domDocument;
}
public function getEncoding() {
$assumed = $this
->getDomDocument()->encoding;
if (empty($assumed)) {
$assumed = 'UTF-8';
}
return $assumed;
}
public function saveXml() {
return $this
->getDomDocument()
->saveXml();
}
public function getElement() {
return $this
->getDomDocument()->documentElement;
}
public function getXpath() {
return $this->xpath;
}
public function getType() {
return $this->data['type'];
}
public function key() {
return $this->entriesKey;
}
public function next() {
++$this->entriesKey;
}
public function rewind() {
$this->entriesKey = 0;
}
public function valid() {
return 0 <= $this->entriesKey && $this->entriesKey < $this
->count();
}
public function getExtensions() {
return $this->extensions;
}
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\BadMethodCallException('Method: ' . $method . 'does not exist and could not be located on a registered Extension');
}
public function getExtension($name) {
if (array_key_exists($name . '\\Feed', $this->extensions)) {
return $this->extensions[$name . '\\Feed'];
}
return;
}
protected function loadExtensions() {
$all = Reader\Reader::getExtensions();
$manager = Reader\Reader::getExtensionManager();
$feed = $all['feed'];
foreach ($feed as $extension) {
if (in_array($extension, $all['core'])) {
continue;
}
if (!$manager
->has($extension)) {
throw new Exception\RuntimeException(sprintf('Unable to load extension "%s"; cannot find class', $extension));
}
$plugin = $manager
->get($extension);
$plugin
->setDomDocument($this
->getDomDocument());
$plugin
->setType($this->data['type']);
$plugin
->setXpath($this->xpath);
$this->extensions[$extension] = $plugin;
}
}
protected abstract function indexEntries();
protected abstract function registerNamespaces();
}