Further modules included.
[yaffs-website] / web / modules / contrib / libraries / src / Plugin / libraries / VersionDetector / StaticDetector.php
1 <?php
2
3 namespace Drupal\libraries\Plugin\libraries\VersionDetector;
4
5 use Drupal\Core\Plugin\PluginBase;
6 use Drupal\libraries\ExternalLibrary\Exception\UnknownLibraryVersionException;
7 use Drupal\libraries\ExternalLibrary\Version\VersionDetectorInterface;
8 use Drupal\libraries\ExternalLibrary\Version\VersionedLibraryInterface;
9
10 /**
11  * Detects the version by returning a static string.
12  *
13  * As this does not perform any actual detection and, thus, circumvents any
14  * negotiation of versions by Libraries API it should only be used for testing
15  * or when the version of a library cannot be determined from the source code
16  * itself.
17  *
18  * @VersionDetector("static")
19  */
20 class StaticDetector extends PluginBase implements VersionDetectorInterface {
21
22   /**
23    * Constructs a static version detector.
24    *
25    * @param array $configuration
26    * @param string $plugin_id
27    * @param array $plugin_definition
28    */
29   public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
30     $configuration += [
31       'version' => NULL,
32     ];
33     parent::__construct($configuration, $plugin_id, $plugin_definition);
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function detectVersion(VersionedLibraryInterface $library) {
40     if (!isset($this->configuration['version'])) {
41       throw new UnknownLibraryVersionException($library);
42     }
43     $library->setVersion($this->configuration['version']);
44   }
45
46 }