mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 16:50:09 +01:00
clean up to remove search, refactor to better handle versions using regex
This commit is contained in:
committed by
Matt Stauffer
parent
6a5c06e934
commit
ece3a1ff2f
@@ -287,27 +287,6 @@ function ($exitCode, $errorOutput) use ($formula) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a formula and return found, optional grep to filter results
|
||||
*
|
||||
* @param $formula
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
function search($formula) {
|
||||
return collect(explode(PHP_EOL, $this->cli->runAsUser(
|
||||
sprintf('brew search %s', $formula),
|
||||
function ($exitCode, $errorOutput) use ($formula) {
|
||||
output($errorOutput);
|
||||
|
||||
throw new DomainException('Brew was unable to find [' . $formula . '].');
|
||||
}
|
||||
)))->filter(function ($formulaFound) {
|
||||
// Filter out empty and search category headers
|
||||
return $formulaFound && !in_array($formulaFound, ['==> Formulae', '==> Casks']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently running brew services
|
||||
*
|
||||
|
||||
@@ -141,38 +141,30 @@ function stopRunning()
|
||||
*/
|
||||
function useVersion($version)
|
||||
{
|
||||
// Ensure we have php prefixed
|
||||
if (substr($version, 0, 3) !== 'php') {
|
||||
$version = 'php' . $version;
|
||||
}
|
||||
// If passed php7.2 or php72 formats, convert to php@7.2 format:
|
||||
$version = preg_replace('/(php)([0-9+])(?:.)?([0-9+])/i', '$1@$2.$3', $version);
|
||||
|
||||
info(sprintf('Finding brew formula for: %s', $version));
|
||||
$foundVersion = $this->brew->search($version)
|
||||
->first(function ($service) {
|
||||
return $this->brew->supportedPhpVersions()->contains($service);
|
||||
});
|
||||
|
||||
if (is_null($foundVersion)) {
|
||||
if (!$this->brew->supportedPhpVersions()->contains($version)) {
|
||||
throw new DomainException(
|
||||
sprintf('Valet can\'t find a supported version of PHP for: %s', $version)
|
||||
sprintf('Valet doesnn\'t support PHP version: %s', $version)
|
||||
);
|
||||
}
|
||||
|
||||
info(sprintf('Found brew formula: %s', $foundVersion));
|
||||
// Install the relevant formula if not already installed
|
||||
$this->brew->ensureInstalled($version);
|
||||
|
||||
// Unlink the current php if there is one
|
||||
if ($this->brew->hasLinkedPhp()) {
|
||||
$currentVersion = $this->brew->linkedPhp();
|
||||
info(sprintf('Unlinking current version: %s', $currentVersion));
|
||||
$this->brew->unlink($currentVersion);
|
||||
}
|
||||
|
||||
$this->brew->ensureInstalled($foundVersion);
|
||||
|
||||
info(sprintf('Linking new version: %s', $foundVersion));
|
||||
$this->brew->link($foundVersion, true);
|
||||
info(sprintf('Linking new version: %s', $version));
|
||||
$this->brew->link($version, true);
|
||||
|
||||
$this->install();
|
||||
|
||||
return $foundVersion;
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user