mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 08:30:07 +01:00
wip
This commit is contained in:
@@ -312,36 +312,45 @@ public function getPhpBinaryPath($phpVersion = null)
|
|||||||
return BREW_PREFIX.'/bin/php';
|
return BREW_PREFIX.'/bin/php';
|
||||||
}
|
}
|
||||||
|
|
||||||
$versionInteger = preg_replace('~[^\d]~', '', $phpVersion);
|
|
||||||
$phpBinaryPath = null;
|
$phpBinaryPath = null;
|
||||||
$symlinkedPath = BREW_PREFIX. "/bin/valetphp{$versionInteger}";
|
$versionInteger = preg_replace('~[^\d]~', '', $phpVersion);
|
||||||
|
$symlinkedValetPhpPath = BREW_PREFIX. "/bin/valetphp{$versionInteger}";
|
||||||
|
|
||||||
if ($this->files->isLink($symlinkedPath)) {
|
// If the symlinked valet php path exists, then we can use that
|
||||||
$phpBinaryPath = $this->files->readLink($symlinkedPath);
|
if ($this->files->isLink($symlinkedValetPhpPath)) {
|
||||||
|
$phpBinaryPath = $this->files->readLink($symlinkedValetPhpPath);
|
||||||
|
|
||||||
|
// Still make sure that the version of the binrary exists
|
||||||
if ($this->files->exists($phpBinaryPath)) {
|
if ($this->files->exists($phpBinaryPath)) {
|
||||||
return $symlinkedPath;
|
return $symlinkedValetPhpPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cellar = $this->cli->runAsUser("brew --cellar $phpVersion");
|
// If the symlinked valet php path doesn't exist, then we need to look for the correct binary path
|
||||||
|
$cellar = $this->cli->runAsUser("brew --cellar $phpVersion"); // Example output: `/opt/homebrew/Cellar/php@8.0`
|
||||||
$details = json_decode($this->cli->runAsUser("brew info --json $phpVersion"));
|
$details = json_decode($this->cli->runAsUser("brew info --json $phpVersion"));
|
||||||
|
|
||||||
$phpDirectory = !empty($details[0]->linked_keg) ? $details[0]->linked_keg : $details[0]->installed[0]->version;
|
if (!empty($details[0]->linked_keg)) {
|
||||||
|
$phpDirectory = $details[0]->linked_keg;
|
||||||
|
} elseif (!empty($details[0]->installed[0]->version)) {
|
||||||
|
$phpDirectory = $details[0]->installed[0]->version;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->files->exists(trim($cellar).'/'.$phpDirectory.'/bin/php')) {
|
if (isset($phpDirectory) && $this->files->exists(trim($cellar).'/'.$phpDirectory.'/bin/php')) {
|
||||||
$phpBinaryPath = trim($cellar).'/'.$phpDirectory.'/bin/php';
|
$phpBinaryPath = trim($cellar).'/'.$phpDirectory.'/bin/php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When PHP Version is installed directly though shivammathur/homebrew-php, it usually stores the binaries in this directory
|
||||||
if (is_null($phpBinaryPath) && $this->files->exists(BREW_PREFIX."/opt/{$phpVersion}/bin/php")) {
|
if (is_null($phpBinaryPath) && $this->files->exists(BREW_PREFIX."/opt/{$phpVersion}/bin/php")) {
|
||||||
$phpBinaryPath = BREW_PREFIX."/opt/{$phpVersion}/bin/php";
|
$phpBinaryPath = BREW_PREFIX."/opt/{$phpVersion}/bin/php";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a symlink to the valet php version, so next time valet won't have to look for the binary path
|
||||||
if($phpBinaryPath){
|
if($phpBinaryPath){
|
||||||
$this->files->symlinkAsUser($phpBinaryPath, $symlinkedPath);
|
$this->files->symlinkAsUser($phpBinaryPath, $symlinkedValetPhpPath);
|
||||||
return $phpBinaryPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return BREW_PREFIX.'/bin/php';
|
return $phpBinaryPath ?: BREW_PREFIX.'/bin/php';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -565,7 +565,7 @@
|
|||||||
* Get PHP Birnary
|
* Get PHP Birnary
|
||||||
*/
|
*/
|
||||||
$app->command('which-php [site]', function ($site = null) {
|
$app->command('which-php [site]', function ($site = null) {
|
||||||
$host = Site::host($site ? $site : getcwd()).'.'.Configuration::read()['tld'];
|
$host = Site::host($site ?: getcwd()).'.'.Configuration::read()['tld'];
|
||||||
$phpVersion = Site::customPhpVersion($host);
|
$phpVersion = Site::customPhpVersion($host);
|
||||||
|
|
||||||
if(! $phpVersion){
|
if(! $phpVersion){
|
||||||
@@ -576,6 +576,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$phpVersion = $phpVersion ? PhpFpm::normalizePhpVersion($phpVersion) : null;
|
$phpVersion = $phpVersion ? PhpFpm::normalizePhpVersion($phpVersion) : null;
|
||||||
|
|
||||||
return output(Brew::getPhpBinaryPath($phpVersion));
|
return output(Brew::getPhpBinaryPath($phpVersion));
|
||||||
})->descriptions('Get the PHP binary path for a given site', [
|
})->descriptions('Get the PHP binary path for a given site', [
|
||||||
'site' => 'The site to get the PHP binary path for',
|
'site' => 'The site to get the PHP binary path for',
|
||||||
|
|||||||
@@ -395,6 +395,23 @@ public function test_restart_linked_php_will_pass_through_linked_php_formula_to_
|
|||||||
$brewMock->restartLinkedPhp();
|
$brewMock->restartLinkedPhp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_can_get_php_binary_path_from_php_version()
|
||||||
|
{
|
||||||
|
$cli = Mockery::mock(CommandLine::class);
|
||||||
|
$cli->shouldReceive('runAsUser')->once()->with('brew info php@7.4 --json')
|
||||||
|
->andReturn('[{"name":"php@7.4","full_name":"php@7.4","aliases":[],"versioned_formulae":[],"versions":{"stable":"7.4.5"},"installed":[{"version":"7.4.5"}]}]');
|
||||||
|
swap(CommandLine::class, $cli);
|
||||||
|
|
||||||
|
dd(resolve(Brew::class)->getPhpBinaryPath('php@7.4'));
|
||||||
|
|
||||||
|
// $cli = Mockery::mock(CommandLine::class);
|
||||||
|
// $cli->shouldReceive('runAsUser')->once()->with('brew info php --json')
|
||||||
|
// ->andReturn('[{"name":"php","full_name":"php","aliases":["php@8.0"],"versioned_formulae":[],"versions":{"stable":"8.0.0"},"installed":[{"version":"8.0.0"}]}]');
|
||||||
|
// swap(CommandLine::class, $cli);
|
||||||
|
// $this->assertTrue(resolve(Brew::class)->installed('php'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider of php links and their expected split matches.
|
* Provider of php links and their expected split matches.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user