You are here

class DocManager in Forena Reports 8

Implements \Drupal\forena\DocManager @package Drupal\forena

Hierarchy

Expanded class hierarchy of DocManager

9 files declare their use of DocManager
CSVTest.php in tests/src/Unit/Document/CSVTest.php
DocumentConfigForm.php in src/Form/DocumentConfigForm.php
DrupalTest.php in tests/src/Unit/Document/DrupalTest.php
EmailMerge.php in src/FrxPlugin/Document/EmailMerge.php
EmailMergeForm.php in src/Form/EmailMergeForm.php

... See full list

File

src/DocManager.php, line 15

Namespace

Drupal\forena
View source
class DocManager {
  private static $instance;
  private $writers = [];
  private $type;

  /** @var array  */
  protected $docTypes;

  /**
   * @return \Drupal\forena\DocManager
   */
  public static function instance() {
    if (static::$instance === null) {
      static::$instance = new static();
    }
    return static::$instance;
  }

  /**
   * Initilaize Document Manager
   */
  public function __construct() {

    // Determine plugins

    /** @var \Drupal\forena\FrxDocumentPluginManager $pm */
    $this->docTypes = AppService::instance()
      ->getDocumentPlugins();
    $this
      ->setDocument('drupal');
  }

  /**
   * @param string $type
   *   Document type
   * @return \Drupal\forena\FrxPlugin\Document\DocumentInterface
   *   Generated class
   */
  public function setDocument($type = '') {
    if (!$type) {
      $type = 'drupal';
    }
    if (!isset($this->writers[$type])) {
      $class = $this->docTypes[$type];
      $this->writers[$type] = new $class();
    }
    $this->type = $type;
    return $this->writers[$this->type];
  }

  /**
   * Gets current document.
   * @return \Drupal\forena\FrxPlugin\Document\DocumentBase
   */
  public function getDocument() {
    return $this->writers[$this->type];
  }

  /**
   * @return string
   *   Document type of current document.
   */
  public function getDocumentType() {
    return $this->type;
  }

  /**
   * Return a list of document types.
   * @return array
   *   List of doctype extensions possible.
   */
  public function getDocTypes() {
    return array_keys($this->docTypes);
  }

  /**
   * @param string $base_name
   *   Name of file to set.
   */
  public function setFilename($base_name) {
    $ext = $this
      ->getDocumentType();
    $this
      ->getDocument()
      ->setFilename("{$base_name}.{$ext}");
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DocManager::$docTypes protected property @var array
DocManager::$instance private static property
DocManager::$type private property
DocManager::$writers private property
DocManager::getDocTypes public function Return a list of document types.
DocManager::getDocument public function Gets current document.
DocManager::getDocumentType public function
DocManager::instance public static function
DocManager::setDocument public function
DocManager::setFilename public function
DocManager::__construct public function Initilaize Document Manager