You are here

abstract class AbstractEntry in Zircon Profile 8

Same name in this branch
  1. 8 vendor/zendframework/zend-feed/src/Reader/AbstractEntry.php \Zend\Feed\Reader\AbstractEntry
  2. 8 vendor/zendframework/zend-feed/src/Reader/Extension/AbstractEntry.php \Zend\Feed\Reader\Extension\AbstractEntry
  3. 8 vendor/zendframework/zend-feed/src/Reader/Entry/AbstractEntry.php \Zend\Feed\Reader\Entry\AbstractEntry
Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-feed/src/Reader/AbstractEntry.php \Zend\Feed\Reader\AbstractEntry

Hierarchy

Expanded class hierarchy of AbstractEntry

File

vendor/zendframework/zend-feed/src/Reader/AbstractEntry.php, line 16

Namespace

Zend\Feed\Reader
View source
abstract class AbstractEntry {

  /**
   * Feed entry data
   *
   * @var array
   */
  protected $data = [];

  /**
   * DOM document object
   *
   * @var DOMDocument
   */
  protected $domDocument = null;

  /**
   * Entry instance
   *
   * @var DOMElement
   */
  protected $entry = null;

  /**
   * Pointer to the current entry
   *
   * @var int
   */
  protected $entryKey = 0;

  /**
   * XPath object
   *
   * @var DOMXPath
   */
  protected $xpath = null;

  /**
   * Registered extensions
   *
   * @var array
   */
  protected $extensions = [];

  /**
   * Constructor
   *
   * @param  DOMElement $entry
   * @param  int $entryKey
   * @param  null|string $type
   */
  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;
    }
    else {
      $this->data['type'] = Reader::detectType($entry);
    }
    $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());
    $entry = $dom
      ->importNode($this
      ->getElement(), true);
    $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 \Zend\Feed\Reader\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 \Zend\Feed\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\BadMethodCallException 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\BadMethodCallException('Method: ' . $method . 'does not exist and could not be located on a registered Extension');
  }

  /**
   * Load extensions from Zend\Feed\Reader\Reader
   *
   * @return void
   */
  protected function _loadExtensions() {
    $all = Reader::getExtensions();
    $feed = $all['entry'];
    foreach ($feed as $extension) {
      if (in_array($extension, $all['core'])) {
        continue;
      }
      $className = Reader::getPluginLoader()
        ->getClassName($extension);
      $this->extensions[$extension] = new $className($this
        ->getElement(), $this->entryKey, $this->data['type']);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractEntry::$data protected property Feed entry data
AbstractEntry::$domDocument protected property DOM document object
AbstractEntry::$entry protected property Entry instance
AbstractEntry::$entryKey protected property Pointer to the current entry
AbstractEntry::$extensions protected property Registered extensions
AbstractEntry::$xpath protected property XPath object
AbstractEntry::getDomDocument public function Get the DOM
AbstractEntry::getElement public function Get the entry element
AbstractEntry::getEncoding public function Get the Entry's encoding
AbstractEntry::getExtension public function Return an Extension object with the matching name (postfixed with _Entry)
AbstractEntry::getExtensions public function Get registered extensions
AbstractEntry::getType public function Get the entry type
AbstractEntry::getXpath public function Get the XPath query object
AbstractEntry::saveXml public function Get entry as xml
AbstractEntry::setXpath public function Set the XPath query
AbstractEntry::_loadExtensions protected function Load extensions from Zend\Feed\Reader\Reader
AbstractEntry::__call public function Method overloading: call given method on first extension implementing it
AbstractEntry::__construct public function Constructor