1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 08:10:07 +01:00

Modify the paths of packages to be based on brew prefix

- brew
- dnsmasq
- nginx
- php-fpm
- log
- etc
This commit is contained in:
soilSpoon
2020-11-15 14:38:18 +09:00
parent e64d5d877b
commit 2c06a5d4f0
10 changed files with 39 additions and 39 deletions

View File

@@ -202,7 +202,7 @@ function stopService($services)
*/
function hasLinkedPhp()
{
return $this->files->isLink(PHP_BINARY_PATH);
return $this->files->isLink(BREW_PREFIX.'/bin/php');
}
/**
@@ -216,7 +216,7 @@ function getParsedLinkedPhp()
throw new DomainException("Homebrew PHP appears not to be linked.");
}
$resolvedPath = $this->files->readLink(PHP_BINARY_PATH);
$resolvedPath = $this->files->readLink(BREW_PREFIX.'/bin/php');
/**
* Typical homebrew path resolutions are like:
@@ -283,7 +283,7 @@ function createSudoersEntry()
{
$this->files->ensureDirExists('/etc/sudoers.d');
$this->files->put('/etc/sudoers.d/brew', 'Cmnd_Alias BREW = /usr/local/bin/brew *
$this->files->put('/etc/sudoers.d/brew', 'Cmnd_Alias BREW = '.BREW_PREFIX.'/bin/brew *
%admin ALL=(root) NOPASSWD:SETENV: BREW'.PHP_EOL);
}
@@ -375,7 +375,7 @@ function uninstallAllPhpVersions()
function uninstallFormula($formula)
{
$this->cli->runAsUser('brew uninstall --force '.$formula);
$this->cli->run('rm -rf /usr/local/Cellar/'.$formula);
$this->cli->run('rm -rf '.BREW_PREFIX.'/Cellar/'.$formula);
}
/**

View File

@@ -35,8 +35,8 @@ class Diagnose
'openssl ciphers',
'sudo nginx -t',
'which -a php-fpm',
'/usr/local/opt/php/sbin/php-fpm -v',
'sudo /usr/local/opt/php/sbin/php-fpm -y '.PHP_SYSCONFDIR.'/php-fpm.conf --test',
BREW_PREFIX.'/opt/php/sbin/php-fpm -v',
'sudo '.BREW_PREFIX.'/opt/php/sbin/php-fpm -y '.PHP_SYSCONFDIR.'/php-fpm.conf --test',
'ls -al ~/Library/LaunchAgents | grep homebrew',
'ls -al /Library/LaunchAgents | grep homebrew',
'ls -al /Library/LaunchDaemons | grep homebrew',

View File

@@ -6,8 +6,8 @@ class DnsMasq
{
var $brew, $cli, $files, $configuration;
var $dnsmasqMasterConfigFile = '/usr/local/etc/dnsmasq.conf';
var $dnsmasqSystemConfDir = '/usr/local/etc/dnsmasq.d';
var $dnsmasqMasterConfigFile = BREW_PREFIX.'/etc/dnsmasq.conf';
var $dnsmasqSystemConfDir = BREW_PREFIX.'/etc/dnsmasq.d';
var $resolverPath = '/etc/resolver';
/**
@@ -53,7 +53,7 @@ function uninstall()
{
$this->brew->stopService('dnsmasq');
$this->brew->uninstallFormula('dnsmasq');
$this->cli->run('rm -rf /usr/local/etc/dnsmasq.d/dnsmasq-valet.conf');
$this->cli->run('rm -rf '.BREW_PREFIX.'/etc/dnsmasq.d/dnsmasq-valet.conf');
$tld = $this->configuration->read()['tld'];
$this->files->unlink($this->resolverPath.'/'.$tld);
}
@@ -80,10 +80,10 @@ function ensureUsingDnsmasqDForConfigs()
// set primary config to look for configs in /usr/local/etc/dnsmasq.d/*.conf
$contents = $this->files->get($this->dnsmasqMasterConfigFile);
// ensure the line we need to use is present, and uncomment it if needed
if (false === strpos($contents, 'conf-dir=/usr/local/etc/dnsmasq.d/,*.conf')) {
$contents .= PHP_EOL . 'conf-dir=/usr/local/etc/dnsmasq.d/,*.conf' . PHP_EOL;
if (false === strpos($contents, 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf')) {
$contents .= PHP_EOL . 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf' . PHP_EOL;
}
$contents = str_replace('#conf-dir=/usr/local/etc/dnsmasq.d/,*.conf', 'conf-dir=/usr/local/etc/dnsmasq.d/,*.conf', $contents);
$contents = str_replace('#conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf', 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf', $contents);
// remove entries used by older Valet versions:
$contents = preg_replace('/^conf-file.*valet.*$/m', '', $contents);

View File

@@ -11,7 +11,7 @@ class Nginx
var $files;
var $configuration;
var $site;
const NGINX_CONF = '/usr/local/etc/nginx/nginx.conf';
const NGINX_CONF = BREW_PREFIX.'/etc/nginx/nginx.conf';
/**
* Create a new Nginx instance.
@@ -73,10 +73,10 @@ function installConfiguration()
*/
function installServer()
{
$this->files->ensureDirExists('/usr/local/etc/nginx/valet');
$this->files->ensureDirExists(BREW_PREFIX.'/etc/nginx/valet');
$this->files->putAsUser(
'/usr/local/etc/nginx/valet/valet.conf',
BREW_PREFIX.'/etc/nginx/valet/valet.conf',
str_replace(
['VALET_HOME_PATH', 'VALET_SERVER_PATH', 'VALET_STATIC_PREFIX'],
[VALET_HOME_PATH, VALET_SERVER_PATH, VALET_STATIC_PREFIX],
@@ -85,7 +85,7 @@ function installServer()
);
$this->files->putAsUser(
'/usr/local/etc/nginx/fastcgi_params',
BREW_PREFIX.'/etc/nginx/fastcgi_params',
$this->files->get(__DIR__.'/../stubs/fastcgi_params')
);
}
@@ -168,6 +168,6 @@ function uninstall()
{
$this->brew->stopService(['nginx', 'nginx-full']);
$this->brew->uninstallFormula('nginx nginx-full');
$this->cli->quietly('rm -rf /usr/local/etc/nginx /usr/local/var/log/nginx');
$this->cli->quietly('rm -rf '.BREW_PREFIX.'/etc/nginx '.BREW_PREFIX.'/var/log/nginx');
}
}

