1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 16:10:08 +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:
James Barnard
2019-01-19 22:07:56 +00:00
committed by Matt Stauffer
parent 28748baa80
commit 25c4fab2b4
5 changed files with 58 additions and 12 deletions

View File

@@ -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 null $grep
@@ -297,13 +297,33 @@ function ($exitCode, $errorOutput) use ($formula) {
* @return string
*/
function search($formula, $grep = null) {
return $this->cli->runAsUser(
sprintf('brew search %s%s', $formula, $grep ? ' | grep ' . $formula : ''),
return str_replace(PHP_EOL, '', $this->cli->runAsUser(
sprintf('brew search %s%s', $formula, $grep ? ' | grep ' . $grep : ''),
function ($exitCode, $errorOutput) use ($formula) {
output($errorOutput);
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.');
}
))));
}
}

View File

@@ -121,6 +121,16 @@ function fpmConfigPath()
: "/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)
{
// Ensure we have php{version}
@@ -128,11 +138,13 @@ function useVersion($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(
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->ensureInstalled($version);
$this->brew->ensureInstalled($foundVersion);
info(sprintf('Linking new version: %s', $version));
$this->brew->link($version, true);
info(sprintf('Linking new version: %s', $foundVersion));
$this->brew->link($foundVersion, true);
$this->install();
}

View File

@@ -280,7 +280,7 @@
* Allow the user to use another version of php
*/
$app->command('use phpVersion', function ($phpVersion = null) {
PhpFpm::stop();
PhpFpm::stopRunning();
PhpFpm::useVersion($phpVersion);

View File

@@ -336,4 +336,10 @@ public function test_unlink_will_pass_formula_to_run_as_user()
swap(CommandLine::class, $cli);
$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
}

View File

@@ -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);
}
// 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
}