Remove unnecessary Pool usage in HomeCommand
parent
75c501251d
commit
049f84f21f
|
@ -12,11 +12,11 @@
|
|||
|
||||
namespace Composer\Command;
|
||||
|
||||
use Composer\DependencyResolver\Pool;
|
||||
use Composer\Factory;
|
||||
use Composer\Package\CompletePackageInterface;
|
||||
use Composer\Repository\CompositeRepository;
|
||||
use Composer\Repository\RepositoryInterface;
|
||||
use Composer\Repository\ArrayRepository;
|
||||
use Composer\Util\ProcessExecutor;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
@ -61,67 +61,51 @@ EOT
|
|||
$return = 0;
|
||||
|
||||
foreach ($input->getArgument('packages') as $packageName) {
|
||||
$handled = false;
|
||||
$packageExists = false;
|
||||
foreach ($repos as $repo) {
|
||||
$package = $this->getPackage($repo, $packageName);
|
||||
if ($package instanceof CompletePackageInterface) {
|
||||
break;
|
||||
foreach ($repo->findPackages($packageName) as $package) {
|
||||
$packageExists = true;
|
||||
if ($this->handlePackage($package, $input->getOption('homepage'), $input->getOption('show'))) {
|
||||
$handled = true;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$package = $this->getPackage($repo, $packageName);
|
||||
|
||||
if (!$package instanceof CompletePackageInterface) {
|
||||
if (!$packageExists) {
|
||||
$return = 1;
|
||||
$this->getIO()->writeError('<warning>Package '.$packageName.' not found</warning>');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$support = $package->getSupport();
|
||||
$url = isset($support['source']) ? $support['source'] : $package->getSourceUrl();
|
||||
if (!$url || $input->getOption('homepage')) {
|
||||
$url = $package->getHomepage();
|
||||
}
|
||||
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
if (!$handled) {
|
||||
$return = 1;
|
||||
$this->getIO()->writeError('<warning>'.($input->getOption('homepage') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL').' for '.$packageName.'</warning>');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($input->getOption('show')) {
|
||||
$this->getIO()->write(sprintf('<info>%s</info>', $url));
|
||||
} else {
|
||||
$this->openBrowser($url);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* finds a package by name
|
||||
*
|
||||
* @param RepositoryInterface $repos
|
||||
* @param string $name
|
||||
* @return CompletePackageInterface
|
||||
*/
|
||||
protected function getPackage(RepositoryInterface $repos, $name)
|
||||
private function handlePackage(CompletePackageInterface $package, $showHomepage, $showOnly)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
$pool = new Pool('dev');
|
||||
$pool->addRepository($repos);
|
||||
$matches = $pool->whatProvides($name);
|
||||
|
||||
foreach ($matches as $index => $package) {
|
||||
// skip providers/replacers
|
||||
if ($package->getName() !== $name) {
|
||||
unset($matches[$index]);
|
||||
continue;
|
||||
$support = $package->getSupport();
|
||||
$url = isset($support['source']) ? $support['source'] : $package->getSourceUrl();
|
||||
if (!$url || $showHomepage) {
|
||||
$url = $package->getHomepage();
|
||||
}
|
||||
|
||||
return $package;
|
||||
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($showOnly) {
|
||||
$this->getIO()->write(sprintf('<info>%s</info>', $url));
|
||||
} else {
|
||||
$this->openBrowser($url);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,14 +145,15 @@ EOT
|
|||
$composer = $this->getComposer(false);
|
||||
|
||||
if ($composer) {
|
||||
return array(
|
||||
$composer->getRepositoryManager()->getLocalRepository(),
|
||||
new CompositeRepository($composer->getRepositoryManager()->getRepositories())
|
||||
return array_merge(
|
||||
array(new ArrayRepository(array($composer->getPackage()))), // root package
|
||||
array($composer->getRepositoryManager()->getLocalRepository()), // installed packages
|
||||
$composer->getRepositoryManager()->getRepositories() // remotes
|
||||
);
|
||||
}
|
||||
|
||||
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
|
||||
|
||||
return array(new CompositeRepository($defaultRepos));
|
||||
return $defaultRepos;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue