diff --git a/doc/03-cli.md b/doc/03-cli.md index b421d7909..cf4e8b0c8 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -345,6 +345,7 @@ symfony/symfony requires monolog/monolog (~1) * **--match-constraint (-m):** Filters the dependencies shown using this constraint. * **--invert-match-constraint (-i):** Turns --match-constraint around into a blacklist insteead of a whitelist. +* **--with-replaces:** Search for replaced packages as well. ## validate diff --git a/src/Composer/Command/DependsCommand.php b/src/Composer/Command/DependsCommand.php index 7a37e1058..0fb524117 100644 --- a/src/Composer/Command/DependsCommand.php +++ b/src/Composer/Command/DependsCommand.php @@ -47,6 +47,7 @@ class DependsCommand extends Command new InputOption('link-type', '', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Link types to show (require, require-dev)', array_keys($this->linkTypes)), new InputOption('match-constraint', 'm', InputOption::VALUE_REQUIRED, 'Filters the dependencies shown using this constraint', '*'), new InputOption('invert-match-constraint', 'i', InputOption::VALUE_NONE, 'Turns --match-constraint around into a blacklist insteead of whitelist'), + new InputOption('with-replaces', '', InputOption::VALUE_NONE, 'Search for replaced packages as well'), )) ->setHelp(<<parseConstraints($input->getOption('match-constraint')); $matchInvert = $input->getOption('invert-match-constraint'); + $needles = array($needle); + if (true === $input->getOption('with-replaces')) { + foreach ($packages as $package) { + $needles = array_merge($needles, array_map(function (Link $link) { + return $link->getTarget(); + }, $package->getReplaces())); + } + } + $messages = array(); $outputPackages = array(); $io = $this->getIO(); @@ -104,10 +114,12 @@ EOT foreach ($types as $type) { /** @var Link $link */ foreach ($package->{'get'.$linkTypes[$type][0]}() as $link) { - if ($link->getTarget() === $needle && ($link->getConstraint()->matches($constraint) ? !$matchInvert : $matchInvert)) { - if (!isset($outputPackages[$package->getName()])) { - $messages[] = ''.$package->getPrettyName() . ' ' . $linkTypes[$type][1] . ' ' . $needle .' (' . $link->getPrettyConstraint() . ')'; - $outputPackages[$package->getName()] = true; + foreach ($needles as $needle) { + if ($link->getTarget() === $needle && ($link->getConstraint()->matches($constraint) ? !$matchInvert : $matchInvert)) { + if (!isset($outputPackages[$package->getName()])) { + $messages[] = ''.$package->getPrettyName() . ' ' . $linkTypes[$type][1] . ' ' . $needle .' (' . $link->getPrettyConstraint() . ')'; + $outputPackages[$package->getName()] = true; + } } } }