-
Notifications
You must be signed in to change notification settings - Fork 703
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Last year's Homebrew's PHP packaging changes altered their version numbering strategy. Now that their changes appear to have stabilized, Valet also needs some updates to match. The `linkedPhp()` function was parsing the symlinked directory name for where the php binaries are stored, but that numbering strategy has morphed over time. This PR changes the logic to accommodate the most common directory naming strategies I can find, including those of older installs. I've included some examples of these names in code comments for future reference since finding a variety of them can be complicated.
- Loading branch information
1 parent
7dd06db
commit 83b1b2c
Showing
2 changed files
with
39 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,17 +192,28 @@ function stopService($services) | |
function linkedPhp() | ||
{ | ||
if (! $this->files->isLink('/usr/local/bin/php')) { | ||
throw new DomainException("Unable to determine linked PHP."); | ||
throw new DomainException("Homebrew PHP appears not to be linked."); | ||
} | ||
|
||
$resolvedPath = $this->files->readLink('/usr/local/bin/php'); | ||
|
||
return $this->supportedPhpVersions()->first(function ($version) use ($resolvedPath) { | ||
$resolvedPathNormalized= preg_replace('/([@|\.])/', '', $resolvedPath); | ||
$versionNormalized = preg_replace('/([@|\.])/', '', $version); | ||
return strpos($resolvedPathNormalized, "/$versionNormalized/") !== false; | ||
}, function () { | ||
throw new DomainException("Unable to determine linked PHP."); | ||
/** | ||
* Typical homebrew path resolutions are like: | ||
* "../Cellar/[email protected]/7.2.13/bin/php" | ||
* or older styles: | ||
* "../Cellar/php/7.2.9_2/bin/php | ||
* "../Cellar/php55/bin/php | ||
*/ | ||
preg_match('~\w{3,}/(php)(@?\d\.?\d)?/(\d\.\d)?([_\d\.]*)?/?\w{3,}~', $resolvedPath, $matches); | ||
$resolvedPhpVersion = $matches[3] ?: $matches[2]; | ||
|
||
return $this->supportedPhpVersions()->first( | ||
function ($version) use ($resolvedPhpVersion) { | ||
$resolvedVersionNormalized = preg_replace('/[^\d]/', '', $resolvedPhpVersion); | ||
$versionNormalized = preg_replace('/[^\d]/', '', $version); | ||
return $resolvedVersionNormalized === $versionNormalized; | ||
}, function () use ($resolvedPhpVersion) { | ||
throw new DomainException("Unable to determine linked PHP when parsing '$resolvedPhpVersion'"); | ||
}); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,9 +174,27 @@ public function test_linked_php_returns_linked_php_formula_name() | |
{ | ||
$files = Mockery::mock(Filesystem::class); | ||
$files->shouldReceive('isLink')->once()->with('/usr/local/bin/php')->andReturn(true); | ||
$files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php71/test'); | ||
$files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php/7.3.0/test'); | ||
swap(Filesystem::class, $files); | ||
$this->assertSame('[email protected]', resolve(Brew::class)->linkedPhp()); | ||
$this->assertSame('[email protected]', resolve(Brew::class)->linkedPhp()); | ||
|
||
$files = Mockery::mock(Filesystem::class); | ||
$files->shouldReceive('isLink')->once()->with('/usr/local/bin/php')->andReturn(true); | ||
$files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/[email protected]/7.2.13/test'); | ||
swap(Filesystem::class, $files); | ||
$this->assertSame('[email protected]', resolve(Brew::class)->linkedPhp()); | ||
|
||
$files = Mockery::mock(Filesystem::class); | ||
$files->shouldReceive('isLink')->once()->with('/usr/local/bin/php')->andReturn(true); | ||
$files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php/7.2.9_2/test'); | ||
swap(Filesystem::class, $files); | ||
$this->assertSame('[email protected]', resolve(Brew::class)->linkedPhp()); | ||
|
||
$files = Mockery::mock(Filesystem::class); | ||
$files->shouldReceive('isLink')->once()->with('/usr/local/bin/php')->andReturn(true); | ||
$files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php72/7.2.9_2/test'); | ||
swap(Filesystem::class, $files); | ||
$this->assertSame('[email protected]', resolve(Brew::class)->linkedPhp()); | ||
|
||
$files = Mockery::mock(Filesystem::class); | ||
$files->shouldReceive('isLink')->once()->with('/usr/local/bin/php')->andReturn(true); | ||
|
@@ -205,7 +223,7 @@ public function test_linked_php_throws_exception_if_unsupported_php_version_is_l | |
{ | ||
$files = Mockery::mock(Filesystem::class); | ||
$files->shouldReceive('isLink')->once()->with('/usr/local/bin/php')->andReturn(true); | ||
$files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php42/test'); | ||
$files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php/5.4.14/test'); | ||
swap(Filesystem::class, $files); | ||
resolve(Brew::class)->linkedPhp(); | ||
} | ||
|