Skip to content

Commit 228b6eb

Browse files
authored
Merge pull request #1411 from drbyte/install-via-alt-tap
Install older PHP versions via alternate tap
2 parents a6f0c64 + 615d61d commit 228b6eb

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

cli/Valet/Brew.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class Brew
1010
{
11+
// This is the array of PHP versions that Valet will attempt to install/configure when requested
1112
const SUPPORTED_PHP_VERSIONS = [
1213
'php',
1314
@@ -19,9 +20,22 @@ class Brew
1920
2021
];
2122

22-
const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1';
23+
// Update this LATEST and the following LIMITED array when PHP versions are released or retired
24+
// We specify a numbered version here even though Homebrew links its generic 'php' alias to it
25+
const LATEST_PHP_VERSION = '[email protected]';
2326

24-
const LATEST_PHP_VERSION = '[email protected]';
27+
// These are the PHP versions that should be installed via the shivammathur/php tap because
28+
// Homebrew officially no longer bottles them or they're marked disabled in their formula
29+
// Cue: Homebrew reports "[email protected] has been disabled because it is a versioned formula"
30+
const LIMITED_PHP_VERSIONS = [
31+
32+
33+
34+
35+
36+
];
37+
38+
const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1';
2539

2640
public function __construct(public CommandLine $cli, public Filesystem $files)
2741
{
@@ -72,6 +86,14 @@ public function supportedPhpVersions(): Collection
7286
return collect(static::SUPPORTED_PHP_VERSIONS);
7387
}
7488

89+
/**
90+
* Get a list of disabled/limited PHP versions.
91+
*/
92+
public function limitedPhpVersions(): Collection
93+
{
94+
return collect(static::LIMITED_PHP_VERSIONS);
95+
}
96+
7597
/**
7698
* Get a list of installed PHP formulae.
7799
*/
@@ -135,7 +157,9 @@ public function installOrFail(string $formula, array $options = [], array $taps
135157
}
136158

137159
output('<info>['.$formula.'] is not installed, installing it now via Brew...</info> 🍻');
138-
if ($formula !== 'php' && starts_with($formula, 'php') && preg_replace('/[^\d]/', '', $formula) < '73') {
160+
161+
if ($this->limitedPhpVersions()->contains($formula)) {
162+
$formula = 'shivammathur/php/' . $formula;
139163
warning('Note: older PHP versions may take 10+ minutes to compile from source. Please wait ...');
140164
}
141165

tests/BrewTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ public function test_linked_php_throws_exception_if_unsupported_php_version_is_l
203203
resolve(Brew::class)->linkedPhp();
204204
}
205205

206+
public function test_outdated_php_versions_use_the_alternate_tap()
207+
{
208+
$brewMock = Mockery::mock(Brew::class, [
209+
$cli = Mockery::mock(CommandLine::class),
210+
Mockery::mock(Filesystem::class),
211+
])->makePartial();
212+
213+
$brewMock->shouldReceive('limitedPhpVersions')->andReturn(collect([
214+
215+
]));
216+
217+
$cli->shouldReceive('runAsUser')->once()->with(Brew::BREW_DISABLE_AUTO_CLEANUP.' brew install shivammathur/php/[email protected]', Mockery::type('Closure'));
218+
219+
$brewMock->installOrFail('[email protected]');
220+
}
221+
206222
public function test_install_or_fail_will_install_brew_formulae()
207223
{
208224
$cli = Mockery::mock(CommandLine::class);

0 commit comments

Comments
 (0)