2012-01-05 03:11:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Command;
|
|
|
|
|
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2012-01-15 12:00:39 +00:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2012-01-05 03:11:37 +00:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Justin Rainbow <justin.rainbow@gmail.com>
|
2012-01-15 12:00:39 +00:00
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
2012-01-05 03:11:37 +00:00
|
|
|
*/
|
|
|
|
class DependsCommand extends Command
|
|
|
|
{
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('depends')
|
2012-01-15 12:00:39 +00:00
|
|
|
->setDescription('Shows which packages depend on the given package')
|
2012-01-05 03:11:37 +00:00
|
|
|
->setDefinition(array(
|
2012-01-15 12:00:39 +00:00
|
|
|
new InputArgument('package', InputArgument::REQUIRED, 'Package to inspect'),
|
|
|
|
new InputOption('link-type', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Link types to show', array('requires', 'recommends', 'suggests'))
|
2012-01-05 03:11:37 +00:00
|
|
|
))
|
|
|
|
->setHelp(<<<EOT
|
2012-01-15 12:00:39 +00:00
|
|
|
Displays detailed information about where a package is referenced.
|
|
|
|
|
2012-01-05 03:11:37 +00:00
|
|
|
<info>php composer.phar depends composer/composer</info>
|
|
|
|
|
|
|
|
EOT
|
|
|
|
)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$composer = $this->getComposer();
|
|
|
|
$references = $this->getReferences($input, $output, $composer);
|
|
|
|
|
2012-01-15 12:00:39 +00:00
|
|
|
if ($input->getOption('verbose')) {
|
|
|
|
$this->printReferences($input, $output, $references);
|
|
|
|
} else {
|
|
|
|
$this->printPackages($input, $output, $references);
|
|
|
|
}
|
2012-01-05 03:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* finds a list of packages which depend on another package
|
|
|
|
*
|
|
|
|
* @param InputInterface $input
|
|
|
|
* @param OutputInterface $output
|
|
|
|
* @param Composer $composer
|
|
|
|
* @return array
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
2012-01-08 21:39:42 +00:00
|
|
|
private function getReferences(InputInterface $input, OutputInterface $output, Composer $composer)
|
2012-01-05 03:11:37 +00:00
|
|
|
{
|
|
|
|
$needle = $input->getArgument('package');
|
|
|
|
|
|
|
|
$references = array();
|
2012-01-15 12:00:39 +00:00
|
|
|
$verbose = (Boolean) $input->getOption('verbose');
|
2012-01-05 03:11:37 +00:00
|
|
|
|
2012-01-15 12:00:39 +00:00
|
|
|
$repos = $composer->getRepositoryManager()->getRepositories();
|
|
|
|
$types = $input->getOption('link-type');
|
2012-01-05 03:11:37 +00:00
|
|
|
foreach ($repos as $repository) {
|
|
|
|
foreach ($repository->getPackages() as $package) {
|
2012-01-15 12:00:39 +00:00
|
|
|
foreach ($types as $type) {
|
2012-01-08 21:39:42 +00:00
|
|
|
foreach ($package->{'get'.$type}() as $link) {
|
|
|
|
if ($link->getTarget() === $needle) {
|
2012-01-15 12:00:39 +00:00
|
|
|
if ($verbose) {
|
|
|
|
$references[] = array($type, $package, $link);
|
|
|
|
} else {
|
|
|
|
$references[$package->getName()] = $package->getPrettyName();
|
|
|
|
}
|
2012-01-08 21:39:42 +00:00
|
|
|
}
|
2012-01-05 03:11:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $references;
|
|
|
|
}
|
|
|
|
|
2012-01-08 21:39:42 +00:00
|
|
|
private function printReferences(InputInterface $input, OutputInterface $output, array $references)
|
2012-01-05 03:11:37 +00:00
|
|
|
{
|
2012-01-08 21:39:42 +00:00
|
|
|
foreach ($references as $ref) {
|
|
|
|
$output->writeln($ref[1]->getPrettyName() . ' ' . $ref[1]->getPrettyVersion() . ' <info>' . $ref[0] . '</info> ' . $ref[2]->getPrettyConstraint());
|
2012-01-05 03:11:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-15 12:00:39 +00:00
|
|
|
|
|
|
|
private function printPackages(InputInterface $input, OutputInterface $output, array $packages)
|
|
|
|
{
|
|
|
|
ksort($packages);
|
|
|
|
foreach ($packages as $package) {
|
|
|
|
$output->writeln($package);
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 03:11:37 +00:00
|
|
|
}
|