You are here

abstract class LibraryBase in Libraries API 8.3

Provides a base external library implementation.

Hierarchy

Expanded class hierarchy of LibraryBase

3 files declare their use of LibraryBase
AssetLibrary.php in src/ExternalLibrary/Asset/AssetLibrary.php
MultipleAssetLibrary.php in src/ExternalLibrary/Asset/MultipleAssetLibrary.php
PhpFileLibrary.php in src/ExternalLibrary/PhpFile/PhpFileLibrary.php

File

src/ExternalLibrary/LibraryBase.php, line 15

Namespace

Drupal\libraries\ExternalLibrary
View source
abstract class LibraryBase implements LibraryInterface, DependentLibraryInterface, VersionedLibraryInterface {
  use IdAccessorTrait, DependentLibraryTrait, VersionedLibraryTrait;

  /**
   * The library type of this library.
   *
   * @var \Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface
   */
  protected $type;

  /**
   * Constructs a library.
   *
   * @param string $id
   *   The library ID.
   * @param array $definition
   *   The library definition array.
   * @param \Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface $type
   *   The library type of this library.
   */
  public function __construct($id, array $definition, LibraryTypeInterface $type) {
    $this->id = (string) $id;
    $this->type = $type;
    $this->dependencies = $definition['dependencies'];
    $this->versionDetector = $definition['version_detector'];
  }

  /**
   * {@inheritdoc}
   */
  public static function create($id, array $definition, LibraryTypeInterface $type) {
    static::processDefinition($definition);
    return new static($id, $definition, $type);
  }

  /**
   * Gets library definition defaults.
   *
   * @param array $definition
   *   A library definition array.
   */
  protected static function processDefinition(array &$definition) {
    $definition += [
      'dependencies' => [],
      // @todo This fallback is not very elegant.
      'version_detector' => [
        'id' => 'static',
        'configuration' => [
          'version' => '',
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getType() {
    return $this->type;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependentLibraryInterface::getDependencies public function Returns the libraries dependencies, if any.
IdAccessorTrait::$id protected property The ID.
IdAccessorTrait::getId public function Returns the ID.
LibraryBase::$type protected property The library type of this library.
LibraryBase::create public static function Creates an instance of the library from its definition. Overrides LibraryInterface::create
LibraryBase::getType public function Returns the library type of the library. Overrides LibraryInterface::getType
LibraryBase::processDefinition protected static function Gets library definition defaults. 3
LibraryBase::__construct public function Constructs a library. 3
VersionedLibraryInterface::getVersion public function Gets the version of the library.
VersionedLibraryInterface::getVersionDetector public function Gets the version detector of this library using the detector factory.
VersionedLibraryInterface::setVersion public function Sets the version of the library.