*/
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:----HEFFRM26YX5xpz3zsQnpFYVjrjY6GEm6ZnWtISs5vZHNj8D9LaiqDiM0PstI5KqRGKmG+pVN4F083rtMqX6EbgrJzIiC2akP/MXjEEcfvCvQvfeFZXTRJnKwamSHV3zXDP+g7UGJDd8CV3lsmNuOcTDbmujS8iFCFF4QSn1VG93cZiU/kRjXJys3GquXJ/7+dgwm1JCuxDpQus0OPJgIhjuAtxbtUxG1/CAkWdrF8bJyhW5I9D11sm/2Bo4JoqJOW3HIgaLx3OsJWwTOTfeBQRzshyiQ6tb8bXDM60Nh48jx4XGjk/RqvCcsnCusaugwVxwIYz8SK1P+qAJ5uIr3dGhUvBwI/I7eG4cwCDT0NNj60ux0+80QJq6q+FWtrMAZ8g3p9XPHRZ74IDHL5PW4myNmZQe8+k5otSiXHiS38KTEMv+STBQgv6hMHUN2SRbfObS0rEFRo35gQiUkv0czUnS/FPlaIRCbtuRa7v8XDetUbByxtTB08Quxm8EZDxG6GWq7O2VDnRnR2da72SjFFAZyFiB5dQYSTw0lqY5GnT53uIAURmh/8pvi6X6jL/t58/Sy2VhmdYqkr7C6l99b67/nd3n7UbvDkqPSrcJ0WL9u3f0fXwXZXUpzuCnj1p7WliX6SHhHUvFa5SYnnz2/T8k3GcEiazZS6CLRcFb2VAM=----ATTACHMENT:----NTk4NzI4NjcwMzA2MjgyIDU4ODI0Njg1MTQzMDU4MzkgMzY3MzA0MTI2MDYyMzYzMA==