class ComposerPackage in Markdown 8.2
Annotation for providing an installable library via Composer.
@Target("ANNOTATION")
@todo Move upstream to https://www.drupal.org/project/installable_plugins.
Hierarchy
- class \Drupal\Component\Annotation\AnnotationBase implements AnnotationInterface
- class \Drupal\markdown\Annotation\AnnotationObject implements \Drupal\markdown\Annotation\ArrayAccess, \Drupal\markdown\Annotation\IteratorAggregate, PluginDefinitionInterface uses DependencySerializationTrait
- class \Drupal\markdown\Annotation\InstallableLibrary uses InstallablePluginTrait, HttpClientTrait
- class \Drupal\markdown\Annotation\ComposerPackage
- class \Drupal\markdown\Annotation\InstallableLibrary uses InstallablePluginTrait, HttpClientTrait
- class \Drupal\markdown\Annotation\AnnotationObject implements \Drupal\markdown\Annotation\ArrayAccess, \Drupal\markdown\Annotation\IteratorAggregate, PluginDefinitionInterface uses DependencySerializationTrait
Expanded class hierarchy of ComposerPackage
See also
https://www.drupal.org/project/markdown/issues/3200476
File
- src/
Annotation/ ComposerPackage.php, line 19
Namespace
Drupal\markdown\AnnotationView source
class ComposerPackage extends InstallableLibrary {
/**
* Detects the installed version of a Composer package.
*
* @return string|void
* The detected version of the Composer package or NULL if not enabled.
*/
protected function detectVersion() {
$id = $this
->getId();
// Composer 1 support.
// @todo Remove in 4.0.0.
// @see https://www.drupal.org/project/markdown/issues/3200476
if (!class_exists('\\Composer\\InstalledVersions')) {
return Composer::getInstalledVersion($id) ?: Composer::getVersionFromClass($this->object);
}
// Composer 2+ runtime installed versions support.
// @see https://getcomposer.org/doc/07-runtime.md#knowing-the-version-of-package-x
if (InstalledVersions::isInstalled($id)) {
return InstalledVersions::getPrettyVersion($id);
}
}
/**
* {@inheritdoc}
*/
public function getAvailableVersions() {
if (!isset($this->availableVersions)) {
$this->availableVersions = [];
$id = $this
->getId();
// To ensure we have the latest versions at all times, use the
// https://repo.packagist.org/p/[vendor]/[package].json URL which are
// static files and not cached.
$json = $this
->requestJson(sprintf('https://repo.packagist.org/p/%s.json', $id));
if (!empty($json['packages'][$id])) {
$this->availableVersions = array_keys($json['packages'][$id]);
}
}
return $this->availableVersions;
}
/**
* {@inheritdoc}
*/
public function getInstallCommand() {
return 'composer require ' . $this->id;
}
/**
* Retrieves the package name from the library identifier.
*
* @return string|void
* The package name.
*/
public function getPackageName() {
if ($parts = explode('/', $this->id, 2)) {
return $parts[1];
}
}
/**
* Retrieves the vendor name from the library identifier.
*
* @return string|void
* The vendor name.
*/
public function getVendorName() {
if ($parts = explode('/', $this->id, 2)) {
return $parts[0];
}
}
/**
* {@inheritdoc}
*/
public function getVersionUrl($version = NULL, array $options = []) {
if (!$version) {
$version = $this->version;
}
if (!isset($this->versionUrls[$version])) {
$this->versionUrls[$version] = FALSE;
if ($this
->isKnownVersion($version) && !$this
->isDev($version) && ($json = $this
->requestPackage())) {
$repository = !empty($json['repository']) ? $json['repository'] : sprintf('https://packagist.org/packages/%s', $this
->getId());
if (!isset($json['versions'][$version])) {
$version = "v{$version}";
$this->versionUrls[$version] = FALSE;
}
if (isset($json['versions'][$version])) {
if (!isset($options['attributes']['target'])) {
$options['attributes']['target'] = '_blank';
}
switch (parse_url($repository, PHP_URL_HOST)) {
case 'github.com':
$uri = sprintf('%s/releases/%s', $repository, $version);
break;
case 'packagist.org':
$uri = sprintf('%s#%s', $repository, $version);
break;
default:
$uri = $repository;
}
$this->versionUrls[$version] = Url::fromUri($uri, $options);
}
}
}
return $this->versionUrls[$version];
}
/**
* Retrieves the package JSON data.
*
* @return array
* The package JSON data.
*/
protected function requestPackage() {
// When requesting package information, use the normal API URL which
// includes a lot more metadata about the package. This, unfortunately,
// cached and only refreshed once every 12 hours.
$json = $this
->requestJson(sprintf('https://packagist.org/packages/%s.json', $this
->getId()));
return !empty($json['package']) ? $json['package'] : [];
}
/**
* {@inheritdoc}
*/
protected function validateIdentifier(Identifier $id) {
if (!$id
->contains('/')) {
throw AnnotationException::semanticalError('A ComposerPackage definition must contain a forward-slash (/) in its identifier so that it represents the correct {vendor}/{package} name.');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AnnotationBase:: |
protected | property | The class used for this annotated class. | |
AnnotationBase:: |
public | property | The annotated class ID. | 1 |
AnnotationBase:: |
protected | property | The provider of the annotated class. | |
AnnotationBase:: |
public | function |
Gets the class of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationBase:: |
public | function |
Gets the name of the provider of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationBase:: |
public | function |
Sets the class of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationBase:: |
public | function |
Sets the name of the provider of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationObject:: |
public | property | The description of the plugin. | |
AnnotationObject:: |
public | property | A human-readable label. | |
AnnotationObject:: |
public | property | The weight of the plugin. | |
AnnotationObject:: |
protected | property | Stores deprecated values. | |
AnnotationObject:: |
protected | property | A list of deprecation messages, keyed by the deprecated property name. | |
AnnotationObject:: |
private | property | A list of triggered deprecations. | |
AnnotationObject:: |
public static | function | Allows the creation of new objects statically, for easier chainability. | |
AnnotationObject:: |
constant | |||
AnnotationObject:: |
protected | function | Merges values with this plugin. | |
AnnotationObject:: |
public | function |
Gets the value of an annotation. Overrides AnnotationInterface:: |
|
AnnotationObject:: |
public | function |
Gets the unique ID for this annotated class. Overrides AnnotationBase:: |
|
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
public | function |
Gets the unique identifier of the plugin. Overrides PluginDefinitionInterface:: |
|
AnnotationObject:: |
public | function | Merges values with this plugin. | |
AnnotationObject:: |
protected | function | Normalizes a value to ensure its ready to be merged with the definition. | |
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
protected | function | Indicates properties that should never be overridden after instantiation. | 1 |
AnnotationObject:: |
private | function | Triggers a deprecation notice for a given property. | |
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
public | function | ||
AnnotationObject:: |
public | function | ||
ComposerPackage:: |
protected | function |
Detects the installed version of a Composer package. Overrides InstallableLibrary:: |
|
ComposerPackage:: |
public | function |
Retrieves the available versions of the library. Overrides InstallableLibrary:: |
|
ComposerPackage:: |
public | function |
Retrieves the CLI command used to install the library, if any. Overrides InstallableLibrary:: |
|
ComposerPackage:: |
public | function | Retrieves the package name from the library identifier. | |
ComposerPackage:: |
public | function | Retrieves the vendor name from the library identifier. | |
ComposerPackage:: |
public | function |
Retrieves the version as a URL. Overrides InstallableLibrary:: |
|
ComposerPackage:: |
protected | function | Retrieves the package JSON data. | |
ComposerPackage:: |
protected | function |
Helper method for validating the definition identifier. Overrides AnnotationObject:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | Aliased as: __sleepTrait | 1 |
DependencySerializationTrait:: |
public | function | Aliased as: __wakeupTrait | 2 |
HttpClientTrait:: |
protected static | property | The HTTP client. | |
HttpClientTrait:: |
protected static | function | Retrieves an HTTP client. | |
InstallableLibrary:: |
protected | property | All available versions, regardless of stability. | |
InstallableLibrary:: |
public | property | Optional. A customized human-readable label for the library. | |
InstallableLibrary:: |
protected | property | The latest version, based on currently available versions and stability. | |
InstallableLibrary:: |
protected | property | An array of newer versions, based on currently set version and stability. | |
InstallableLibrary:: |
protected | property | The last exception thrown when attempting to initiate a request. | |
InstallableLibrary:: |
public | property | The version with extra metadata. | |
InstallableLibrary:: |
protected | property | A specific version URL, if known. | |
InstallableLibrary:: |
public | function | ||
InstallableLibrary:: |
public | function | Retrieves the latest version based on available versions. | |
InstallableLibrary:: |
public | function | Retrieves the newer versions of the library. | |
InstallableLibrary:: |
public | function | Retrieves the current status of the library. | |
InstallableLibrary:: |
public | function | Retrieves the version as a link to a specific release. | |
InstallableLibrary:: |
public | function | Indicates whether there is an issue performing requests for the library. | |
InstallableLibrary:: |
public | function | Indicates whether this is an alpha version. | |
InstallableLibrary:: |
public | function | Indicates whether this is a beta version. | |
InstallableLibrary:: |
public | function | Indicates whether this is an alpha version. | |
InstallableLibrary:: |
public | function | Indicates whether this is a known version. | |
InstallableLibrary:: |
public | function | Indicates whether this is any prerelease version. | |
InstallableLibrary:: |
public | function | Indicates whether this is a release candidate version. | |
InstallableLibrary:: |
public | function | Indicates whether this is a stable version. | |
InstallableLibrary:: |
protected | function | Requests a URL. | |
InstallableLibrary:: |
protected | function | Retrieves JSON from a URL. | |
InstallableLibrary:: |
protected | function | Retrieves XML from a URL. | |
InstallableLibrary:: |
public | function |
AnnotationObject constructor. Overrides AnnotationObject:: |
1 |
InstallablePluginTrait:: |
public | property | Indicates the plugin has been deprecated by providing a message. | |
InstallablePluginTrait:: |
public | property | Indicates the plugin is experimental by providing a message. | |
InstallablePluginTrait:: |
public | property | Flag indicating whether plugin is installed. | |
InstallablePluginTrait:: |
public | property | The class name of the primary object that is implemented by the library. | |
InstallablePluginTrait:: |
public | property | Flag indicating whether it is the preferred library. | |
InstallablePluginTrait:: |
public | property | An array of requirements for the plugin. | |
InstallablePluginTrait:: |
public | property | A list of requirement violation messages. | |
InstallablePluginTrait:: |
public | property | An array of runtime requirements for the plugin. | |
InstallablePluginTrait:: |
public | property | Flag indicating whether this plugin is to be visible in UI areas. | |
InstallablePluginTrait:: |
public | property | A URL for the plugin, typically for installation instructions. | |
InstallablePluginTrait:: |
public | property | The installed version. | |
InstallablePluginTrait:: |
public | property | The constraint the version must satisfy to be considered "installable". | |
InstallablePluginTrait:: |
public | function | Retrieves the plugin as a link using its label and URL. | |
InstallablePluginTrait:: |
public | function | Retrieves the definition's URL property as an object. | 1 |
InstallablePluginTrait:: |
public | function | Retrieves requirements that contain "Version" constraints. | |
InstallablePluginTrait:: |
public | function | Validates the plugin requirements. |