Further modules included.
[yaffs-website] / web / modules / contrib / libraries / src / ExternalLibrary / PhpFile / PhpFileLibrary.php
1 <?php
2
3 namespace Drupal\libraries\ExternalLibrary\PhpFile;
4
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;
10
11 /**
12  * Provides a base PHP file library implementation.
13  */
14 class PhpFileLibrary extends LibraryBase implements PhpFileLibraryInterface {
15
16   use LocalLibraryTrait;
17
18   /**
19    * An array of PHP files for this library.
20    *
21    * @var array
22    */
23   protected $files = [];
24
25   /**
26    * Constructs a PHP file library.
27    *
28    * @param string $id
29    *   The library ID.
30    * @param array $definition
31    *   The library definition array.
32    * @param \Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface $type
33    *   The library type of this library.
34    */
35   public function __construct($id, array $definition, LibraryTypeInterface $type) {
36     parent::__construct($id, $definition, $type);
37     $this->files = $definition['files'];
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   protected static function processDefinition(array &$definition) {
44     parent::processDefinition($definition);
45     $definition += [
46       'files' => [],
47     ];
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public function getPhpFiles() {
54     if (!$this->isInstalled()) {
55       throw new LibraryNotInstalledException($this);
56     }
57
58     $processed_files = [];
59     foreach ($this->files as $file) {
60       $processed_files[] = $this->getLocalPath() . '/' . $file;
61     }
62     return $processed_files;
63   }
64
65   /**
66    * {@inheritdoc}
67    */
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://']);
71   }
72
73 }