1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-11 09:32:55 +00:00

Added --type option to search

This commit is contained in:
Pierre du Plessis 2016-06-21 16:38:52 +02:00
parent 5a3d60c0cf
commit 6a557e45b8
7 changed files with 110 additions and 11 deletions

View file

@ -89,7 +89,7 @@ class ArrayRepository extends BaseRepository
/**
* {@inheritDoc}
*/
public function search($query, $mode = 0)
public function search($query, $mode = 0, $type = null)
{
$regex = '{(?:'.implode('|', preg_split('{\s+}', $query)).')}i';
@ -102,9 +102,13 @@ class ArrayRepository extends BaseRepository
if (preg_match($regex, $name)
|| ($mode === self::SEARCH_FULLTEXT && $package instanceof CompletePackageInterface && preg_match($regex, implode(' ', (array) $package->getKeywords()) . ' ' . $package->getDescription()))
) {
if (null !== $type && $package->getType() !== $type) {
continue;
}
$matches[$name] = array(
'name' => $package->getPrettyName(),
'description' => $package->getDescription(),
'description' => $package instanceof CompletePackageInterface ? $package->getDescription() : null,
);
}
}