public static function Composer::getInstalledJson in Markdown 8.2
Retrieves the installed Composer JSON for a specific package.
@internal
Parameters
string $name: The package name for which version to check is installed.
array $comparisonJson: Optional. The JSON array to look for if the specified name doesn't exist. This can happen if installing an older package version where it uses an older package name. Unless the user explicitly installed that older package name, Composer will default to the newer/current package name in its installed.json file.
Return value
string|void The installed version or NULL if not installed.
Deprecated
in markdown:8.x-2.0 and is removed from markdown:4.0.0. No replacement.
See also
https://www.drupal.org/project/markdown/issues/3200476
1 call to Composer::getInstalledJson()
- Composer::getInstalledVersion in src/
Util/ Composer.php - Retrieves the installed version for a specific package.
File
- src/
Util/ Composer.php, line 112
Class
- Composer
- Helper class used to deal with composer.
Namespace
Drupal\markdown\UtilCode
public static function getInstalledJson($name, array $comparisonJson = []) {
/** @var \Composer\Autoload\ClassLoader $autoloader */
$autoloader = \Drupal::service('class_loader');
if ($name && ($file = $autoloader
->findFile('Composer\\Semver\\Semver'))) {
if (($file = realpath(dirname($file) . "/../../installed.json")) && ($contents = file_get_contents($file)) && ($installedJson = Json::decode($contents))) {
$packages = array_filter(isset($installedJson['packages']) ? $installedJson['packages'] : $installedJson, function ($package) use ($name) {
return !empty($package['name']) && $package['name'] === $name;
});
if (!$packages && $comparisonJson) {
$keysToCompare = [
'description',
'homepage',
'require',
'require-dev',
'autoload',
];
$packages = array_filter($installedJson, function ($package) use ($comparisonJson, $keysToCompare) {
foreach ($keysToCompare as $key) {
// Ignore key if not in the original JSON.
if (!isset($comparisonJson[$key])) {
continue;
}
// Package doesn't have the same key.
if (!isset($package[$key])) {
return FALSE;
}
// Check whether associative property arrays differ.
if (is_array($package[$key])) {
if (DiffArray::diffAssocRecursive($comparisonJson[$key], $package[$key])) {
return FALSE;
}
}
elseif ($package[$key] !== $comparisonJson[$key]) {
return FALSE;
}
}
return TRUE;
});
}
return current($packages) ?: NULL;
}
}
}