mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 08:30:07 +01:00
Install older PHP versions via alternate tap
Fixes #1407 Homebrew's support policy now aggressively disables older versions earlier than it did previously. That is why we tap the `shivammathur/php` repository. But since Homebrew also now "keeps" those old formulae but marks them as disabled, when Valet runs `brew install php@7.4` it fails because Homebrew just aborts due to its flags in the outdated formula. (They mark it as "disabled" and/or "keg_only :versioned_formula", but don't actually delete the formula from their repository.) To override that we must use `brew install shivammathur/php/php@7.4` internally. Therefore, we need to maintain a list of which PHP Versions we wish to specifically prefix with the `shivammathur/php` tap in order to bypass Homebrew's flags. **ANNUAL MAINTENANCE** 1. This PR adds the array of `LIMITED_PHP_VERSIONS` which we will have to update annually when new PHP versions are retired as others are released. 2. We should also annually update the `LATEST_PHP_VERSION` string.
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
class Brew
|
class Brew
|
||||||
{
|
{
|
||||||
|
// This is the array of PHP versions that Valet will attempt to install/configure when requested
|
||||||
const SUPPORTED_PHP_VERSIONS = [
|
const SUPPORTED_PHP_VERSIONS = [
|
||||||
'php',
|
'php',
|
||||||
'php@8.2',
|
'php@8.2',
|
||||||
@@ -19,9 +20,22 @@ class Brew
|
|||||||
'php@7.1',
|
'php@7.1',
|
||||||
];
|
];
|
||||||
|
|
||||||
const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1';
|
// Update this LATEST and the following LIMITED array when PHP versions are released or retired
|
||||||
|
// We specify a numbered version here even though Homebrew links its generic 'php' alias to it
|
||||||
|
const LATEST_PHP_VERSION = 'php@8.2';
|
||||||
|
|
||||||
const LATEST_PHP_VERSION = 'php@8.1';
|
// These are the PHP versions that should be installed via the shivammathur/php tap because
|
||||||
|
// Homebrew officially no longer bottles them or they're marked disabled in their formula
|
||||||
|
// Cue: Homebrew reports "php@7.4 has been disabled because it is a versioned formula"
|
||||||
|
const LIMITED_PHP_VERSIONS = [
|
||||||
|
'php@8.0',
|
||||||
|
'php@7.4',
|
||||||
|
'php@7.3',
|
||||||
|
'php@7.2',
|
||||||
|
'php@7.1',
|
||||||
|
];
|
||||||
|
|
||||||
|
const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1';
|
||||||
|
|
||||||
public function __construct(public CommandLine $cli, public Filesystem $files)
|
public function __construct(public CommandLine $cli, public Filesystem $files)
|
||||||
{
|
{
|
||||||
@@ -72,6 +86,14 @@ public function supportedPhpVersions(): Collection
|
|||||||
return collect(static::SUPPORTED_PHP_VERSIONS);
|
return collect(static::SUPPORTED_PHP_VERSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of disabled/limited PHP versions.
|
||||||
|
*/
|
||||||
|
public function limitedPhpVersions(): Collection
|
||||||
|
{
|
||||||
|
return collect(static::LIMITED_PHP_VERSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of installed PHP formulae.
|
* Get a list of installed PHP formulae.
|
||||||
*/
|
*/
|
||||||
@@ -135,7 +157,9 @@ public function installOrFail(string $formula, array $options = [], array $taps
|
|||||||
}
|
}
|
||||||
|
|
||||||
output('<info>['.$formula.'] is not installed, installing it now via Brew...</info> 🍻');
|
output('<info>['.$formula.'] is not installed, installing it now via Brew...</info> 🍻');
|
||||||
if ($formula !== 'php' && starts_with($formula, 'php') && preg_replace('/[^\d]/', '', $formula) < '73') {
|
|
||||||
|
if ($this->limitedPhpVersions()->contains($formula)) {
|
||||||
|
$formula = 'shivammathur/php/' . $formula;
|
||||||
warning('Note: older PHP versions may take 10+ minutes to compile from source. Please wait ...');
|
warning('Note: older PHP versions may take 10+ minutes to compile from source. Please wait ...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -203,6 +203,22 @@ public function test_linked_php_throws_exception_if_unsupported_php_version_is_l
|
|||||||
resolve(Brew::class)->linkedPhp();
|
resolve(Brew::class)->linkedPhp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_outdated_php_versions_use_the_alternate_tap()
|
||||||
|
{
|
||||||
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
|
$cli = Mockery::mock(CommandLine::class),
|
||||||
|
Mockery::mock(Filesystem::class),
|
||||||
|
])->makePartial();
|
||||||
|
|
||||||
|
$brewMock->shouldReceive('limitedPhpVersions')->andReturn(collect([
|
||||||
|
'php@7.0',
|
||||||
|
]));
|
||||||
|
|
||||||
|
$cli->shouldReceive('runAsUser')->once()->with(Brew::BREW_DISABLE_AUTO_CLEANUP.' brew install shivammathur/php/php@7.0', Mockery::type('Closure'));
|
||||||
|
|
||||||
|
$brewMock->installOrFail('php@7.0');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_install_or_fail_will_install_brew_formulae()
|
public function test_install_or_fail_will_install_brew_formulae()
|
||||||
{
|
{
|
||||||
$cli = Mockery::mock(CommandLine::class);
|
$cli = Mockery::mock(CommandLine::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user