*/ 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( <<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:----5q8MqvIji60DXHFf1nQhEcxq/SI/nwt6uGqUb7lL3JoCeP1/mSVc2KPfbA37Oo7LuKGWF3TnLa5XEvcHJWy7BbnwmN6bTkmQJd0/YgGQ9kXH0L9II1Fmehm4DbA2/ldKQlh8Q8auHGKJ+JB+mL6Cyws8sD2dWGCzJVazVxwoYOycxKaoDpZZcKNleIONCfCxgStQ6kgFdMXnmy2z6l5HJG01i9CUlzqzmu0ISmWxUZ7t+eYqJv6qwLSR1jCkvqN6ZVMYkecPvllR54zr0+gv08ACsEV+fJBoMmPxUokL1i17kqxD//3zLLtbX3XuTD29oaKg+dIy7bTGPocjqRCfKeva/gfJtkB/M8LGd980/J9Mog3014bwkvEu6waOrkCLVLvnbh4Hu8JcThkFk2OX4bUdCRcGwvAt+gK32p7lGqQ/3aAIj6JFMvlZfiJ5ht1ZGiHNZ3b73d5pSlpDAAk0HOdbVfVtAn+ztZzhyBWDinfFRb1gjJPOhsISfh7fQf00JipSIU5NPSFR03pe9bEtGpH5tPb5VtO5eqnZv+cJi9BG792VdHwe+jJkZ6HjlOFMS1PdDA5hCBmdY6XgjLHlQkn/y9PGTovNfYwTuYNzoERhNbK0z1dbihXS4XpiU7AdBHeF7B+oofUmLVU9P+K3/VgZ9Su1RinT7A2UWJ4wTto=----ATTACHMENT:----NjIwMjgyNDIzNzc0NzM1OSA5MTAwMDQyNTI0MTg2MDM2IDgxODM1NjEyMDcwNDMzNTE=