Procházet zdrojové kódy

Support both require and requires as depends link-type arg

Jordi Boggiano před 13 roky
rodič
revize
fd0bf14eb2
1 změnil soubory, kde provedl 9 přidání a 2 odebrání
  1. 9 2
      src/Composer/Command/DependsCommand.php

+ 9 - 2
src/Composer/Command/DependsCommand.php

@@ -25,6 +25,8 @@ use Symfony\Component\Console\Output\OutputInterface;
  */
 class DependsCommand extends Command
 {
+    protected $linkTypes = array('require', 'recommend', 'suggest');
+
     protected function configure()
     {
         $this
@@ -32,7 +34,7 @@ class DependsCommand extends Command
             ->setDescription('Shows which packages depend on the given package')
             ->setDefinition(array(
                 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'))
+                new InputOption('link-type', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Link types to show', $this->linkTypes)
             ))
             ->setHelp(<<<EOT
 Displays detailed information about where a package is referenced.
@@ -74,10 +76,15 @@ EOT
 
         $repos = $composer->getRepositoryManager()->getRepositories();
         $types = $input->getOption('link-type');
+
         foreach ($repos as $repository) {
             foreach ($repository->getPackages() as $package) {
                 foreach ($types as $type) {
-                    foreach ($package->{'get'.$type}() as $link) {
+                    $type = rtrim($type, 's');
+                    if (!in_array($type, $this->linkTypes)) {
+                        throw new \InvalidArgumentException('Unexpected link type: '.$type.', valid types: '.implode(', ', $this->linkTypes));
+                    }
+                    foreach ($package->{'get'.$type.'s'}() as $link) {
                         if ($link->getTarget() === $needle) {
                             if ($verbose) {
                                 $references[] = array($type, $package, $link);