You are here

class AbstractRenderer in Zircon Profile 8

Same name in this branch
  1. 8 vendor/zendframework/zend-feed/src/Writer/Extension/AbstractRenderer.php \Zend\Feed\Writer\Extension\AbstractRenderer
  2. 8 vendor/zendframework/zend-feed/src/Writer/Renderer/AbstractRenderer.php \Zend\Feed\Writer\Renderer\AbstractRenderer
Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-feed/src/Writer/Renderer/AbstractRenderer.php \Zend\Feed\Writer\Renderer\AbstractRenderer

Hierarchy

Expanded class hierarchy of AbstractRenderer

File

vendor/zendframework/zend-feed/src/Writer/Renderer/AbstractRenderer.php, line 18

Namespace

Zend\Feed\Writer\Renderer
View source
class AbstractRenderer {

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

  /**
   * @var Writer\AbstractFeed
   */
  protected $container = null;

  /**
   * @var DOMDocument
   */
  protected $dom = null;

  /**
   * @var bool
   */
  protected $ignoreExceptions = false;

  /**
   * @var array
   */
  protected $exceptions = [];

  /**
   * Encoding of all text values
   *
   * @var string
   */
  protected $encoding = 'UTF-8';

  /**
   * Holds the value "atom" or "rss" depending on the feed type set when
   * when last exported.
   *
   * @var string
   */
  protected $type = null;

  /**
   * @var DOMElement
   */
  protected $rootElement = null;

  /**
   * Constructor
   *
   * @param Writer\AbstractFeed $container
   */
  public function __construct($container) {
    $this->container = $container;
    $this
      ->setType($container
      ->getType());
    $this
      ->_loadExtensions();
  }

  /**
   * Save XML to string
   *
   * @return string
   */
  public function saveXml() {
    return $this
      ->getDomDocument()
      ->saveXml();
  }

  /**
   * Get DOM document
   *
   * @return DOMDocument
   */
  public function getDomDocument() {
    return $this->dom;
  }

  /**
   * Get document element from DOM
   *
   * @return DOMElement
   */
  public function getElement() {
    return $this
      ->getDomDocument()->documentElement;
  }

  /**
   * Get data container of items being rendered
   *
   * @return Writer\AbstractFeed
   */
  public function getDataContainer() {
    return $this->container;
  }

  /**
   * Set feed encoding
   *
   * @param  string $enc
   * @return AbstractRenderer
   */
  public function setEncoding($enc) {
    $this->encoding = $enc;
    return $this;
  }

  /**
   * Get feed encoding
   *
   * @return string
   */
  public function getEncoding() {
    return $this->encoding;
  }

  /**
   * Indicate whether or not to ignore exceptions
   *
   * @param  bool $bool
   * @return AbstractRenderer
   * @throws Writer\Exception\InvalidArgumentException
   */
  public function ignoreExceptions($bool = true) {
    if (!is_bool($bool)) {
      throw new Writer\Exception\InvalidArgumentException('Invalid parameter: $bool. Should be TRUE or FALSE (defaults to TRUE if null)');
    }
    $this->ignoreExceptions = $bool;
    return $this;
  }

  /**
   * Get exception list
   *
   * @return array
   */
  public function getExceptions() {
    return $this->exceptions;
  }

  /**
   * Set the current feed type being exported to "rss" or "atom". This allows
   * other objects to gracefully choose whether to execute or not, depending
   * on their appropriateness for the current type, e.g. renderers.
   *
   * @param string $type
   */
  public function setType($type) {
    $this->type = $type;
  }

  /**
   * Retrieve the current or last feed type exported.
   *
   * @return string Value will be "rss" or "atom"
   */
  public function getType() {
    return $this->type;
  }

  /**
   * Sets the absolute root element for the XML feed being generated. This
   * helps simplify the appending of namespace declarations, but also ensures
   * namespaces are added to the root element - not scattered across the entire
   * XML file - may assist namespace unsafe parsers and looks pretty ;).
   *
   * @param DOMElement $root
   */
  public function setRootElement(DOMElement $root) {
    $this->rootElement = $root;
  }

  /**
   * Retrieve the absolute root element for the XML feed being generated.
   *
   * @return DOMElement
   */
  public function getRootElement() {
    return $this->rootElement;
  }

  /**
   * Load extensions from Zend\Feed\Writer\Writer
   *
   * @return void
   */
  protected function _loadExtensions() {
    Writer\Writer::registerCoreExtensions();
    $manager = Writer\Writer::getExtensionManager();
    $all = Writer\Writer::getExtensions();
    if (stripos(get_class($this), 'entry')) {
      $exts = $all['entryRenderer'];
    }
    else {
      $exts = $all['feedRenderer'];
    }
    foreach ($exts as $extension) {
      $plugin = $manager
        ->get($extension);
      $plugin
        ->setDataContainer($this
        ->getDataContainer());
      $plugin
        ->setEncoding($this
        ->getEncoding());
      $this->extensions[$extension] = $plugin;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractRenderer::$container protected property
AbstractRenderer::$dom protected property
AbstractRenderer::$encoding protected property Encoding of all text values
AbstractRenderer::$exceptions protected property
AbstractRenderer::$extensions protected property Extensions
AbstractRenderer::$ignoreExceptions protected property
AbstractRenderer::$rootElement protected property
AbstractRenderer::$type protected property Holds the value "atom" or "rss" depending on the feed type set when when last exported.
AbstractRenderer::getDataContainer public function Get data container of items being rendered
AbstractRenderer::getDomDocument public function Get DOM document
AbstractRenderer::getElement public function Get document element from DOM
AbstractRenderer::getEncoding public function Get feed encoding
AbstractRenderer::getExceptions public function Get exception list
AbstractRenderer::getRootElement public function Retrieve the absolute root element for the XML feed being generated.
AbstractRenderer::getType public function Retrieve the current or last feed type exported.
AbstractRenderer::ignoreExceptions public function Indicate whether or not to ignore exceptions
AbstractRenderer::saveXml public function Save XML to string
AbstractRenderer::setEncoding public function Set feed encoding
AbstractRenderer::setRootElement public function Sets the absolute root element for the XML feed being generated. This helps simplify the appending of namespace declarations, but also ensures namespaces are added to the root element - not scattered across the entire XML file - may assist namespace…
AbstractRenderer::setType public function Set the current feed type being exported to "rss" or "atom". This allows other objects to gracefully choose whether to execute or not, depending on their appropriateness for the current type, e.g. renderers.
AbstractRenderer::_loadExtensions protected function Load extensions from Zend\Feed\Writer\Writer
AbstractRenderer::__construct public function Constructor