3 namespace Drupal\libraries\ExternalLibrary\PhpFile;
5 use Drupal\Component\Plugin\Factory\FactoryInterface;
6 use Drupal\libraries\ExternalLibrary\Exception\LibraryNotInstalledException;
7 use Drupal\libraries\ExternalLibrary\LibraryBase;
8 use Drupal\libraries\ExternalLibrary\Local\LocalLibraryTrait;
9 use Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface;
12 * Provides a base PHP file library implementation.
14 class PhpFileLibrary extends LibraryBase implements PhpFileLibraryInterface {
16 use LocalLibraryTrait;
19 * An array of PHP files for this library.
23 protected $files = [];
26 * Constructs a PHP file library.
30 * @param array $definition
31 * The library definition array.
32 * @param \Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface $type
33 * The library type of this library.
35 public function __construct($id, array $definition, LibraryTypeInterface $type) {
36 parent::__construct($id, $definition, $type);
37 $this->files = $definition['files'];
43 protected static function processDefinition(array &$definition) {
44 parent::processDefinition($definition);
53 public function getPhpFiles() {
54 if (!$this->isInstalled()) {
55 throw new LibraryNotInstalledException($this);
58 $processed_files = [];
59 foreach ($this->files as $file) {
60 $processed_files[] = $this->getLocalPath() . '/' . $file;
62 return $processed_files;
68 public function getLocator(FactoryInterface $locator_factory) {
69 // @todo Consider refining the stream wrapper used here.
70 return $locator_factory->createInstance('uri', ['uri' => 'php-file://']);