Support both require and requires as depends link-type arg
parent
c97a33577b
commit
fd0bf14eb2
|
@ -25,6 +25,8 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
*/
|
*/
|
||||||
class DependsCommand extends Command
|
class DependsCommand extends Command
|
||||||
{
|
{
|
||||||
|
protected $linkTypes = array('require', 'recommend', 'suggest');
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -32,7 +34,7 @@ class DependsCommand extends Command
|
||||||
->setDescription('Shows which packages depend on the given package')
|
->setDescription('Shows which packages depend on the given package')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputArgument('package', InputArgument::REQUIRED, 'Package to inspect'),
|
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
|
->setHelp(<<<EOT
|
||||||
Displays detailed information about where a package is referenced.
|
Displays detailed information about where a package is referenced.
|
||||||
|
@ -74,10 +76,15 @@ EOT
|
||||||
|
|
||||||
$repos = $composer->getRepositoryManager()->getRepositories();
|
$repos = $composer->getRepositoryManager()->getRepositories();
|
||||||
$types = $input->getOption('link-type');
|
$types = $input->getOption('link-type');
|
||||||
|
|
||||||
foreach ($repos as $repository) {
|
foreach ($repos as $repository) {
|
||||||
foreach ($repository->getPackages() as $package) {
|
foreach ($repository->getPackages() as $package) {
|
||||||
foreach ($types as $type) {
|
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 ($link->getTarget() === $needle) {
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
$references[] = array($type, $package, $link);
|
$references[] = array($type, $package, $link);
|
||||||
|
|
Loading…
Reference in New Issue