diff --git a/src/Composer/Command/RemoveCommand.php b/src/Composer/Command/RemoveCommand.php index 9646d6db1..27be1a0ca 100644 --- a/src/Composer/Command/RemoveCommand.php +++ b/src/Composer/Command/RemoveCommand.php @@ -22,6 +22,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; +use Composer\Package\BasePackage; /** * @author Pierre du Plessis @@ -100,11 +101,11 @@ EOT $json->removeLink($altType, $composer[$altType][$package]); } } - } elseif (isset($composer[$type]) && $matches = preg_grep('#^'.$package.'#', array_keys($composer[$type]))) { + } elseif (isset($composer[$type]) && $matches = preg_grep(BasePackage::packageNameToRegexp($package), array_keys($composer[$type]))) { foreach ($matches as $matchedPackage) { $json->removeLink($type, $matchedPackage); } - } elseif (isset($composer[$altType]) && $matches = preg_grep('#^'.$package.'#', array_keys($composer[$altType]))) { + } elseif (isset($composer[$altType]) && $matches = preg_grep(BasePackage::packageNameToRegexp($package), array_keys($composer[$altType]))) { foreach ($matches as $matchedPackage) { $io->writeError('' . $matchedPackage . ' could not be found in ' . $type . ' but it is present in ' . $altType . ''); if ($io->isInteractive()) { diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 2ace251af..bd0d22e3c 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -33,6 +33,7 @@ use Composer\Installer\NoopInstaller; use Composer\Installer\SuggestedPackagesReporter; use Composer\IO\IOInterface; use Composer\Package\AliasPackage; +use Composer\Package\BasePackage; use Composer\Package\CompletePackage; use Composer\Package\Link; use Composer\Package\Loader\ArrayLoader; @@ -1254,7 +1255,7 @@ class Installer } foreach ($this->updateWhitelist as $whiteListedPattern => $void) { - $patternRegexp = $this->packageNameToRegexp($whiteListedPattern); + $patternRegexp = BasePackage::packageNameToRegexp($whiteListedPattern); if (preg_match($patternRegexp, $package->getName())) { return true; } @@ -1263,19 +1264,6 @@ class Installer return false; } - /** - * Build a regexp from a package name, expanding * globs as required - * - * @param string $whiteListedPattern - * @return string - */ - private function packageNameToRegexp($whiteListedPattern) - { - $cleanedWhiteListedPattern = str_replace('\\*', '.*', preg_quote($whiteListedPattern)); - - return "{^" . $cleanedWhiteListedPattern . "$}i"; - } - /** * @param array $links * @return array @@ -1341,7 +1329,7 @@ class Installer // check if the name is a glob pattern that did not match directly if (!$nameMatchesRequiredPackage) { - $whitelistPatternRegexp = $this->packageNameToRegexp($packageName); + $whitelistPatternRegexp = BasePackage::packageNameToRegexp($packageName); foreach ($rootRequiredPackageNames as $rootRequiredPackageName) { if (preg_match($whitelistPatternRegexp, $rootRequiredPackageName)) { $nameMatchesRequiredPackage = true; diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index 1e3081c7e..65ea6860f 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -234,4 +234,17 @@ abstract class BasePackage implements PackageInterface $this->repository = null; $this->id = -1; } + + /** + * Build a regexp from a package name, expanding * globs as required + * + * @param string $whiteListedPattern + * @return string + */ + public static function packageNameToRegexp($whiteListedPattern) + { + $cleanedWhiteListedPattern = str_replace('\\*', '.*', preg_quote($whiteListedPattern)); + + return "{^" . $cleanedWhiteListedPattern . "$}i"; + } }