1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 16:40:05 +01:00

Refactor to collections

This commit is contained in:
Adam Wathan
2017-06-22 07:34:51 -04:00
parent ba746e37fb
commit 84ade711b6
2 changed files with 45 additions and 22 deletions

View File

@@ -40,9 +40,19 @@ function installed($formula)
*/
function hasInstalledPhp()
{
return $this->installed('php71')
|| $this->installed('php70')
|| $this->installed('php56');
return $this->supportedPhpVersions()->contains(function ($version) {
return $this->installed($version);
});
}
/**
* Get a list of supported PHP versions
*
* @return \Illuminate\Support\Collection
*/
function supportedPhpVersions()
{
return collect(['php72', 'php71', 'php70', 'php56']);
}
/**
@@ -171,15 +181,11 @@ function linkedPhp()
$resolvedPath = $this->files->readLink('/usr/local/bin/php');
// Check all currently supported PHP versions
$phpVersions = ['php72', 'php71', 'php70', 'php56'];
foreach ($phpVersions as $version) {
if (strpos($resolvedPath, $version) !== false) {
return $version;
}
}
throw new DomainException("Unable to determine linked PHP.");
return $this->supportedPhpVersions()->first(function ($version) use ($resolvedPath) {
return strpos($resolvedPath, $version) !== false;
}, function () {
throw new DomainException("Unable to determine linked PHP.");
});
}
/**