mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 16:40:05 +01:00
stop running php and search brew for php to verify can install it before trying the wrong formula, todos for tests
This commit is contained in:
committed by
Matt Stauffer
parent
28748baa80
commit
25c4fab2b4
@@ -289,7 +289,7 @@ function ($exitCode, $errorOutput) use ($formula) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for a formula
|
* Search for a formula and return found, optional grep to filter results
|
||||||
*
|
*
|
||||||
* @param $formula
|
* @param $formula
|
||||||
* @param null $grep
|
* @param null $grep
|
||||||
@@ -297,13 +297,33 @@ function ($exitCode, $errorOutput) use ($formula) {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function search($formula, $grep = null) {
|
function search($formula, $grep = null) {
|
||||||
return $this->cli->runAsUser(
|
return str_replace(PHP_EOL, '', $this->cli->runAsUser(
|
||||||
sprintf('brew search %s%s', $formula, $grep ? ' | grep ' . $formula : ''),
|
sprintf('brew search %s%s', $formula, $grep ? ' | grep ' . $grep : ''),
|
||||||
function ($exitCode, $errorOutput) use ($formula) {
|
function ($exitCode, $errorOutput) use ($formula) {
|
||||||
output($errorOutput);
|
output($errorOutput);
|
||||||
|
|
||||||
throw new DomainException('Brew was unable to find [' . $formula . '].');
|
throw new DomainException('Brew was unable to find [' . $formula . '].');
|
||||||
}
|
}
|
||||||
);
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the currently running brew services
|
||||||
|
*
|
||||||
|
* @param null $grep
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
function getRunningServices($grep = null)
|
||||||
|
{
|
||||||
|
$grep = 'started' . ($grep ? '.*' . $grep : '');
|
||||||
|
|
||||||
|
return collect(array_filter(explode(PHP_EOL, $this->cli->runAsUser(
|
||||||
|
sprintf('brew services list | grep %s | awk \'{ print $1; }\'', $grep),
|
||||||
|
function ($exitCode, $errorOutput) {
|
||||||
|
output($errorOutput);
|
||||||
|
|
||||||
|
throw new DomainException('Brew was unable to check which services are running.');
|
||||||
|
}
|
||||||
|
))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,6 +121,16 @@ function fpmConfigPath()
|
|||||||
: "/usr/local/etc/php/${versionNormalized}/php-fpm.d/www.conf";
|
: "/usr/local/etc/php/${versionNormalized}/php-fpm.d/www.conf";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only stop running php services
|
||||||
|
*/
|
||||||
|
function stopRunning()
|
||||||
|
{
|
||||||
|
$this->brew->stopService(
|
||||||
|
$this->brew->getRunningServices('php')->all()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function useVersion($version)
|
function useVersion($version)
|
||||||
{
|
{
|
||||||
// Ensure we have php{version}
|
// Ensure we have php{version}
|
||||||
@@ -128,11 +138,13 @@ function useVersion($version)
|
|||||||
$version = 'php' . $version;
|
$version = 'php' . $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
$foundResult = $this->brew->search($version, 'php');
|
info(sprintf('Finding brew formula for: %s', $version));
|
||||||
|
$foundVersion = $this->brew->search($version, 'php');
|
||||||
|
info(sprintf('Found brew formula: %s', $foundVersion));
|
||||||
|
|
||||||
if (!$this->brew->supportedPhpVersions()->contains($version)) {
|
if (!$this->brew->supportedPhpVersions()->contains($foundVersion)) {
|
||||||
throw new DomainException(
|
throw new DomainException(
|
||||||
sprintf('Valet doesn\'t support PHP version: %s', $version)
|
sprintf('Valet doesn\'t support PHP version: %s', $foundVersion)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,10 +154,10 @@ function useVersion($version)
|
|||||||
$this->brew->unlink($currentVersion);
|
$this->brew->unlink($currentVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->brew->ensureInstalled($version);
|
$this->brew->ensureInstalled($foundVersion);
|
||||||
|
|
||||||
info(sprintf('Linking new version: %s', $version));
|
info(sprintf('Linking new version: %s', $foundVersion));
|
||||||
$this->brew->link($version, true);
|
$this->brew->link($foundVersion, true);
|
||||||
|
|
||||||
$this->install();
|
$this->install();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -280,7 +280,7 @@
|
|||||||
* Allow the user to use another version of php
|
* Allow the user to use another version of php
|
||||||
*/
|
*/
|
||||||
$app->command('use phpVersion', function ($phpVersion = null) {
|
$app->command('use phpVersion', function ($phpVersion = null) {
|
||||||
PhpFpm::stop();
|
PhpFpm::stopRunning();
|
||||||
|
|
||||||
PhpFpm::useVersion($phpVersion);
|
PhpFpm::useVersion($phpVersion);
|
||||||
|
|
||||||
|
|||||||
@@ -336,4 +336,10 @@ public function test_unlink_will_pass_formula_to_run_as_user()
|
|||||||
swap(CommandLine::class, $cli);
|
swap(CommandLine::class, $cli);
|
||||||
$this->assertSame('Some output', resolve(Brew::class)->unlink('aformula'));
|
$this->assertSame('Some output', resolve(Brew::class)->unlink('aformula'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: search will pass to brew search
|
||||||
|
// TODO: search will pass into grep if passed
|
||||||
|
// TODO: search will throw if fails
|
||||||
|
// TODO: getRunningServices will return array of services currently started
|
||||||
|
// TODO: getRunningServices can pass grep to filter result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,15 @@ public function test_fpm_is_configured_with_the_correct_user_group_and_port()
|
|||||||
$this->assertContains("\nlisten = ".VALET_HOME_PATH."/valet.sock", $contents);
|
$this->assertContains("\nlisten = ".VALET_HOME_PATH."/valet.sock", $contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: useVersion
|
// TODO: useVersion if no php at start it will prefix
|
||||||
|
// TODO: useVersion will pass version to Brew::search and then check if it's supported
|
||||||
|
// TODO: - if not supported will through
|
||||||
|
// TODO: useVersion if already linked php will unlink it
|
||||||
|
// TODO: useVersion will ensure new version is installed
|
||||||
|
// TODO: useVersion will link found version (force)
|
||||||
|
// TODO: useVersion will call install at end
|
||||||
|
|
||||||
|
// TODO: stopRunning will get the running php services and stop them
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user