mirror of
https://github.com/composer/composer
synced 2025-05-11 09:32:55 +00:00
Remove filterPackages and add RepositoryInterface::search, refactor all commands to use new methods and remove all usage of the full package list for Composer repositories that support providers, fixes #1646
This commit is contained in:
parent
095852933e
commit
be861f090a
11 changed files with 233 additions and 205 deletions
|
@ -74,6 +74,27 @@ class ArrayRepository implements RepositoryInterface
|
|||
return $packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function search($query, $mode = 0)
|
||||
{
|
||||
$regex = '{(?:'.implode('|', preg_split('{\s+}', $query)).')}i';
|
||||
|
||||
$matches = array();
|
||||
foreach ($this->getPackages() as $package) {
|
||||
// TODO implement SEARCH_FULLTEXT handling with keywords/description matching
|
||||
if (preg_match($regex, $package->getName())) {
|
||||
$matches[] = array(
|
||||
'name' => $package->getName(),
|
||||
'description' => $package->getDescription(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -112,20 +133,6 @@ class ArrayRepository implements RepositoryInterface
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function filterPackages($callback, $class = 'Composer\Package\Package')
|
||||
{
|
||||
foreach ($this->getPackages() as $package) {
|
||||
if (false === call_user_func($callback, $package)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function createAliasPackage(PackageInterface $package, $alias = null, $prettyAlias = null)
|
||||
{
|
||||
return new AliasPackage($package, $alias ?: $package->getAlias(), $prettyAlias ?: $package->getPrettyAlias());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue