You are here

class PhpFileLibrary in Libraries API 8.3

Provides a base PHP file library implementation.

Hierarchy

Expanded class hierarchy of PhpFileLibrary

1 file declares its use of PhpFileLibrary
PhpFileLibraryType.php in src/Plugin/libraries/Type/PhpFileLibraryType.php

File

src/ExternalLibrary/PhpFile/PhpFileLibrary.php, line 14

Namespace

Drupal\libraries\ExternalLibrary\PhpFile
View source
class PhpFileLibrary extends LibraryBase implements PhpFileLibraryInterface {
  use LocalLibraryTrait;

  /**
   * An array of PHP files for this library.
   *
   * @var array
   */
  protected $files = [];

  /**
   * Constructs a PHP file 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) {
    parent::__construct($id, $definition, $type);
    $this->files = $definition['files'];
  }

  /**
   * {@inheritdoc}
   */
  protected static function processDefinition(array &$definition) {
    parent::processDefinition($definition);
    $definition += [
      'files' => [],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getPhpFiles() {
    if (!$this
      ->isInstalled()) {
      throw new LibraryNotInstalledException($this);
    }
    $processed_files = [];
    foreach ($this->files as $file) {
      $processed_files[] = $this
        ->getLocalPath() . '/' . $file;
    }
    return $processed_files;
  }

  /**
   * {@inheritdoc}
   */
  public function getLocator(FactoryInterface $locator_factory) {

    // @todo Consider refining the stream wrapper used here.
    return $locator_factory
      ->createInstance('uri', [
      'uri' => 'php-file://',
    ]);
  }

}

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
LocalLibraryTrait::$installed protected property Whether or not the library is installed.
LocalLibraryTrait::$localPath protected property The local path to the library relative to the app root.
LocalLibraryTrait::getLocalPath public function Gets the path to the library.
LocalLibraryTrait::isInstalled public function Checks whether the library is installed.
LocalLibraryTrait::setLocalPath public function Sets the library path of the library.
LocalLibraryTrait::setUninstalled public function Marks the library as uninstalled.
PhpFileLibrary::$files protected property An array of PHP files for this library.
PhpFileLibrary::getLocator public function Gets the locator of this library using the locator factory. Overrides LocalLibraryInterface::getLocator
PhpFileLibrary::getPhpFiles public function Returns the PHP files of this library. Overrides PhpFileLibraryInterface::getPhpFiles
PhpFileLibrary::processDefinition protected static function Gets library definition defaults. Overrides LibraryBase::processDefinition
PhpFileLibrary::__construct public function Constructs a PHP file library. Overrides LibraryBase::__construct
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.