|
@@ -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);
|