DebugPackagesCommand.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Command;
  12. use Composer\Autoload\AutoloadGenerator;
  13. use Composer\DependencyResolver;
  14. use Composer\DependencyResolver\Pool;
  15. use Composer\DependencyResolver\Request;
  16. use Composer\DependencyResolver\Operation;
  17. use Composer\Package\LinkConstraint\VersionConstraint;
  18. use Composer\Repository\PlatformRepository;
  19. use Symfony\Component\Console\Input\InputInterface;
  20. use Symfony\Component\Console\Output\OutputInterface;
  21. /**
  22. * @author Jordi Boggiano <j.boggiano@seld.be>
  23. */
  24. class DebugPackagesCommand extends Command
  25. {
  26. protected function configure()
  27. {
  28. $this
  29. ->setName('debug:packages')
  30. ->setDescription('Lists all existing packages and their version')
  31. ->setHelp(<<<EOT
  32. <info>php composer debug:packages</info>
  33. EOT
  34. )
  35. ;
  36. }
  37. protected function execute(InputInterface $input, OutputInterface $output)
  38. {
  39. $composer = $this->getComposer();
  40. // create local repo, this contains all packages that are installed in the local project
  41. $localRepo = $composer->getRepositoryManager()->getLocalRepository();
  42. // create installed repo, this contains all local packages + platform packages (php & extensions)
  43. $installedRepo = new PlatformRepository($localRepo);
  44. foreach ($installedRepo->getPackages() as $package) {
  45. $output->writeln('installed: '.$package->getName().' '.$package->getVersion());
  46. }
  47. foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
  48. foreach ($repository->getPackages() as $package) {
  49. $output->writeln('available: '.$package->getName().' '.$package->getVersion());
  50. }
  51. }
  52. }
  53. }