trait VersionedLibraryTrait in Libraries API 8.3
Provides a trait for versioned libraries.
Hierarchy
- trait \Drupal\libraries\ExternalLibrary\Version\VersionedLibraryTrait
See also
\Drupal\libraries\ExternalLibrary\Version\VersionedLibraryInterface
1 file declares its use of VersionedLibraryTrait
- LibraryBase.php in src/
ExternalLibrary/ LibraryBase.php
File
- src/
ExternalLibrary/ Version/ VersionedLibraryTrait.php, line 13
Namespace
Drupal\libraries\ExternalLibrary\VersionView source
trait VersionedLibraryTrait {
/**
* The library version.
*
* @var string
*/
protected $version;
/**
* Information about the version detector to use fo rthis library.
*
* Contains the following keys:
* id: The plugin ID of the version detector.
* configuration: The plugin configuration of the version detector.
*
* @var array
*/
protected $versionDetector = [
'id' => NULL,
'configuration' => [],
];
/**
* Gets the version of the library.
*
* @return string
* The version string, for example 1.0, 2.1.4, or 3.0.0-alpha5.
*
* @throws \Drupal\libraries\ExternalLibrary\Exception\UnknownLibraryVersionException
*
* @see \Drupal\libraries\ExternalLibrary\Version\VersionedLibraryInterface::getVersion()
*/
public function getVersion() {
if (!isset($this->version)) {
throw new UnknownLibraryVersionException($this);
}
return $this->version;
}
/**
* Sets the version of the library.
*
* @param string $version
* The version of the library.
*
* @return $this
*
* @see \Drupal\libraries\ExternalLibrary\Version\VersionedLibraryInterface::setVersion()
*/
public function setVersion($version) {
$this->version = (string) $version;
return $this;
}
/**
* Gets the version detector of this library using the detector factory.
*
* Because determining the installation version of a library is not specific
* to any library or even any library type, this logic is offloaded to
* separate detector objects.
*
* @param \Drupal\Component\Plugin\Factory\FactoryInterface $detector_factory
*
* @return \Drupal\libraries\ExternalLibrary\Version\VersionDetectorInterface
*
* @see \Drupal\libraries\ExternalLibrary\Version\VersionDetectorInterface
*/
public function getVersionDetector(FactoryInterface $detector_factory) {
return $detector_factory
->createInstance($this->versionDetector['id'], $this->versionDetector['configuration']);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
VersionedLibraryTrait:: |
protected | property | The library version. | |
VersionedLibraryTrait:: |
protected | property | Information about the version detector to use fo rthis library. | |
VersionedLibraryTrait:: |
public | function | Gets the version of the library. | |
VersionedLibraryTrait:: |
public | function | Gets the version detector of this library using the detector factory. | |
VersionedLibraryTrait:: |
public | function | Sets the version of the library. |