class PeclExtension in Markdown 8.2
PeclExtension Annotation.
@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\PeclExtension
- 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 PeclExtension
File
- src/
Annotation/ PeclExtension.php, line 16
Namespace
Drupal\markdown\AnnotationView source
class PeclExtension extends InstallableLibrary {
/**
* An associative array of package information, keyed by version.
*
* @var array[]
*/
protected $packageInfo = [];
/**
* {@inheritdoc}
*/
public function __construct($values = []) {
parent::__construct($values);
// Add the necessary PHP requirement.
if (($info = $this
->getPackageInfo()) && !empty($info['dependencies']['required']['php']['min'])) {
$this->requirements[] = InstallableRequirement::create([
'value' => PHP_VERSION,
'constraints' => [
'Version' => [
'name' => 'PHP',
'value' => '>=' . $info['dependencies']['required']['php']['min'],
],
],
]);
}
}
/**
* {@inheritdoc}
*/
protected function detectVersion() {
if (($name = $this
->getName()) && extension_loaded($name) && ($version = phpversion($name))) {
// Extract any compiled "library" version associated with the extension.
// @todo Revisit this to see if there's a better way.
ob_start();
phpinfo(INFO_MODULES);
$contents = ob_get_contents();
ob_clean();
preg_match('/(lib-?' . preg_quote($name, '/') . ').*?v?\\s?(\\d+\\.\\d+(?:\\.\\d+)?)/', $contents, $matches);
if (!empty($matches[2]) && (!$version || $version !== $matches[2])) {
$libName = rtrim($matches[1], '-');
$libVersion = $matches[2];
$versionExtra = "{$version}+{$libName}-{$libVersion}";
}
return isset($versionExtra) ? [
$version,
$versionExtra,
] : $version;
}
}
/**
* {@inheritdoc}
*/
public function getAvailableVersions() {
if (!isset($this->availableVersions)) {
$this->availableVersions = [];
// @see https://github.com/php/web-pecl/blob/e98cb34ebcb26b75b4001d1b3458afdad6ba6f83/src/Rest.php#L519-L520
if (($name = $this
->getName()) && ($data = $this
->requestXml(sprintf('https://pecl.php.net/rest/r/%s/allreleases.xml', $name), TRUE)) && !empty($data['r'])) {
$this->availableVersions = array_column($data['r'], 'v');
}
}
return $this->availableVersions;
}
/**
* {@inheritdoc}
*/
public function getInstallCommand() {
return 'pecl install ' . $this
->getName();
}
/**
* Retrieves the name of a PHP extension.
*
* The name is extracted from a plugin identifier that starts with "ext-".
*
* @return string|null
* The PHP extension name, if it exists.
*/
public function getName() {
return $this->id
->removeLeft('ext-');
}
/**
* Retrieves the package information for the PECL package.
*
* @param string|null $version
* A specific version of package information to retrieve. If not specified,
* it will default to the currently installed version or the latest version
* available if not installed.
*
* @return array
* An associative array of PECL package information.
*/
public function getPackageInfo($version = NULL) {
// Attempt to use installed version if none was explicitly specified.
if (!$version && $this->version) {
$version = $this->version;
}
elseif (!$version && ($latestVersion = $this
->getLatestVersion())) {
$version = $latestVersion;
}
// Immediately return if version couldn't be determined.
if (!$version) {
return [];
}
if (!isset($this->packageInfo[$version])) {
$this->packageInfo[$version] = [];
// @see https://github.com/php/web-pecl/blob/e98cb34ebcb26b75b4001d1b3458afdad6ba6f83/src/Rest.php#L519-L520
if (($name = $this
->getName()) && ($data = $this
->requestXml(sprintf('https://pecl.php.net/rest/r/%s/package.%s.xml', $name, $version), TRUE))) {
$this->packageInfo[$version] = $data;
}
}
return $this->packageInfo[$version];
}
/**
* {@inheritdoc}
*/
public function getUrl(array $options = []) {
if (!$this->url && ($name = $this
->getName())) {
$this->url = sprintf('https://pecl.php.net/package/%s', $name);
}
return parent::getUrl($options);
}
/**
* {@inheritdoc}
*/
public function getVersionUrl($version = NULL, array $options = []) {
if (!isset($version)) {
$version = $this->version ?: '';
}
if (!isset($this->versionUrls[$version])) {
$this->versionUrls[$version] = FALSE;
if ($this
->isKnownVersion($version) && !$this
->isDev($version) && ($name = $this
->getName())) {
if (!isset($options['attributes']['target'])) {
$options['attributes']['target'] = '_blank';
}
$this->versionUrls[$version] = Url::fromUri(sprintf('https://pecl.php.net/package/%s/%s', $name, $version), $options);
}
}
return $this->versionUrls[$version];
}
/**
* {@inheritdoc}
*/
protected function validateIdentifier(Identifier $id) {
if (!$id
->startsWith('ext-')) {
throw AnnotationException::semanticalError('A PeclExtension definition must prefix its identifier with "ext-".');
}
}
}
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 | ||
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. | |
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 requirements that contain "Version" constraints. | |
InstallablePluginTrait:: |
public | function | Validates the plugin requirements. | |
PeclExtension:: |
protected | property | An associative array of package information, keyed by version. | |
PeclExtension:: |
protected | function |
Detects the version of the library installed. Overrides InstallableLibrary:: |
|
PeclExtension:: |
public | function |
Retrieves the available versions of the library. Overrides InstallableLibrary:: |
|
PeclExtension:: |
public | function |
Retrieves the CLI command used to install the library, if any. Overrides InstallableLibrary:: |
|
PeclExtension:: |
public | function | Retrieves the name of a PHP extension. | |
PeclExtension:: |
public | function | Retrieves the package information for the PECL package. | |
PeclExtension:: |
public | function |
Retrieves the definition's URL property as an object. Overrides InstallablePluginTrait:: |
|
PeclExtension:: |
public | function |
Retrieves the version as a URL. Overrides InstallableLibrary:: |
|
PeclExtension:: |
protected | function |
Helper method for validating the definition identifier. Overrides AnnotationObject:: |
|
PeclExtension:: |
public | function |
AnnotationObject constructor. Overrides InstallableLibrary:: |