function ShowCommand::printPackageInfoAsJson
Prints package info in JSON format.
Parameters
array<string, string> $versions:
1 call to ShowCommand::printPackageInfoAsJson()
- ShowCommand::execute in vendor/
composer/ composer/ src/ Composer/ Command/ ShowCommand.php - Executes the current command.
File
-
vendor/
composer/ composer/ src/ Composer/ Command/ ShowCommand.php, line 1028
Class
- ShowCommand
- @author Robert Schönthal <seroscho@googlemail.com> @author Jordi Boggiano <j.boggiano@seld.be> @author Jérémy Romey <jeremyFreeAgent> @author Mihai Plasoianu <mihai@plasoianu.de>
Namespace
Composer\CommandCode
protected function printPackageInfoAsJson(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, ?PackageInterface $latestPackage = null) : void {
$json = [
'name' => $package->getPrettyName(),
'description' => $package->getDescription(),
'keywords' => $package->getKeywords() ?: [],
'type' => $package->getType(),
'homepage' => $package->getHomepage(),
'names' => $package->getNames(),
];
$json = $this->appendVersions($json, $versions);
$json = $this->appendLicenses($json, $package);
if ($latestPackage) {
$json['latest'] = $latestPackage->getPrettyVersion();
}
else {
$latestPackage = $package;
}
if (null !== $package->getSourceType()) {
$json['source'] = [
'type' => $package->getSourceType(),
'url' => $package->getSourceUrl(),
'reference' => $package->getSourceReference(),
];
}
if (null !== $package->getDistType()) {
$json['dist'] = [
'type' => $package->getDistType(),
'url' => $package->getDistUrl(),
'reference' => $package->getDistReference(),
];
}
if (!PlatformRepository::isPlatformPackage($package->getName()) && $installedRepo->hasPackage($package)) {
$path = $this->requireComposer()
->getInstallationManager()
->getInstallPath($package);
if (is_string($path)) {
$path = realpath($path);
if ($path !== false) {
$json['path'] = $path;
}
}
else {
$json['path'] = null;
}
if ($package->getReleaseDate() !== null) {
$json['released'] = $package->getReleaseDate()
->format(DATE_ATOM);
}
}
if ($latestPackage instanceof CompletePackageInterface && $latestPackage->isAbandoned()) {
$json['replacement'] = $latestPackage->getReplacementPackage();
}
if ($package->getSuggests()) {
$json['suggests'] = $package->getSuggests();
}
if ($package->getSupport()) {
$json['support'] = $package->getSupport();
}
$json = $this->appendAutoload($json, $package);
if ($package->getIncludePaths()) {
$json['include_path'] = $package->getIncludePaths();
}
$json = $this->appendLinks($json, $package);
$this->getIO()
->write(JsonFile::encode($json));
}