3 namespace Drupal\libraries\Plugin\libraries\VersionDetector;
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;
11 * Detects the version by returning a static string.
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
18 * @VersionDetector("static")
20 class StaticDetector extends PluginBase implements VersionDetectorInterface {
23 * Constructs a static version detector.
25 * @param array $configuration
26 * @param string $plugin_id
27 * @param array $plugin_definition
29 public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
33 parent::__construct($configuration, $plugin_id, $plugin_definition);
39 public function detectVersion(VersionedLibraryInterface $library) {
40 if (!isset($this->configuration['version'])) {
41 throw new UnknownLibraryVersionException($library);
43 $library->setVersion($this->configuration['version']);