You are here

class Csl in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x src/Csl.php \Drupal\bibcite\Csl

Simple wrapper for CSL XML.

Hierarchy

  • class \Drupal\bibcite\Csl

Expanded class hierarchy of Csl

3 files declare their use of Csl
CslStyle.php in src/Entity/CslStyle.php
CslStyleFileForm.php in src/Form/CslStyleFileForm.php
CslStyleForm.php in src/Form/CslStyleForm.php

File

src/Csl.php, line 8

Namespace

Drupal\bibcite
View source
class Csl {

  /**
   * CSL content.
   *
   * @var \SimpleXMLElement
   */
  protected $xml;

  /**
   * Csl constructor.
   *
   * @param string $csl_content
   *   CSL content.
   */
  public function __construct($csl_content) {
    $this->xml = simplexml_load_string($csl_content);
  }

  /**
   * Return XML string.
   *
   * @return string
   *   XML content as string.
   */
  public function __toString() {
    return (string) $this->xml
      ->asXML();
  }

  /**
   * Get CSL style identifier.
   *
   * @return string
   *   Identifier of the style
   */
  public function getId() {
    return (string) $this->xml->info->id;
  }

  /**
   * Get CSL style title.
   *
   * @return string
   *   Title of the style.
   */
  public function getTitle() {
    return (string) $this->xml->info->title;
  }

  /**
   * Get parent style identifier.
   *
   * @return null|string
   *   Identifier of the parent style or NULL.
   */
  public function getParent() {

    /** @var \SimpleXMLElement $link */
    foreach ($this->xml->info->link as $link) {
      $attributes = $link
        ->attributes();
      if (isset($attributes->rel, $attributes->href) && (string) $attributes->rel === 'independent-parent') {
        return (string) $attributes->href;
      }
    }
    return NULL;
  }

  /**
   * Validate CSL style.
   *
   * @todo This is a very simple XML validation. Need to be replaced by some CSL validation mechanism.
   *
   * @return bool
   *   TRUE if provided CSL is valid, FALSE if not.
   */
  public function validate() {
    return (bool) $this->xml;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Csl::$xml protected property CSL content.
Csl::getId public function Get CSL style identifier.
Csl::getParent public function Get parent style identifier.
Csl::getTitle public function Get CSL style title.
Csl::validate public function Validate CSL style.
Csl::__construct public function Csl constructor.
Csl::__toString public function Return XML string.