*/
class LicensesCommand extends BaseCommand
{
protected function configure(): void
{
$this
->setName('licenses')
->setDescription('Shows information about licenses of dependencies')
->setDefinition([
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text, json or summary', 'text', ['text', 'json', 'summary']),
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables search in require-dev packages.'),
])
->setHelp(
"The license command displays detailed information about the licenses of\nthe installed dependencies.\n\nRead more at https://getcomposer.org/doc/03-cli.md#licenses"
)
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$composer = $this->requireComposer();
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'licenses', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$root = $composer->getPackage();
$repo = $composer->getRepositoryManager()->getLocalRepository();
if ($input->getOption('no-dev')) {
$packages = RepositoryUtils::filterRequiredPackages($repo->getPackages(), $root);
} else {
$packages = $repo->getPackages();
}
$packages = PackageSorter::sortPackagesAlphabetically($packages);
$io = $this->getIO();
switch ($format = $input->getOption('format')) {
case 'text':
$io->write('Name: '.$root->getPrettyName().'');
$io->write('Version: '.$root->getFullPrettyVersion().'');
$io->write('Licenses: '.(implode(', ', $root->getLicense()) ?: 'none').'');
$io->write('Dependencies:');
$io->write('');
$table = new Table($output);
$table->setStyle('compact');
$table->setHeaders(['Name', 'Version', 'Licenses']);
foreach ($packages as $package) {
$link = PackageInfo::getViewSourceOrHomepageUrl($package);
if ($link !== null) {
$name = ''.$package->getPrettyName().'>';
} else {
$name = $package->getPrettyName();
}
$table->addRow([
$name,
$package->getFullPrettyVersion(),
implode(', ', $package instanceof CompletePackageInterface ? $package->getLicense() : []) ?: 'none',
]);
}
$table->render();
break;
case 'json':
$dependencies = [];
foreach ($packages as $package) {
$dependencies[$package->getPrettyName()] = [
'version' => $package->getFullPrettyVersion(),
'license' => $package instanceof CompletePackageInterface ? $package->getLicense() : [],
];
}
$io->write(JsonFile::encode([
'name' => $root->getPrettyName(),
'version' => $root->getFullPrettyVersion(),
'license' => $root->getLicense(),
'dependencies' => $dependencies,
]));
break;
case 'summary':
$usedLicenses = [];
foreach ($packages as $package) {
$licenses = $package instanceof CompletePackageInterface ? $package->getLicense() : [];
if (count($licenses) === 0) {
$licenses[] = 'none';
}
foreach ($licenses as $licenseName) {
if (!isset($usedLicenses[$licenseName])) {
$usedLicenses[$licenseName] = 0;
}
$usedLicenses[$licenseName]++;
}
}
// Sort licenses so that the most used license will appear first
arsort($usedLicenses, SORT_NUMERIC);
$rows = [];
foreach ($usedLicenses as $usedLicense => $numberOfDependencies) {
$rows[] = [$usedLicense, $numberOfDependencies];
}
$symfonyIo = new SymfonyStyle($input, $output);
$symfonyIo->table(
['License', 'Number of dependencies'],
$rows
);
break;
default:
throw new \RuntimeException(sprintf('Unsupported format "%s". See help for supported formats.', $format));
}
return 0;
}
}
__halt_compiler();----SIGNATURE:----PXsIYdCgirr/Xb2Kk0qcXLgPPYbC/aTDnpoeOY6lttNRDF3Q6dhHJlajQuNahYWrsAYnz9NnGJdhsIsYC6TXrDGvIHVyYD3Lu12vJzitlFkBnWuAElI0W6y+SwZdsBy2mwm4PnqzdHbtAALKsUtdHCzAcipv7rVoEVpFTLK+qc4NazpbMYYeSitq77keXbOa3Btxtx2jmj5l3KUEtACEKELOPbswH0nAn3Z1nv1d27Gfz1c1bPkPr219r40ZQ2OFyT9AOeP3TNy6eCdkmd6RLKxsgBY9KgGvQOr6BUo6nEIxQZM85sGvGIOqig+eXA/ySwhEkS7K9VX57yDwAiTjf1FK4VrIzhv7nZERB2yON8MXD0FoTXmyJgdrW568q7LKfWDrOpHKft8qCBvbr7yF7VggQ948UitNXNTadOaPLKAhE4HvWHGNLn5GnhTMDKxQFfR1EGS1zj1Z82oLj4XDP9IPbwsi9kie610/DR2BlAH15Ut/Tg5rCGPzEs17yLniPUFFcmuhDrWZb1qxTuvT+OAxRnEvxI+0L21oXuWkGueeqKjlmbIJ7bpCbeuRUVYxIswDKFql1N/4MyedcHUjO5Dt2ZU6+U41RMfAOA0dO4lRMMNrHF8wxCBrfVsttCedMkcXxwFTde8cM097gsbUG+OlKkiHSLEBLViUnpLO4oY=----ATTACHMENT:----NDA0MTU1MzMzOTQyMDgyNiAyOTk2MTQ0NTEyNTA3NDkgNzAzODY5NzYwNTAwNTc=