View File

@@ -53,8 +53,8 @@ function install()
function uninstall()
{
$this->brew->uninstallAllPhpVersions();
rename('/usr/local/etc/php', '/usr/local/etc/php-valet-bak'.time());
$this->cli->run('rm -rf /usr/local/var/log/php-fpm.log');
rename(BREW_PREFIX.'/etc/php', BREW_PREFIX.'/etc/php-valet-bak'.time());
$this->cli->run('rm -rf '.BREW_PREFIX.'/var/log/php-fpm.log');
}
/**
@@ -141,8 +141,8 @@ function fpmConfigPath()
);
return $versionNormalized === '5.6'
? '/usr/local/etc/php/5.6/php-fpm.conf'
: "/usr/local/etc/php/${versionNormalized}/php-fpm.d/valet-fpm.conf";
? BREW_PREFIX.'/etc/php/5.6/php-fpm.conf'
: BREW_PREFIX."/etc/php/${versionNormalized}/php-fpm.d/valet-fpm.conf";
}
/**

View File

@@ -16,7 +16,7 @@
define('VALET_LEGACY_HOME_PATH', $_SERVER['HOME'].'/.valet');
define('PHP_BINARY_PATH', (new CommandLine())->runAsUser('printf $(brew --prefix)/bin/php'));
define('BREW_PREFIX', (new CommandLine())->runAsUser('printf $(brew --prefix)'));
/**
* Output the given text to the console.

View File

@@ -401,13 +401,13 @@
<info>4. Homebrew Services</info>
<fg=red>You may remove the core services (php, nginx, dnsmasq) by running:</> <comment>brew uninstall --force php nginx dnsmasq</comment>
<fg=red>You can then remove selected leftover configurations for these services manually</> in both <comment>/usr/local/etc/</comment> and <comment>/usr/local/logs/</comment>.
<fg=red>You can then remove selected leftover configurations for these services manually</> in both <comment>".BREW_PREFIX."/etc/</comment> and <comment>".BREW_PREFIX."/logs/</comment>.
(If you have other PHP versions installed, run <info>brew list | grep php</info> to see which versions you should also uninstall manually.)
<error>BEWARE:</error> Uninstalling PHP via Homebrew will leave your Mac with its original PHP version, which may not be compatible with other Composer dependencies you have installed. Thus you may get unexpected errors.
Some additional services which you may have installed (but which Valet does not directly configure or manage) include: <comment>mariadb mysql mailhog</comment>.
If you wish to also remove them, you may manually run <comment>brew uninstall SERVICENAME</comment> and clean up their configurations in /usr/local/etc if necessary.
If you wish to also remove them, you may manually run <comment>brew uninstall SERVICENAME</comment> and clean up their configurations in ".BREW_PREFIX."/etc if necessary.
You can discover more Homebrew services by running: <comment>brew services list</comment> and <comment>brew list</comment>
@@ -480,10 +480,10 @@
*/
$app->command('log [-f|--follow] [-l|--lines=] [key]', function ($follow, $lines, $key = null) {
$defaultLogs = [
'php-fpm' => '/usr/local/var/log/php-fpm.log',
'php-fpm' => BREW_PREFIX.'/var/log/php-fpm.log',
'nginx' => VALET_HOME_PATH.'/Log/nginx-error.log',
'mailhog' => '/usr/local/var/log/mailhog.log',
'redis' => '/usr/local/var/log/redis.log',
'mailhog' => BREW_PREFIX.'/var/log/mailhog.log',
'redis' => BREW_PREFIX.'/var/log/redis.log',
];
$configLogs = data_get(Configuration::read(), 'logs');

View File

@@ -238,27 +238,27 @@ public function test_linked_php_returns_linked_php_formula_name()
};
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php/7.4.0/test');
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/7.4.0/test');
$this->assertSame('php@7.4', $getBrewMock($files)->linkedPhp());
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php/7.3.0/test');
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/7.3.0/test');
$this->assertSame('php@7.3', $getBrewMock($files)->linkedPhp());
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php@7.2/7.2.13/test');
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php@7.2/7.2.13/test');
$this->assertSame('php@7.2', $getBrewMock($files)->linkedPhp());
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php/7.2.9_2/test');
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/7.2.9_2/test');
$this->assertSame('php@7.2', $getBrewMock($files)->linkedPhp());
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php72/7.2.9_2/test');
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php72/7.2.9_2/test');
$this->assertSame('php@7.2', $getBrewMock($files)->linkedPhp());
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php56/test');
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php56/test');
$this->assertSame('php@5.6', $getBrewMock($files)->linkedPhp());
}
@@ -277,7 +277,7 @@ public function test_linked_php_throws_exception_if_no_php_link()
public function test_has_linked_php_returns_true_if_php_link_exists()
{
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('isLink')->twice()->with(PHP_BINARY_PATH)->andReturn(false, true);
$files->shouldReceive('isLink')->twice()->with(BREW_PREFIX.'/bin/php')->andReturn(false, true);
swap(Filesystem::class, $files);
$brew = resolve(Brew::class);
@@ -292,8 +292,8 @@ public function test_has_linked_php_returns_true_if_php_link_exists()
public function test_linked_php_throws_exception_if_unsupported_php_version_is_linked()
{
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('isLink')->once()->with(PHP_BINARY_PATH)->andReturn(true);
$files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php/5.4.14/test');
$files->shouldReceive('isLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn(true);
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/5.4.14/test');
swap(Filesystem::class, $files);
resolve(Brew::class)->linkedPhp();
}
@@ -449,7 +449,7 @@ public function test_get_parsed_linked_php_will_return_matches_for_linked_php($p
};
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn($path);
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn($path);
$this->assertSame($matches, $getBrewMock($files)->getParsedLinkedPhp());
}

View File

@@ -51,7 +51,7 @@ public function test_install_installs_and_places_configuration_files_in_proper_l
$this->assertSame('nameserver 127.0.0.1'.PHP_EOL, file_get_contents(__DIR__.'/output/resolver/test'));
$this->assertSame('address=/.test/127.0.0.1'.PHP_EOL.'listen-address=127.0.0.1'.PHP_EOL, file_get_contents(__DIR__.'/output/tld-test.conf'));
$this->assertSame('test-contents
' . PHP_EOL . 'conf-dir=/usr/local/etc/dnsmasq.d/,*.conf' . PHP_EOL,
' . PHP_EOL . 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf' . PHP_EOL,
file_get_contents($dnsMasq->dnsmasqMasterConfigFile)
);
}

View File

@@ -30,7 +30,7 @@ public function test_install_nginx_configuration_places_nginx_base_configuration
$files = Mockery::mock(Filesystem::class.'[putAsUser]');
$files->shouldReceive('putAsUser')->andReturnUsing(function ($path, $contents) {
$this->assertSame('/usr/local/etc/nginx/nginx.conf', $path);
$this->assertSame(BREW_PREFIX.'/etc/nginx/nginx.conf', $path);
$this->assertContains('include "'.VALET_HOME_PATH.'/Nginx/*"', $contents);
})->once();