Further modules included.
[yaffs-website] / web / modules / contrib / libraries / src / ExternalLibrary / LibraryBase.php
1 <?php
2
3 namespace Drupal\libraries\ExternalLibrary;
4
5 use Drupal\libraries\ExternalLibrary\Dependency\DependentLibraryInterface;
6 use Drupal\libraries\ExternalLibrary\Dependency\DependentLibraryTrait;
7 use Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface;
8 use Drupal\libraries\ExternalLibrary\Utility\IdAccessorTrait;
9 use Drupal\libraries\ExternalLibrary\Version\VersionedLibraryInterface;
10 use Drupal\libraries\ExternalLibrary\Version\VersionedLibraryTrait;
11
12 /**
13  * Provides a base external library implementation.
14  */
15 abstract class LibraryBase implements
16   LibraryInterface,
17   DependentLibraryInterface,
18   VersionedLibraryInterface
19 {
20
21   use
22     IdAccessorTrait,
23     DependentLibraryTrait,
24     VersionedLibraryTrait
25   ;
26
27   /**
28    * The library type of this library.
29    *
30    * @var \Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface
31    */
32   protected $type;
33
34   /**
35    * Constructs a library.
36    *
37    * @param string $id
38    *   The library ID.
39    * @param array $definition
40    *   The library definition array.
41    * @param \Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface $type
42    *   The library type of this library.
43    */
44   public function __construct($id, array $definition, LibraryTypeInterface $type) {
45     $this->id = (string) $id;
46     $this->type = $type;
47     $this->dependencies = $definition['dependencies'];
48     $this->versionDetector = $definition['version_detector'];
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public static function create($id, array $definition, LibraryTypeInterface $type) {
55     static::processDefinition($definition);
56     return new static($id, $definition, $type);
57   }
58
59   /**
60    * Gets library definition defaults.
61    *
62    * @param array $definition
63    *   A library definition array.
64    */
65   protected static function processDefinition(array &$definition) {
66     $definition += [
67       'dependencies' => [],
68       // @todo This fallback is not very elegant.
69       'version_detector' => [
70         'id' => 'static',
71         'configuration' => ['version' => ''],
72       ],
73     ];
74   }
75
76   /**
77    * {@inheritdoc}
78    */
79   public function getType() {
80     return $this->type;
81   }
82
83 }