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

Apply fixes from StyleCI

This commit is contained in:
Taylor Otwell
2021-12-06 10:40:37 +00:00
committed by StyleCI Bot
parent 3a5d12e24d
commit 101abeae0e
35 changed files with 580 additions and 536 deletions

View File

@@ -20,12 +20,13 @@ class Brew
'php72',
'php71',
'php70',
'php56'
'php56',
];
const LATEST_PHP_VERSION = 'php@8.0';
var $cli, $files;
public $cli;
public $files;
/**
* Create a new Brew instance.
@@ -34,19 +35,19 @@ class Brew
* @param Filesystem $files
* @return void
*/
function __construct(CommandLine $cli, Filesystem $files)
public function __construct(CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->files = $files;
}
/**
* Ensure the formula exists in the current Homebrew configuration
* Ensure the formula exists in the current Homebrew configuration.
*
* @param string $formula
* @return bool
*/
function installed($formula)
public function installed($formula)
{
$result = $this->cli->runAsUser("brew info $formula --json");
@@ -57,7 +58,7 @@ function installed($formula)
$details = json_decode($result);
return !empty($details[0]->installed);
return ! empty($details[0]->installed);
}
/**
@@ -65,13 +66,13 @@ function installed($formula)
*
* @return bool
*/
function hasInstalledPhp()
public function hasInstalledPhp()
{
$installed = $this->installedPhpFormulae()->first(function ($formula) {
return $this->supportedPhpVersions()->contains($formula);
});
return !empty($installed);
return ! empty($installed);
}
/**
@@ -79,12 +80,12 @@ function hasInstalledPhp()
*
* @return \Illuminate\Support\Collection
*/
function supportedPhpVersions()
public function supportedPhpVersions()
{
return collect(static::SUPPORTED_PHP_VERSIONS);
}
function installedPhpFormulae()
public function installedPhpFormulae()
{
return collect(
explode(PHP_EOL, $this->cli->runAsUser('brew list --formula | grep php'))
@@ -92,13 +93,13 @@ function installedPhpFormulae()
}
/**
* Get the aliased formula version from Homebrew
* Get the aliased formula version from Homebrew.
*/
function determineAliasedVersion($formula)
public function determineAliasedVersion($formula)
{
$details = json_decode($this->cli->runAsUser("brew info $formula --json"));
if (!empty($details[0]->aliases[0])) {
if (! empty($details[0]->aliases[0])) {
return $details[0]->aliases[0];
}
@@ -110,7 +111,7 @@ function determineAliasedVersion($formula)
*
* @return bool
*/
function hasInstalledNginx()
public function hasInstalledNginx()
{
return $this->installed('nginx')
|| $this->installed('nginx-full');
@@ -121,7 +122,7 @@ function hasInstalledNginx()
*
* @return string
*/
function nginxServiceName()
public function nginxServiceName()
{
return $this->installed('nginx-full') ? 'nginx-full' : 'nginx';
}
@@ -134,7 +135,7 @@ function nginxServiceName()
* @param array $taps
* @return void
*/
function ensureInstalled($formula, $options = [], $taps = [])
public function ensureInstalled($formula, $options = [], $taps = [])
{
if (! $this->installed($formula)) {
$this->installOrFail($formula, $options, $taps);
@@ -149,7 +150,7 @@ function ensureInstalled($formula, $options = [], $taps = [])
* @param array $taps
* @return void
*/
function installOrFail($formula, $options = [], $taps = [])
public function installOrFail($formula, $options = [], $taps = [])
{
info("Installing {$formula}...");
@@ -175,7 +176,7 @@ function installOrFail($formula, $options = [], $taps = [])
* @param dynamic[string] $formula
* @return void
*/
function tap($formulas)
public function tap($formulas)
{
$formulas = is_array($formulas) ? $formulas : func_get_args();
@@ -189,7 +190,7 @@ function tap($formulas)
*
* @param
*/
function restartService($services)
public function restartService($services)
{
$services = is_array($services) ? $services : func_get_args();
@@ -212,7 +213,7 @@ function restartService($services)
*
* @param
*/
function stopService($services)
public function stopService($services)
{
$services = is_array($services) ? $services : func_get_args();
@@ -234,7 +235,7 @@ function stopService($services)
*
* @return bool
*/
function hasLinkedPhp()
public function hasLinkedPhp()
{
return $this->files->isLink(BREW_PREFIX.'/bin/php');
}
@@ -244,10 +245,10 @@ function hasLinkedPhp()
*
* @return mixed
*/
function getParsedLinkedPhp()
public function getParsedLinkedPhp()
{
if (! $this->hasLinkedPhp()) {
throw new DomainException("Homebrew PHP appears not to be linked. Please run [valet use php@X.Y]");
throw new DomainException('Homebrew PHP appears not to be linked. Please run [valet use php@X.Y]');
}
$resolvedPath = $this->files->readLink(BREW_PREFIX.'/bin/php');
@@ -257,7 +258,7 @@ function getParsedLinkedPhp()
* "../Cellar/php@7.4/7.4.13/bin/php"
* or older styles:
* "../Cellar/php/7.4.9_2/bin/php
* "../Cellar/php55/bin/php
* "../Cellar/php55/bin/php.
*/
preg_match('~\w{3,}/(php)(@?\d\.?\d)?/(\d\.\d)?([_\d\.]*)?/?\w{3,}~', $resolvedPath, $matches);
@@ -267,14 +268,15 @@ function getParsedLinkedPhp()
/**
* Gets the currently linked formula by identifying the symlink in the hombrew bin directory.
* Different to ->linkedPhp() in that this will just get the linked directory name,
* whether that is php, php74 or php@7.4
* whether that is php, php74 or php@7.4.
*
* @return string
*/
function getLinkedPhpFormula()
public function getLinkedPhpFormula()
{
$matches = $this->getParsedLinkedPhp();
return $matches[1] . $matches[2];
return $matches[1].$matches[2];
}
/**
@@ -282,7 +284,7 @@ function getLinkedPhpFormula()
*
* @return string
*/
function linkedPhp()
public function linkedPhp()
{
$matches = $this->getParsedLinkedPhp();
$resolvedPhpVersion = $matches[3] ?: $matches[2];
@@ -291,10 +293,11 @@ function linkedPhp()
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'");
});
}, function () use ($resolvedPhpVersion) {
throw new DomainException("Unable to determine linked PHP when parsing '$resolvedPhpVersion'");
});
}
/**
@@ -302,7 +305,7 @@ function ($version) use ($resolvedPhpVersion) {
*
* @return void
*/
function restartLinkedPhp()
public function restartLinkedPhp()
{
$this->restartService($this->getLinkedPhpFormula());
}
@@ -312,7 +315,7 @@ function restartLinkedPhp()
*
* @return void
*/
function createSudoersEntry()
public function createSudoersEntry()
{
$this->files->ensureDirExists('/etc/sudoers.d');
@@ -325,7 +328,7 @@ function createSudoersEntry()
*
* @return void
*/
function removeSudoersEntry()
public function removeSudoersEntry()
{
$this->cli->quietly('rm /etc/sudoers.d/brew');
}
@@ -334,36 +337,35 @@ function removeSudoersEntry()
* Link passed formula.
*
* @param $formula
* @param bool $force
*
* @param bool $force
* @return string
*/
function link($formula, $force = false)
public function link($formula, $force = false)
{
return $this->cli->runAsUser(
sprintf('brew link %s%s', $formula, $force ? ' --force': ''),
sprintf('brew link %s%s', $formula, $force ? ' --force' : ''),
function ($exitCode, $errorOutput) use ($formula) {
output($errorOutput);
throw new DomainException('Brew was unable to link [' . $formula . '].');
throw new DomainException('Brew was unable to link ['.$formula.'].');
}
);
}
/**
* Unlink passed formula.
* @param $formula
*
* @param $formula
* @return string
*/
function unlink($formula)
public function unlink($formula)
{
return $this->cli->runAsUser(
sprintf('brew unlink %s', $formula),
function ($exitCode, $errorOutput) use ($formula) {
output($errorOutput);
throw new DomainException('Brew was unable to unlink [' . $formula . '].');
throw new DomainException('Brew was unable to unlink ['.$formula.'].');
}
);
}
@@ -373,7 +375,7 @@ function ($exitCode, $errorOutput) use ($formula) {
*
* @return \Illuminate\Support\Collection
*/
function getRunningServices()
public function getRunningServices()
{
return collect(array_filter(explode(PHP_EOL, $this->cli->runAsUser(
'brew services list | grep started | awk \'{ print $1; }\'',
@@ -390,7 +392,7 @@ function ($exitCode, $errorOutput) {
*
* @return string
*/
function uninstallAllPhpVersions()
public function uninstallAllPhpVersions()
{
$this->supportedPhpVersions()->each(function ($formula) {
$this->uninstallFormula($formula);
@@ -401,11 +403,11 @@ function uninstallAllPhpVersions()
/**
* Uninstall a Homebrew app by formula name.
* @param string $formula
*
* @param string $formula
* @return void
*/
function uninstallFormula($formula)
public function uninstallFormula($formula)
{
$this->cli->runAsUser('brew uninstall --force '.$formula);
$this->cli->run('rm -rf '.BREW_PREFIX.'/Cellar/'.$formula);
@@ -416,7 +418,7 @@ function uninstallFormula($formula)
*
* @return string
*/
function cleanupBrew()
public function cleanupBrew()
{
return $this->cli->runAsUser(
'brew cleanup && brew services cleanup',

View File

@@ -12,7 +12,7 @@ class CommandLine
* @param string $command
* @return void
*/
function quietly($command)
public function quietly($command)
{
$this->runCommand($command.' > /dev/null 2>&1');
}
@@ -23,7 +23,7 @@ function quietly($command)
* @param string $command
* @return void
*/
function quietlyAsUser($command)
public function quietlyAsUser($command)
{
$this->quietly('sudo -u "'.user().'" '.$command.' > /dev/null 2>&1');
}
@@ -34,7 +34,7 @@ function quietlyAsUser($command)
* @param string $command
* @return void
*/
function passthru($command)
public function passthru($command)
{
passthru($command);
}
@@ -43,10 +43,10 @@ function passthru($command)
* Run the given command as the non-root user.
*
* @param string $command
* @param callable $onError
* @param callable $onError
* @return string
*/
function run($command, callable $onError = null)
public function run($command, callable $onError = null)
{
return $this->runCommand($command, $onError);
}
@@ -55,10 +55,10 @@ function run($command, callable $onError = null)
* Run the given command.
*
* @param string $command
* @param callable $onError
* @param callable $onError
* @return string
*/
function runAsUser($command, callable $onError = null)
public function runAsUser($command, callable $onError = null)
{
return $this->runCommand('sudo -u "'.user().'" '.$command, $onError);
}
@@ -67,12 +67,13 @@ function runAsUser($command, callable $onError = null)
* Run the given command.
*
* @param string $command
* @param callable $onError
* @param callable $onError
* @return string
*/
function runCommand($command, callable $onError = null)
public function runCommand($command, callable $onError = null)
{
$onError = $onError ?: function () {};
$onError = $onError ?: function () {
};
// Symfony's 4.x Process component has deprecated passing a command string
// to the constructor, but older versions (which Valet's Composer

View File

@@ -4,14 +4,14 @@
class Configuration
{
var $files;
public $files;
/**
* Create a new Valet configuration class instance.
*
* @param Filesystem $files
* @param Filesystem $files
*/
function __construct(Filesystem $files)
public function __construct(Filesystem $files)
{
$this->files = $files;
}
@@ -21,7 +21,7 @@ function __construct(Filesystem $files)
*
* @return void
*/
function install()
public function install()
{
$this->createConfigurationDirectory();
$this->createDriversDirectory();
@@ -39,7 +39,7 @@ function install()
*
* @return void
*/
function uninstall()
public function uninstall()
{
$this->files->unlink(VALET_HOME_PATH);
}
@@ -49,7 +49,7 @@ function uninstall()
*
* @return void
*/
function createConfigurationDirectory()
public function createConfigurationDirectory()
{
$this->files->ensureDirExists(preg_replace('~/valet$~', '', VALET_HOME_PATH), user());
@@ -68,7 +68,7 @@ function createConfigurationDirectory()
*
* @return void
*/
function createDriversDirectory()
public function createDriversDirectory()
{
if ($this->files->isDir($driversDirectory = VALET_HOME_PATH.'/Drivers')) {
return;
@@ -87,7 +87,7 @@ function createDriversDirectory()
*
* @return void
*/
function createSitesDirectory()
public function createSitesDirectory()
{
$this->files->ensureDirExists(VALET_HOME_PATH.'/Sites', user());
}
@@ -97,7 +97,7 @@ function createSitesDirectory()
*
* @return void
*/
function createExtensionsDirectory()
public function createExtensionsDirectory()
{
$this->files->ensureDirExists(VALET_HOME_PATH.'/Extensions', user());
}
@@ -107,7 +107,7 @@ function createExtensionsDirectory()
*
* @return void
*/
function createLogDirectory()
public function createLogDirectory()
{
$this->files->ensureDirExists(VALET_HOME_PATH.'/Log', user());
@@ -119,7 +119,7 @@ function createLogDirectory()
*
* @return void
*/
function createCertificatesDirectory()
public function createCertificatesDirectory()
{
$this->files->ensureDirExists(VALET_HOME_PATH.'/Certificates', user());
}
@@ -127,19 +127,19 @@ function createCertificatesDirectory()
/**
* Write the base, initial configuration for Valet.
*/
function writeBaseConfiguration()
public function writeBaseConfiguration()
{
if (! $this->files->exists($this->path())) {
$this->write(['tld' => 'test', 'loopback' => VALET_LOOPBACK, 'paths' => []]);
}
/**
* Migrate old configurations from 'domain' to 'tld'
* Migrate old configurations from 'domain' to 'tld'.
*/
$config = $this->read();
if (! isset($config['tld'])) {
$this->updateKey('tld', !empty($config['domain']) ? $config['domain'] : 'test');
$this->updateKey('tld', ! empty($config['domain']) ? $config['domain'] : 'test');
}
if (! isset($config['loopback'])) {
@@ -154,7 +154,7 @@ function writeBaseConfiguration()
* @param bool $prepend
* @return void
*/
function addPath($path, $prepend = false)
public function addPath($path, $prepend = false)
{
$this->write(tap($this->read(), function (&$config) use ($path, $prepend) {
$method = $prepend ? 'prepend' : 'push';
@@ -169,7 +169,7 @@ function addPath($path, $prepend = false)
* @param string $path
* @return void
*/
function prependPath($path)
public function prependPath($path)
{
$this->addPath($path, true);
}
@@ -180,11 +180,11 @@ function prependPath($path)
* @param string $path
* @return void
*/
function removePath($path)
public function removePath($path)
{
if ($path == VALET_HOME_PATH.'/Sites') {
info("Cannot remove this directory because this is where Valet stores its site definitions.\nRun [valet paths] for a list of parked paths.");
die();
exit();
}
$this->write(tap($this->read(), function (&$config) use ($path) {
@@ -199,7 +199,7 @@ function removePath($path)
*
* @return void
*/
function prune()
public function prune()
{
if (! $this->files->exists($this->path())) {
return;
@@ -217,7 +217,7 @@ function prune()
*
* @return array
*/
function read()
public function read()
{
return json_decode($this->files->get($this->path()), true);
}
@@ -229,7 +229,7 @@ function read()
* @param mixed $value
* @return array
*/
function updateKey($key, $value)
public function updateKey($key, $value)
{
return tap($this->read(), function (&$config) use ($key, $value) {
$config[$key] = $value;
@@ -244,7 +244,7 @@ function updateKey($key, $value)
* @param array $config
* @return void
*/
function write($config)
public function write($config)
{
$this->files->putAsUser($this->path(), json_encode(
$config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
@@ -256,7 +256,7 @@ function write($config)
*
* @return string
*/
function path()
public function path()
{
return VALET_HOME_PATH.'/config.json';
}

View File

@@ -7,7 +7,7 @@
class Diagnose
{
var $commands = [
public $commands = [
'sw_vers',
'valet --version',
'cat ~/.config/valet/config.json',
@@ -50,7 +50,10 @@ class Diagnose
'sh -c \'for file in ~/.config/valet/nginx/*; do echo "------\n~/.config/valet/nginx/$(basename $file)\n---\n"; cat $file | grep -n "# valet loopback"; echo "\n------\n"; done\'',
];
var $cli, $files, $print, $progressBar;
public $cli;
public $files;
public $print;
public $progressBar;
/**
* Create a new Diagnose instance.
@@ -59,7 +62,7 @@ class Diagnose
* @param Filesystem $files
* @return void
*/
function __construct(CommandLine $cli, Filesystem $files)
public function __construct(CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->files = $files;
@@ -68,7 +71,7 @@ function __construct(CommandLine $cli, Filesystem $files)
/**
* Run diagnostics.
*/
function run($print, $plainText)
public function run($print, $plainText)
{
$this->print = $print;
@@ -79,7 +82,9 @@ function run($print, $plainText)
$output = $this->runCommand($command);
if ($this->ignoreOutput($command)) return;
if ($this->ignoreOutput($command)) {
return;
}
$this->afterCommand($command, $output);
@@ -97,7 +102,7 @@ function run($print, $plainText)
$this->afterRun();
}
function beforeRun()
public function beforeRun()
{
if ($this->print) {
return;
@@ -108,7 +113,7 @@ function beforeRun()
$this->progressBar->start();
}
function afterRun()
public function afterRun()
{
if ($this->progressBar) {
$this->progressBar->finish();
@@ -117,21 +122,21 @@ function afterRun()
output('');
}
function runCommand($command)
public function runCommand($command)
{
return strpos($command, 'sudo ') === 0
? $this->cli->run($command)
: $this->cli->runAsUser($command);
}
function beforeCommand($command)
public function beforeCommand($command)
{
if ($this->print) {
info(PHP_EOL."$ $command");
}
}
function afterCommand($command, $output)
public function afterCommand($command, $output)
{
if ($this->print) {
output(trim($output));
@@ -140,12 +145,12 @@ function afterCommand($command, $output)
}
}
function ignoreOutput($command)
public function ignoreOutput($command)
{
return strpos($command, '> /dev/null 2>&1') !== false;
}
function format($results, $plainText)
public function format($results, $plainText)
{
return $results->map(function ($result) use ($plainText) {
$command = $result['command'];

View File

@@ -4,16 +4,19 @@
class DnsMasq
{
var $brew, $cli, $files, $configuration;
public $brew;
public $cli;
public $files;
public $configuration;
var $dnsmasqMasterConfigFile = BREW_PREFIX.'/etc/dnsmasq.conf';
var $dnsmasqSystemConfDir = BREW_PREFIX.'/etc/dnsmasq.d';
var $resolverPath = '/etc/resolver';
public $dnsmasqMasterConfigFile = BREW_PREFIX.'/etc/dnsmasq.conf';
public $dnsmasqSystemConfDir = BREW_PREFIX.'/etc/dnsmasq.d';
public $resolverPath = '/etc/resolver';
/**
* Create a new DnsMasq instance.
*/
function __construct(Brew $brew, CommandLine $cli, Filesystem $files, Configuration $configuration)
public function __construct(Brew $brew, CommandLine $cli, Filesystem $files, Configuration $configuration)
{
$this->cli = $cli;
$this->brew = $brew;
@@ -26,7 +29,7 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files, Configurat
*
* @return void
*/
function install($tld = 'test')
public function install($tld = 'test')
{
$this->brew->ensureInstalled('dnsmasq');
@@ -49,7 +52,7 @@ function install($tld = 'test')
*
* @return void
*/
function uninstall()
public function uninstall()
{
$this->brew->stopService('dnsmasq');
$this->brew->uninstallFormula('dnsmasq');
@@ -59,21 +62,21 @@ function uninstall()
}
/**
* Tell Homebrew to restart dnsmasq
* Tell Homebrew to restart dnsmasq.
*
* @return void
*/
function restart()
public function restart()
{
$this->brew->restartService('dnsmasq');
}
/**
* Ensure the DnsMasq configuration primary config is set to read custom configs
* Ensure the DnsMasq configuration primary config is set to read custom configs.
*
* @return void
*/
function ensureUsingDnsmasqDForConfigs()
public function ensureUsingDnsmasqDForConfigs()
{
info('Updating Dnsmasq configuration...');
@@ -81,7 +84,7 @@ function ensureUsingDnsmasqDForConfigs()
$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='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf')) {
$contents .= PHP_EOL . 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf' . PHP_EOL;
$contents .= PHP_EOL.'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf'.PHP_EOL;
}
$contents = str_replace('#conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf', 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf', $contents);
@@ -92,7 +95,7 @@ function ensureUsingDnsmasqDForConfigs()
$this->files->put($this->dnsmasqMasterConfigFile, $contents);
// remove old ~/.config/valet/dnsmasq.conf file because things are moved to the ~/.config/valet/dnsmasq.d/ folder now
if (file_exists($file = dirname($this->dnsmasqUserConfigDir()) . '/dnsmasq.conf')) {
if (file_exists($file = dirname($this->dnsmasqUserConfigDir()).'/dnsmasq.conf')) {
unlink($file);
}
@@ -100,19 +103,20 @@ function ensureUsingDnsmasqDForConfigs()
$contents = $this->files->get(__DIR__.'/../stubs/etc-dnsmasq-valet.conf');
$contents = str_replace('VALET_HOME_PATH', VALET_HOME_PATH, $contents);
$this->files->ensureDirExists($this->dnsmasqSystemConfDir, user());
$this->files->putAsUser($this->dnsmasqSystemConfDir . '/dnsmasq-valet.conf', $contents);
$this->files->putAsUser($this->dnsmasqSystemConfDir.'/dnsmasq-valet.conf', $contents);
$this->files->ensureDirExists(VALET_HOME_PATH . '/dnsmasq.d', user());
$this->files->ensureDirExists(VALET_HOME_PATH.'/dnsmasq.d', user());
}
/**
* Create the TLD-specific dnsmasq config file
* Create the TLD-specific dnsmasq config file.
*
* @param string $tld
* @return void
*/
function createDnsmasqTldConfigFile($tld)
public function createDnsmasqTldConfigFile($tld)
{
$tldConfigFile = $this->dnsmasqUserConfigDir() . 'tld-' . $tld . '.conf';
$tldConfigFile = $this->dnsmasqUserConfigDir().'tld-'.$tld.'.conf';
$loopback = $this->configuration->read()['loopback'];
$this->files->putAsUser($tldConfigFile, 'address=/.'.$tld.'/'.$loopback.PHP_EOL.'listen-address='.$loopback.PHP_EOL);
@@ -124,7 +128,7 @@ function createDnsmasqTldConfigFile($tld)
* @param string $tld
* @return void
*/
function createTldResolver($tld)
public function createTldResolver($tld)
{
$this->files->ensureDirExists($this->resolverPath);
$loopback = $this->configuration->read()['loopback'];
@@ -139,10 +143,10 @@ function createTldResolver($tld)
* @param string $newTld
* @return void
*/
function updateTld($oldTld, $newTld)
public function updateTld($oldTld, $newTld)
{
$this->files->unlink($this->resolverPath.'/'.$oldTld);
$this->files->unlink($this->dnsmasqUserConfigDir() . 'tld-' . $oldTld . '.conf');
$this->files->unlink($this->dnsmasqUserConfigDir().'tld-'.$oldTld.'.conf');
$this->install($newTld);
}
@@ -152,7 +156,7 @@ function updateTld($oldTld, $newTld)
*
* @return void
*/
function refreshConfiguration()
public function refreshConfiguration()
{
$tld = $this->configuration->read()['tld'];
@@ -164,7 +168,7 @@ function refreshConfiguration()
*
* @return string
*/
function dnsmasqUserConfigDir()
public function dnsmasqUserConfigDir()
{
return $_SERVER['HOME'].'/.config/valet/dnsmasq.d/';
}

View File

@@ -12,7 +12,7 @@ class Filesystem
* @param string $path
* @return bool
*/
function isDir($path)
public function isDir($path)
{
return is_dir($path);
}
@@ -25,7 +25,7 @@ function isDir($path)
* @param int $mode
* @return void
*/
function mkdir($path, $owner = null, $mode = 0755)
public function mkdir($path, $owner = null, $mode = 0755)
{
mkdir($path, $mode, true);
@@ -42,7 +42,7 @@ function mkdir($path, $owner = null, $mode = 0755)
* @param int $mode
* @return void
*/
function ensureDirExists($path, $owner = null, $mode = 0755)
public function ensureDirExists($path, $owner = null, $mode = 0755)
{
if (! $this->isDir($path)) {
$this->mkdir($path, $owner, $mode);
@@ -56,7 +56,7 @@ function ensureDirExists($path, $owner = null, $mode = 0755)
* @param int $mode
* @return void
*/
function mkdirAsUser($path, $mode = 0755)
public function mkdirAsUser($path, $mode = 0755)
{
$this->mkdir($path, user(), $mode);
}
@@ -68,7 +68,7 @@ function mkdirAsUser($path, $mode = 0755)
* @param string|null $owner
* @return string
*/
function touch($path, $owner = null)
public function touch($path, $owner = null)
{
touch($path);
@@ -85,7 +85,7 @@ function touch($path, $owner = null)
* @param string $path
* @return void
*/
function touchAsUser($path)
public function touchAsUser($path)
{
return $this->touch($path, user());
}
@@ -96,7 +96,7 @@ function touchAsUser($path)
* @param string $path
* @return bool
*/
function exists($path)
public function exists($path)
{
return file_exists($path);
}
@@ -107,7 +107,7 @@ function exists($path)
* @param string $path
* @return string
*/
function get($path)
public function get($path)
{
return file_get_contents($path);
}
@@ -120,7 +120,7 @@ function get($path)
* @param string|null $owner
* @return void
*/
function put($path, $contents, $owner = null)
public function put($path, $contents, $owner = null)
{
file_put_contents($path, $contents);
@@ -136,7 +136,7 @@ function put($path, $contents, $owner = null)
* @param string $contents
* @return void
*/
function putAsUser($path, $contents)
public function putAsUser($path, $contents)
{
$this->put($path, $contents, user());
}
@@ -149,7 +149,7 @@ function putAsUser($path, $contents)
* @param string|null $owner
* @return void
*/
function append($path, $contents, $owner = null)
public function append($path, $contents, $owner = null)
{
file_put_contents($path, $contents, FILE_APPEND);
@@ -165,7 +165,7 @@ function append($path, $contents, $owner = null)
* @param string $contents
* @return void
*/
function appendAsUser($path, $contents)
public function appendAsUser($path, $contents)
{
$this->append($path, $contents, user());
}
@@ -177,7 +177,7 @@ function appendAsUser($path, $contents)
* @param string $to
* @return void
*/
function copy($from, $to)
public function copy($from, $to)
{
copy($from, $to);
}
@@ -189,7 +189,7 @@ function copy($from, $to)
* @param string $to
* @return void
*/
function copyAsUser($from, $to)
public function copyAsUser($from, $to)
{
copy($from, $to);
@@ -203,7 +203,7 @@ function copyAsUser($from, $to)
* @param string $link
* @return void
*/
function symlink($target, $link)
public function symlink($target, $link)
{
if ($this->exists($link)) {
$this->unlink($link);
@@ -221,7 +221,7 @@ function symlink($target, $link)
* @param string $link
* @return void
*/
function symlinkAsUser($target, $link)
public function symlinkAsUser($target, $link)
{
if ($this->exists($link)) {
$this->unlink($link);
@@ -236,7 +236,7 @@ function symlinkAsUser($target, $link)
* @param string $path
* @return void
*/
function unlink($path)
public function unlink($path)
{
if (file_exists($path) || is_link($path)) {
@unlink($path);
@@ -249,7 +249,7 @@ function unlink($path)
* @param string $path
* @param string $user
*/
function chown($path, $user)
public function chown($path, $user)
{
chown($path, $user);
}
@@ -260,7 +260,7 @@ function chown($path, $user)
* @param string $path
* @param string $group
*/
function chgrp($path, $group)
public function chgrp($path, $group)
{
chgrp($path, $group);
}
@@ -271,7 +271,7 @@ function chgrp($path, $group)
* @param string $path
* @return string
*/
function realpath($path)
public function realpath($path)
{
return realpath($path);
}
@@ -282,7 +282,7 @@ function realpath($path)
* @param string $path
* @return bool
*/
function isLink($path)
public function isLink($path)
{
return is_link($path);
}
@@ -293,7 +293,7 @@ function isLink($path)
* @param string $path
* @return string
*/
function readLink($path)
public function readLink($path)
{
return readlink($path);
}
@@ -304,7 +304,7 @@ function readLink($path)
* @param string $path
* @return void
*/
function removeBrokenLinksAt($path)
public function removeBrokenLinksAt($path)
{
collect($this->scandir($path))
->filter(function ($file) use ($path) {
@@ -321,7 +321,7 @@ function removeBrokenLinksAt($path)
* @param string $path
* @return bool
*/
function isBrokenLink($path)
public function isBrokenLink($path)
{
return is_link($path) && ! file_exists($path);
}
@@ -332,7 +332,7 @@ function isBrokenLink($path)
* @param string $path
* @return array
*/
function scandir($path)
public function scandir($path)
{
return collect(scandir($path))
->reject(function ($file) {

View File

@@ -6,11 +6,11 @@
class Nginx
{
var $brew;
var $cli;
var $files;
var $configuration;
var $site;
public $brew;
public $cli;
public $files;
public $configuration;
public $site;
const NGINX_CONF = BREW_PREFIX.'/etc/nginx/nginx.conf';
/**
@@ -23,7 +23,7 @@ class Nginx
* @param Site $site
* @return void
*/
function __construct(Brew $brew, CommandLine $cli, Filesystem $files,
public function __construct(Brew $brew, CommandLine $cli, Filesystem $files,
Configuration $configuration, Site $site)
{
$this->cli = $cli;
@@ -38,9 +38,9 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files,
*
* @return void
*/
function install()
public function install()
{
if (!$this->brew->hasInstalledNginx()) {
if (! $this->brew->hasInstalledNginx()) {
$this->brew->installOrFail('nginx', []);
}
@@ -54,7 +54,7 @@ function install()
*
* @return void
*/
function installConfiguration()
public function installConfiguration()
{
info('Installing nginx configuration...');
@@ -71,7 +71,7 @@ function installConfiguration()
*
* @return void
*/
function installServer()
public function installServer()
{
$this->files->ensureDirExists(BREW_PREFIX.'/etc/nginx/valet');
@@ -90,7 +90,7 @@ function installServer()
);
}
function replaceLoopback($siteConf)
public function replaceLoopback($siteConf)
{
$loopback = $this->configuration->read()['loopback'];
@@ -114,7 +114,7 @@ function replaceLoopback($siteConf)
*
* @return void
*/
function installNginxDirectory()
public function installNginxDirectory()
{
info('Installing nginx directory...');
@@ -145,7 +145,7 @@ function ($exitCode, $outputMessage) {
*
* @return void
*/
function rewriteSecureNginxFiles()
public function rewriteSecureNginxFiles()
{
$tld = $this->configuration->read()['tld'];
$loopback = $this->configuration->read()['loopback'];
@@ -164,7 +164,7 @@ function rewriteSecureNginxFiles()
*
* @return void
*/
function restart()
public function restart()
{
$this->lint();
@@ -176,11 +176,11 @@ function restart()
*
* @return void
*/
function stop()
public function stop()
{
info('Stopping nginx...');
$this->cli->quietly('sudo brew services stop '. $this->brew->nginxServiceName());
$this->cli->quietly('sudo brew services stop '.$this->brew->nginxServiceName());
}
/**
@@ -188,7 +188,7 @@ function stop()
*
* @return void
*/
function uninstall()
public function uninstall()
{
$this->brew->stopService(['nginx', 'nginx-full']);
$this->brew->uninstallFormula('nginx nginx-full');

View File

@@ -2,12 +2,12 @@
namespace Valet;
use Httpful\Request;
use DomainException;
use Httpful\Request;
class Ngrok
{
var $tunnelsEndpoints = [
public $tunnelsEndpoints = [
'http://127.0.0.1:4040/api/tunnels',
'http://127.0.0.1:4041/api/tunnels',
];
@@ -17,7 +17,7 @@ class Ngrok
*
* @return string
*/
function currentTunnelUrl($domain = null)
public function currentTunnelUrl($domain = null)
{
// wait a second for ngrok to start before attempting to find available tunnels
sleep(1);
@@ -31,12 +31,12 @@ function currentTunnelUrl($domain = null)
}
}, 250);
if (!empty($response)) {
if (! empty($response)) {
return $response;
}
}
throw new DomainException("Tunnel not established.");
throw new DomainException('Tunnel not established.');
}
/**
@@ -45,13 +45,13 @@ function currentTunnelUrl($domain = null)
* @param array $tunnels
* @return string|null
*/
function findHttpTunnelUrl($tunnels, $domain)
public function findHttpTunnelUrl($tunnels, $domain)
{
// If there are active tunnels on the Ngrok instance we will spin through them and
// find the one responding on HTTP. Each tunnel has an HTTP and a HTTPS address
// but for local dev purposes we just desire the plain HTTP URL endpoint.
foreach ($tunnels as $tunnel) {
if ($tunnel->proto === 'http' && strpos($tunnel->config->addr, $domain) ) {
if ($tunnel->proto === 'http' && strpos($tunnel->config->addr, $domain)) {
return $tunnel->public_url;
}
}

View File

@@ -6,9 +6,11 @@
class PhpFpm
{
var $brew, $cli, $files;
public $brew;
public $cli;
public $files;
var $taps = [
public $taps = [
'homebrew/homebrew-core',
'shivammathur/php',
];
@@ -21,7 +23,7 @@ class PhpFpm
* @param Filesystem $files
* @return void
*/
function __construct(Brew $brew, CommandLine $cli, Filesystem $files)
public function __construct(Brew $brew, CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->brew = $brew;
@@ -33,13 +35,13 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files)
*
* @return void
*/
function install()
public function install()
{
if (! $this->brew->hasInstalledPhp()) {
$this->brew->ensureInstalled('php', [], $this->taps);
}
$this->files->ensureDirExists(VALET_HOME_PATH . '/Log', user());
$this->files->ensureDirExists(VALET_HOME_PATH.'/Log', user());
$this->updateConfiguration();
@@ -47,11 +49,11 @@ function install()
}
/**
* Forcefully uninstall all of Valet's supported PHP versions and configurations
* Forcefully uninstall all of Valet's supported PHP versions and configurations.
*
* @return void
*/
function uninstall()
public function uninstall()
{
$this->brew->uninstallAllPhpVersions();
rename(BREW_PREFIX.'/etc/php', BREW_PREFIX.'/etc/php-valet-bak'.time());
@@ -63,7 +65,7 @@ function uninstall()
*
* @return void
*/
function updateConfiguration()
public function updateConfiguration()
{
info('Updating PHP configuration...');
@@ -72,9 +74,9 @@ function updateConfiguration()
$this->files->ensureDirExists(dirname($fpmConfigFile), user());
// rename (to disable) old FPM Pool configuration, regardless of whether it's a default config or one customized by an older Valet version
$oldFile = dirname($fpmConfigFile) . '/www.conf';
$oldFile = dirname($fpmConfigFile).'/www.conf';
if (file_exists($oldFile)) {
rename($oldFile, $oldFile . '-backup');
rename($oldFile, $oldFile.'-backup');
}
if (false === strpos($fpmConfigFile, '5.6')) {
@@ -107,8 +109,8 @@ function updateConfiguration()
$destFile .= '/conf.d/error_log.ini';
$this->files->ensureDirExists(dirname($destFile), user());
$this->files->putAsUser($destFile, $contents);
$this->files->ensureDirExists(VALET_HOME_PATH . '/Log', user());
$this->files->touch(VALET_HOME_PATH . '/Log/php-fpm.log', user());
$this->files->ensureDirExists(VALET_HOME_PATH.'/Log', user());
$this->files->touch(VALET_HOME_PATH.'/Log/php-fpm.log', user());
}
/**
@@ -116,7 +118,7 @@ function updateConfiguration()
*
* @return void
*/
function restart()
public function restart()
{
$this->brew->restartLinkedPhp();
}
@@ -126,7 +128,7 @@ function restart()
*
* @return void
*/
function stop()
public function stop()
{
call_user_func_array(
[$this->brew, 'stopService'],
@@ -139,7 +141,7 @@ function stop()
*
* @return string
*/
function fpmConfigPath()
public function fpmConfigPath()
{
$version = $this->brew->linkedPhp();
@@ -152,9 +154,9 @@ function fpmConfigPath()
}
/**
* Only stop running php services
* Only stop running php services.
*/
function stopRunning()
public function stopRunning()
{
$this->brew->stopService(
$this->brew->getRunningServices()
@@ -166,26 +168,26 @@ function stopRunning()
}
/**
* Use a specific version of php
* Use a specific version of php.
*
* @param $version
* @param $force
* @return string
*/
function useVersion($version, $force = false)
public function useVersion($version, $force = false)
{
$version = $this->validateRequestedVersion($version);
try {
if ($this->brew->linkedPhp() === $version && !$force) {
output(sprintf('<info>Valet is already using version: <comment>%s</comment>.</info> To re-link and re-configure use the --force parameter.' . PHP_EOL,
if ($this->brew->linkedPhp() === $version && ! $force) {
output(sprintf('<info>Valet is already using version: <comment>%s</comment>.</info> To re-link and re-configure use the --force parameter.'.PHP_EOL,
$version));
exit();
}
} catch (DomainException $e)
{ /* ignore thrown exception when no linked php is found */ }
} catch (DomainException $e) { /* ignore thrown exception when no linked php is found */
}
if (!$this->brew->installed($version)) {
if (! $this->brew->installed($version)) {
// Install the relevant formula if not already installed
$this->brew->ensureInstalled($version, [], $this->taps);
}
@@ -204,7 +206,7 @@ function useVersion($version, $force = false)
// remove any orphaned valet.sock files that PHP didn't clean up due to version conflicts
$this->files->unlink(VALET_HOME_PATH.'/valet.sock');
$this->cli->quietly('sudo rm ' . VALET_HOME_PATH.'/valet.sock');
$this->cli->quietly('sudo rm '.VALET_HOME_PATH.'/valet.sock');
// ensure configuration is correct and start the linked version
$this->install();
@@ -212,11 +214,10 @@ function useVersion($version, $force = false)
return $version === 'php' ? $this->brew->determineAliasedVersion($version) : $version;
}
/**
* If passed php7.4 or php74 formats, normalize to php@7.4 format.
*/
function normalizePhpVersion($version)
public function normalizePhpVersion($version)
{
return preg_replace('/(php)([0-9+])(?:.)?([0-9+])/i', '$1@$2.$3', $version);
}
@@ -227,11 +228,11 @@ function normalizePhpVersion($version)
* @param $version
* @return string
*/
function validateRequestedVersion($version)
public function validateRequestedVersion($version)
{
$version = $this->normalizePhpVersion($version);
if (!$this->brew->supportedPhpVersions()->contains($version)) {
if (! $this->brew->supportedPhpVersions()->contains($version)) {
throw new DomainException(
sprintf(
'Valet doesn\'t support PHP version: %s (try something like \'php@7.3\' instead)',

View File

@@ -6,7 +6,9 @@
class Site
{
var $config, $cli, $files;
public $config;
public $cli;
public $files;
/**
* Create a new Site instance.
@@ -15,7 +17,7 @@ class Site
* @param CommandLine $cli
* @param Filesystem $files
*/
function __construct(Configuration $config, CommandLine $cli, Filesystem $files)
public function __construct(Configuration $config, CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->files = $files;
@@ -25,7 +27,7 @@ function __construct(Configuration $config, CommandLine $cli, Filesystem $files)
/**
* Get the name of the site.
*
* @param string|null $name
* @param string|null $name
* @return string
*/
private function getRealSiteName($name)
@@ -65,7 +67,7 @@ private function getLinkNameByCurrentDir()
* @param string $path
* @return string|null
*/
function host($path)
public function host($path)
{
foreach ($this->files->scandir($this->sitesPath()) as $link) {
if ($resolved = realpath($this->sitesPath($link)) === $path) {
@@ -83,7 +85,7 @@ function host($path)
* @param string $link
* @return string
*/
function link($target, $link)
public function link($target, $link)
{
$this->files->ensureDirExists(
$linkPath = $this->sitesPath(), user()
@@ -101,7 +103,7 @@ function link($target, $link)
*
* @return \Illuminate\Support\Collection
*/
function links()
public function links()
{
$certsPath = $this->certificatesPath();
@@ -113,11 +115,11 @@ function links()
}
/**
* Pretty print out all parked links in Valet
* Pretty print out all parked links in Valet.
*
* @return \Illuminate\Support\Collection
*/
function parked()
public function parked()
{
$certs = $this->getCertificates();
@@ -132,7 +134,7 @@ function parked()
// Only merge on the parked sites that don't interfere with the linked sites
$sites = $this->getSites($path, $certs)->filter(function ($site, $key) use ($links) {
return !$links->has($key);
return ! $links->has($key);
});
$parkedLinks = $parkedLinks->merge($sites);
@@ -142,11 +144,11 @@ function parked()
}
/**
* Get all sites which are proxies (not Links, and contain proxy_pass directive)
* Get all sites which are proxies (not Links, and contain proxy_pass directive).
*
* @return \Illuminate\Support\Collection
*/
function proxies()
public function proxies()
{
$dir = $this->nginxPath();
$tld = $this->config->read()['tld'];
@@ -168,17 +170,18 @@ function proxies()
return $links->has($site);
})->mapWithKeys(function ($site) {
$host = $this->getProxyHostForSite($site) ?: '(other)';
return [$site => $host];
})->reject(function ($host, $site) {
// If proxy host is null, it may be just a normal SSL stub, or something else; either way we exclude it from the list
return $host === '(other)';
})->map(function ($host, $site) use ($certs, $tld) {
$secured = $certs->has($site);
$url = ($secured ? 'https': 'http').'://'.$site.'.'.$tld;
$url = ($secured ? 'https' : 'http').'://'.$site.'.'.$tld;
return [
'site' => $site,
'secured' => $secured ? ' X': '',
'secured' => $secured ? ' X' : '',
'url' => $url,
'path' => $host,
];
@@ -190,11 +193,11 @@ function proxies()
/**
* Identify whether a site is for a proxy by reading the host name from its config file.
*
* @param string $site Site name without TLD
* @param string $configContents Config file contents
* @param string $site Site name without TLD
* @param string $configContents Config file contents
* @return string|null
*/
function getProxyHostForSite($site, $configContents = null)
public function getProxyHostForSite($site, $configContents = null)
{
$siteConf = $configContents ?: $this->getSiteConfigFileContents($site);
@@ -206,24 +209,26 @@ function getProxyHostForSite($site, $configContents = null)
if (preg_match('~proxy_pass\s+(?<host>https?://.*)\s*;~', $siteConf, $patterns)) {
$host = trim($patterns['host']);
}
return $host;
}
function getSiteConfigFileContents($site, $suffix = null)
public function getSiteConfigFileContents($site, $suffix = null)
{
$config = $this->config->read();
$suffix = $suffix ?: '.'.$config['tld'];
$file = str_replace($suffix,'',$site).$suffix;
$file = str_replace($suffix, '', $site).$suffix;
return $this->files->exists($this->nginxPath($file)) ? $this->files->get($this->nginxPath($file)) : null;
}
/**
* Get all certificates from config folder.
*
* @param string $path
* @param string $path
* @return \Illuminate\Support\Collection
*/
function getCertificates($path = null)
public function getCertificates($path = null)
{
$path = $path ?: $this->certificatesPath();
@@ -250,25 +255,24 @@ function getCertificates($path = null)
/**
* @deprecated Use getSites instead which works for both normal and symlinked paths.
*
* @param string $path
* @param \Illuminate\Support\Collection $certs
* @param string $path
* @param \Illuminate\Support\Collection $certs
* @return \Illuminate\Support\Collection
*/
function getLinks($path, $certs)
public function getLinks($path, $certs)
{
return $this->getSites($path, $certs);
}
/**
* Get list of sites and return them formatted
* Will work for symlink and normal site paths
* Will work for symlink and normal site paths.
*
* @param $path
* @param $certs
*
* @return \Illuminate\Support\Collection
*/
function getSites($path, $certs)
public function getSites($path, $certs)
{
$config = $this->config->read();
@@ -282,16 +286,17 @@ function getSites($path, $certs)
} else {
$realPath = $this->files->realpath($sitePath);
}
return [$site => $realPath];
})->filter(function ($path) {
return $this->files->isDir($path);
})->map(function ($path, $site) use ($certs, $config) {
$secured = $certs->has($site);
$url = ($secured ? 'https': 'http').'://'.$site.'.'.$config['tld'];
$url = ($secured ? 'https' : 'http').'://'.$site.'.'.$config['tld'];
return [
'site' => $site,
'secured' => $secured ? ' X': '',
'secured' => $secured ? ' X' : '',
'url' => $url,
'path' => $path,
];
@@ -304,7 +309,7 @@ function getSites($path, $certs)
* @param string $name
* @return void
*/
function unlink($name)
public function unlink($name)
{
$name = $this->getRealSiteName($name);
@@ -320,7 +325,7 @@ function unlink($name)
*
* @return void
*/
function pruneLinks()
public function pruneLinks()
{
$this->files->ensureDirExists($this->sitesPath(), user());
@@ -338,7 +343,7 @@ function pruneLinks()
* @param array $new
* @return void
*/
function resecureForNewConfiguration(array $old, array $new)
public function resecureForNewConfiguration(array $old, array $new)
{
if (! $this->files->exists($this->certificatesPath())) {
return;
@@ -347,18 +352,18 @@ function resecureForNewConfiguration(array $old, array $new)
$secured = $this->secured();
$defaultTld = $this->config->read()['tld'];
$oldTld = !empty($old['tld']) ? $old['tld'] : $defaultTld;
$tld = !empty($new['tld']) ? $new['tld'] : $defaultTld;
$oldTld = ! empty($old['tld']) ? $old['tld'] : $defaultTld;
$tld = ! empty($new['tld']) ? $new['tld'] : $defaultTld;
$defaultLoopback = $this->config->read()['loopback'];
$oldLoopback = !empty($old['loopback']) ? $old['loopback'] : $defaultLoopback;
$loopback = !empty($new['loopback']) ? $new['loopback'] : $defaultLoopback;
$oldLoopback = ! empty($old['loopback']) ? $old['loopback'] : $defaultLoopback;
$loopback = ! empty($new['loopback']) ? $new['loopback'] : $defaultLoopback;
foreach ($secured as $url) {
$newUrl = str_replace('.'.$oldTld, '.'.$tld, $url);
$siteConf = $this->getSiteConfigFileContents($url, '.'.$oldTld);
if (!empty($siteConf) && strpos($siteConf, '# valet stub: proxy.valet.conf') === 0) {
if (! empty($siteConf) && strpos($siteConf, '# valet stub: proxy.valet.conf') === 0) {
// proxy config
$this->unsecure($url);
$this->secure(
@@ -380,12 +385,12 @@ function resecureForNewConfiguration(array $old, array $new)
/**
* Parse Nginx site config file contents to swap old domain to new.
*
* @param string $siteConf Nginx site config content
* @param string $old Old domain
* @param string $new New domain
* @param string $siteConf Nginx site config content
* @param string $old Old domain
* @param string $new New domain
* @return string
*/
function replaceOldDomainWithNew($siteConf, $old, $new)
public function replaceOldDomainWithNew($siteConf, $old, $new)
{
$lookups = [];
$lookups[] = '~server_name .*;~';
@@ -400,18 +405,19 @@ function replaceOldDomainWithNew($siteConf, $old, $new)
$siteConf = str_replace($match, $replaced, $siteConf);
}
}
return $siteConf;
}
/**
* Parse Nginx site config file contents to swap old loopback address to new.
*
* @param string $siteConf Nginx site config content
* @param string $old Old loopback address
* @param string $new New loopback address
* @param string $siteConf Nginx site config content
* @param string $old Old loopback address
* @param string $new New loopback address
* @return string
*/
function replaceOldLoopbackWithNew($siteConf, $old, $new)
public function replaceOldLoopbackWithNew($siteConf, $old, $new)
{
$shouldComment = $new === VALET_LOOPBACK;
@@ -436,6 +442,7 @@ function replaceOldLoopbackWithNew($siteConf, $old, $new)
$siteConf = str_replace($match, $replaced, $siteConf);
}
}
return $siteConf;
}
@@ -444,7 +451,7 @@ function replaceOldLoopbackWithNew($siteConf, $old, $new)
*
* @return array
*/
function secured()
public function secured()
{
return collect($this->files->scandir($this->certificatesPath()))
->map(function ($file) {
@@ -459,7 +466,7 @@ function secured()
* @param string $siteConf pregenerated Nginx config file contents
* @return void
*/
function secure($url, $siteConf = null)
public function secure($url, $siteConf = null)
{
$this->unsecure($url);
@@ -483,7 +490,7 @@ function secure($url, $siteConf = null)
*
* @return void
*/
function createCa()
public function createCa()
{
$caPemPath = $this->caPath('LaravelValetCASelfSigned.pem');
$caKeyPath = $this->caPath('LaravelValetCASelfSigned.key');
@@ -520,7 +527,7 @@ function createCa()
* @param string $url
* @return void
*/
function createCertificate($url)
public function createCertificate($url)
{
$caPemPath = $this->caPath('LaravelValetCASelfSigned.pem');
$caKeyPath = $this->caPath('LaravelValetCASelfSigned.key');
@@ -534,7 +541,7 @@ function createCertificate($url)
$this->createPrivateKey($keyPath);
$this->createSigningRequest($url, $keyPath, $csrPath, $confPath);
$caSrlParam = '-CAserial "' . $caSrlPath . '"';
$caSrlParam = '-CAserial "'.$caSrlPath.'"';
if (! $this->files->exists($caSrlPath)) {
$caSrlParam .= ' -CAcreateserial';
}
@@ -561,7 +568,7 @@ function createCertificate($url)
* @param string $keyPath
* @return void
*/
function createPrivateKey($keyPath)
public function createPrivateKey($keyPath)
{
$this->cli->runAsUser(sprintf('openssl genrsa -out "%s" 2048', $keyPath));
}
@@ -572,7 +579,7 @@ function createPrivateKey($keyPath)
* @param string $keyPath
* @return void
*/
function createSigningRequest($url, $keyPath, $csrPath, $confPath)
public function createSigningRequest($url, $keyPath, $csrPath, $confPath)
{
$this->cli->runAsUser(sprintf(
'openssl req -new -key "%s" -out "%s" -subj "/C=/ST=/O=/localityName=/commonName=%s/organizationalUnitName=/emailAddress=%s%s/" -config "%s"',
@@ -586,7 +593,7 @@ function createSigningRequest($url, $keyPath, $csrPath, $confPath)
* @param string $pemPath
* @return void
*/
function trustCa($caPemPath)
public function trustCa($caPemPath)
{
$this->cli->run(sprintf(
'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "%s"', $caPemPath
@@ -599,7 +606,7 @@ function trustCa($caPemPath)
* @param string $crtPath
* @return void
*/
function trustCertificate($crtPath)
public function trustCertificate($crtPath)
{
$this->cli->run(sprintf(
'sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain "%s"', $crtPath
@@ -612,7 +619,7 @@ function trustCertificate($crtPath)
* @param string $url
* @return string
*/
function buildCertificateConf($path, $url)
public function buildCertificateConf($path, $url)
{
$config = str_replace('VALET_DOMAIN', $url, $this->files->get(__DIR__.'/../stubs/openssl.conf'));
$this->files->putAsUser($path, $config);
@@ -625,7 +632,7 @@ function buildCertificateConf($path, $url)
* @param string $siteConf (optional) Nginx site config file content
* @return string
*/
function buildSecureNginxServer($url, $siteConf = null)
public function buildSecureNginxServer($url, $siteConf = null)
{
if ($siteConf === null) {
$siteConf = $this->replaceOldLoopbackWithNew(
@@ -655,7 +662,7 @@ function buildSecureNginxServer($url, $siteConf = null)
* @param string $url
* @return void
*/
function unsecure($url)
public function unsecure($url)
{
if ($this->files->exists($this->certificatesPath($url, 'crt'))) {
$this->files->unlink($this->nginxPath($url));
@@ -674,7 +681,7 @@ function unsecure($url)
));
}
function unsecureAll()
public function unsecureAll()
{
$tld = $this->config->read()['tld'];
@@ -691,7 +698,7 @@ function unsecureAll()
table(['Site', 'SSL', 'URL', 'Path'], $secured->toArray());
foreach ($secured->pluck('site') as $url) {
$this->unsecure($url . '.' . $tld);
$this->unsecure($url.'.'.$tld);
}
$remaining = $this->parked()
@@ -706,21 +713,21 @@ function unsecureAll()
}
/**
* Build the Nginx proxy config for the specified domain
* Build the Nginx proxy config for the specified domain.
*
* @param string $url The domain name to serve
* @param string $host The URL to proxy to, eg: http://127.0.0.1:8080
* @param bool $secure
* @param string $url The domain name to serve
* @param string $host The URL to proxy to, eg: http://127.0.0.1:8080
* @param bool $secure
* @return string
*/
function proxyCreate($url, $host, $secure = false)
public function proxyCreate($url, $host, $secure = false)
{
if (!preg_match('~^https?://.*$~', $host)) {
if (! preg_match('~^https?://.*$~', $host)) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid URL', $host));
}
$tld = $this->config->read()['tld'];
if (!ends_with($url, '.'.$tld)) {
if (! ends_with($url, '.'.$tld)) {
$url .= '.'.$tld;
}
@@ -755,10 +762,10 @@ function proxyCreate($url, $host, $secure = false)
* @param string $url
* @return void
*/
function proxyDelete($url)
public function proxyDelete($url)
{
$tld = $this->config->read()['tld'];
if (!ends_with($url, '.'.$tld)) {
if (! ends_with($url, '.'.$tld)) {
$url .= '.'.$tld;
}
@@ -775,7 +782,7 @@ function proxyDelete($url)
* @param string $siteConf pregenerated Nginx config file contents
* @return void
*/
function put($url, $siteConf)
public function put($url, $siteConf)
{
$this->unsecure($url);
@@ -793,7 +800,7 @@ function put($url, $siteConf)
* @param string $loopback
* @return void
*/
function aliasLoopback($oldLoopback, $loopback)
public function aliasLoopback($oldLoopback, $loopback)
{
if ($oldLoopback !== VALET_LOOPBACK) {
$this->removeLoopbackAlias($oldLoopback);
@@ -812,7 +819,7 @@ function aliasLoopback($oldLoopback, $loopback)
* @param string $loopback
* @return void
*/
function removeLoopbackAlias($loopback)
public function removeLoopbackAlias($loopback)
{
$this->cli->run(sprintf(
'sudo ifconfig lo0 -alias %s', $loopback
@@ -827,7 +834,7 @@ function removeLoopbackAlias($loopback)
* @param string $loopback
* @return void
*/
function addLoopbackAlias($loopback)
public function addLoopbackAlias($loopback)
{
$this->cli->run(sprintf(
'sudo ifconfig lo0 alias %s', $loopback
@@ -842,7 +849,7 @@ function addLoopbackAlias($loopback)
* @param string $loopback
* @return void
*/
function updateLoopbackPlist($loopback)
public function updateLoopbackPlist($loopback)
{
$this->removeLoopbackPlist();
@@ -865,7 +872,7 @@ function updateLoopbackPlist($loopback)
*
* @return void
*/
function removeLoopbackPlist()
public function removeLoopbackPlist()
{
if ($this->files->exists($this->plistPath())) {
$this->files->unlink($this->plistPath());
@@ -879,7 +886,7 @@ function removeLoopbackPlist()
*
* @return void
*/
function uninstallLoopback()
public function uninstallLoopback()
{
if (($loopback = $this->valetLoopback()) !== VALET_LOOPBACK) {
$this->removeLoopbackAlias($loopback);
@@ -888,12 +895,12 @@ function uninstallLoopback()
$this->removeLoopbackPlist();
}
function valetHomePath()
public function valetHomePath()
{
return VALET_HOME_PATH;
}
function valetLoopback()
public function valetLoopback()
{
return $this->config->read()['loopback'];
}
@@ -903,7 +910,7 @@ function valetLoopback()
*
* @return string
*/
function plistPath()
public function plistPath()
{
return '/Library/LaunchDaemons/com.laravel.valet.loopback.plist';
}
@@ -911,7 +918,7 @@ function plistPath()
/**
* Get the path to Nginx site configuration files.
*/
function nginxPath($additionalPath = null)
public function nginxPath($additionalPath = null)
{
return $this->valetHomePath().'/Nginx'.($additionalPath ? '/'.$additionalPath : '');
}
@@ -921,7 +928,7 @@ function nginxPath($additionalPath = null)
*
* @return string
*/
function sitesPath($link = null)
public function sitesPath($link = null)
{
return $this->valetHomePath().'/Sites'.($link ? '/'.$link : '');
}
@@ -931,7 +938,7 @@ function sitesPath($link = null)
*
* @return string
*/
function caPath($caFile = null)
public function caPath($caFile = null)
{
return $this->valetHomePath().'/CA'.($caFile ? '/'.$caFile : '');
}
@@ -941,7 +948,7 @@ function caPath($caFile = null)
*
* @return string
*/
function certificatesPath($url = null, $extension = null)
public function certificatesPath($url = null, $extension = null)
{
$url = $url ? '/'.$url : '';
$extension = $extension ? '.'.$extension : '';

View File

@@ -6,9 +6,10 @@
class Valet
{
var $cli, $files;
public $cli;
public $files;
var $valetBin = BREW_PREFIX.'/bin/valet';
public $valetBin = BREW_PREFIX.'/bin/valet';
/**
* Create a new Valet instance.
@@ -16,7 +17,7 @@ class Valet
* @param CommandLine $cli
* @param Filesystem $files
*/
function __construct(CommandLine $cli, Filesystem $files)
public function __construct(CommandLine $cli, Filesystem $files)
{
$this->cli = $cli;
$this->files = $files;
@@ -27,7 +28,7 @@ function __construct(CommandLine $cli, Filesystem $files)
*
* @return void
*/
function symlinkToUsersBin()
public function symlinkToUsersBin()
{
$this->unlinkFromUsersBin();
@@ -39,7 +40,7 @@ function symlinkToUsersBin()
*
* @return void
*/
function unlinkFromUsersBin()
public function unlinkFromUsersBin()
{
$this->cli->quietlyAsUser('rm '.$this->valetBin);
}
@@ -49,7 +50,7 @@ function unlinkFromUsersBin()
*
* @return array
*/
function extensions()
public function extensions()
{
if (! $this->files->isDir(VALET_HOME_PATH.'/Extensions')) {
return [];
@@ -70,9 +71,10 @@ function extensions()
*
* @param string $currentVersion
* @return bool
*
* @throws \Httpful\Exception\ConnectionErrorException
*/
function onLatestVersion($currentVersion)
public function onLatestVersion($currentVersion)
{
$response = Request::get('https://api.github.com/repos/laravel/valet/releases/latest')->send();
@@ -84,7 +86,7 @@ function onLatestVersion($currentVersion)
*
* @return void
*/
function createSudoersEntry()
public function createSudoersEntry()
{
$this->files->ensureDirExists('/etc/sudoers.d');
@@ -97,23 +99,23 @@ function createSudoersEntry()
*
* @return void
*/
function removeSudoersEntry()
public function removeSudoersEntry()
{
$this->cli->quietly('rm /etc/sudoers.d/valet');
}
/**
* Run composer global diagnose
* Run composer global diagnose.
*/
function composerGlobalDiagnose()
public function composerGlobalDiagnose()
{
$this->cli->runAsUser('composer global diagnose');
}
/**
* Run composer global update
* Run composer global update.
*/
function composerGlobalUpdate()
public function composerGlobalUpdate()
{
$this->cli->runAsUser('composer global update');
}

View File

@@ -48,10 +48,10 @@ public function isStaticFile($sitePath, $siteName, $uri)
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
$_SERVER['PHP_SELF'] = $uri;
$_SERVER['PHP_SELF'] = $uri;
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$dynamicCandidates = [
$this->asActualFile($sitePath, $uri),
$this->asPhpIndexFileInDirectory($sitePath, $uri),
@@ -63,14 +63,15 @@ public function frontControllerPath($sitePath, $siteName, $uri)
$_SERVER['SCRIPT_FILENAME'] = $candidate;
$_SERVER['SCRIPT_NAME'] = str_replace($sitePath, '', $candidate);
$_SERVER['DOCUMENT_ROOT'] = $sitePath;
return $candidate;
}
}
$fixedCandidatesAndDocroots = [
$this->asRootPhpIndexFile($sitePath) => $sitePath,
$this->asPublicPhpIndexFile($sitePath) => $sitePath . '/public',
$this->asPublicHtmlIndexFile($sitePath) => $sitePath . '/public',
$this->asPublicPhpIndexFile($sitePath) => $sitePath.'/public',
$this->asPublicHtmlIndexFile($sitePath) => $sitePath.'/public',
];
foreach ($fixedCandidatesAndDocroots as $candidate => $docroot) {
@@ -78,6 +79,7 @@ public function frontControllerPath($sitePath, $siteName, $uri)
$_SERVER['SCRIPT_FILENAME'] = $candidate;
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['DOCUMENT_ROOT'] = $docroot;
return $candidate;
}
}

View File

@@ -55,8 +55,8 @@ public function frontControllerPath($sitePath, $siteName, $uri)
? $sitePath.'/web'.$this->forceTrailingSlash($uri).'/index.php'
: $sitePath.'/web'.$uri;
}
if($uri !== '/' && file_exists($sitePath.'/web'.$uri)) {
if ($uri !== '/' && file_exists($sitePath.'/web'.$uri)) {
return $sitePath.'/web'.$uri;
}
@@ -66,13 +66,14 @@ public function frontControllerPath($sitePath, $siteName, $uri)
/**
* Redirect to uri with trailing slash.
*
* @param string $uri
* @param string $uri
* @return string
*/
private function forceTrailingSlash($uri)
{
if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') {
header('Location: '.$uri.'/'); die;
header('Location: '.$uri.'/');
exit;
}
return $uri;

View File

@@ -2,28 +2,28 @@
class Concrete5ValetDriver extends BasicValetDriver
{
/**
* If a concrete directory exists, it's probably c5
* @param string $sitePath
* @param string $siteName
* @param string $uri
* If a concrete directory exists, it's probably c5.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
return file_exists($sitePath . "/concrete/config/install/base");
return file_exists($sitePath.'/concrete/config/install/base');
}
/**
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
if (!getenv('CONCRETE5_ENV')) {
if (! getenv('CONCRETE5_ENV')) {
putenv('CONCRETE5_ENV=valet');
}
@@ -35,14 +35,13 @@ public function frontControllerPath($sitePath, $siteName, $uri)
$_SERVER['SCRIPT_FILENAME'] = $sitePath.$filename;
$_SERVER['SCRIPT_NAME'] = $filename;
return $sitePath . $filename;
return $sitePath.$filename;
}
}
$_SERVER['SCRIPT_FILENAME'] = $sitePath . '/index.php';
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/index.php';
$_SERVER['SCRIPT_NAME'] = '/index.php';
return $sitePath . '/index.php';
return $sitePath.'/index.php';
}
}

View File

@@ -14,11 +14,11 @@ public function serves($sitePath, $siteName, $uri)
{
$sitePath = $this->addSubdirectory($sitePath);
/**
* /misc/drupal.js = Drupal 7
* /core/lib/Drupal.php = Drupal 8
*/
if (file_exists($sitePath.'/misc/drupal.js') ||
/**
* /misc/drupal.js = Drupal 7
* /core/lib/Drupal.php = Drupal 8.
*/
if (file_exists($sitePath.'/misc/drupal.js') ||
file_exists($sitePath.'/core/lib/Drupal.php')) {
return true;
}
@@ -57,8 +57,8 @@ public function frontControllerPath($sitePath, $siteName, $uri)
{
$sitePath = $this->addSubdirectory($sitePath);
if (!isset($_GET['q']) && !empty($uri) && $uri !== '/' && strpos($uri, '/jsonapi/') === false) {
$_GET['q'] = $uri;
if (! isset($_GET['q']) && ! empty($uri) && $uri !== '/' && strpos($uri, '/jsonapi/') === false) {
$_GET['q'] = $uri;
}
$matches = [];
@@ -67,6 +67,7 @@ public function frontControllerPath($sitePath, $siteName, $uri)
if (file_exists($sitePath.$filename) && ! is_dir($sitePath.$filename)) {
$_SERVER['SCRIPT_FILENAME'] = $sitePath.$filename;
$_SERVER['SCRIPT_NAME'] = $filename;
return $sitePath.$filename;
}
}
@@ -74,6 +75,7 @@ public function frontControllerPath($sitePath, $siteName, $uri)
// Fallback
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/index.php';
$_SERVER['SCRIPT_NAME'] = '/index.php';
return $sitePath.'/index.php';
}
@@ -91,7 +93,7 @@ public function addSubdirectory($sitePath)
});
// If paths are found, return the first one.
if (!empty($foundPaths)) {
if (! empty($foundPaths)) {
return array_shift($foundPaths);
}

View File

@@ -31,7 +31,7 @@ public function isStaticFile($sitePath, $siteName, $uri)
return $staticFilePath;
}
return false;
return false;
}
/**

View File

@@ -58,7 +58,7 @@ public function frontControllerPath($sitePath, $siteName, $uri)
if (isset($_SERVER['HTTP_X_ORIGINAL_HOST'], $_SERVER['HTTP_X_FORWARDED_HOST'])) {
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
return $sitePath.'/public/index.php';
}
}

View File

@@ -2,9 +2,8 @@
class Magento2ValetDriver extends ValetDriver
{
/**
* Holds the MAGE_MODE from app/etc/config.php or $ENV
* Holds the MAGE_MODE from app/etc/config.php or $ENV.
*
* @var string
*/
@@ -13,22 +12,22 @@ class Magento2ValetDriver extends ValetDriver
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return boolean
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
return file_exists($sitePath . '/bin/magento') && file_exists($sitePath . '/pub/index.php');
return file_exists($sitePath.'/bin/magento') && file_exists($sitePath.'/pub/index.php');
}
/**
* Determine if the incoming request is for a static file.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string|false
*/
public function isStaticFile($sitePath, $siteName, $uri)
@@ -43,7 +42,7 @@ public function isStaticFile($sitePath, $siteName, $uri)
$pub = 'pub/';
}
if (!$this->isPubDirectory($sitePath, $route, $pub)) {
if (! $this->isPubDirectory($sitePath, $route, $pub)) {
return false;
}
@@ -52,21 +51,21 @@ public function isStaticFile($sitePath, $siteName, $uri)
$magentoPackagePubDir .= '/pub';
}
$file = $magentoPackagePubDir . '/' . $route;
$file = $magentoPackagePubDir.'/'.$route;
if (file_exists($file)) {
return $magentoPackagePubDir . $uri;
return $magentoPackagePubDir.$uri;
}
if (strpos($route, $pub . 'static/') === 0) {
$route = preg_replace('#' . $pub . 'static/#', '', $route, 1);
if (strpos($route, $pub.'static/') === 0) {
$route = preg_replace('#'.$pub.'static/#', '', $route, 1);
$_GET['resource'] = $route;
include $magentoPackagePubDir . '/' . $pub . 'static.php';
include $magentoPackagePubDir.'/'.$pub.'static.php';
exit;
}
if (strpos($route, $pub . 'media/') === 0) {
include $magentoPackagePubDir . '/' . $pub . 'get.php';
if (strpos($route, $pub.'media/') === 0) {
include $magentoPackagePubDir.'/'.$pub.'get.php';
exit;
}
@@ -75,9 +74,9 @@ public function isStaticFile($sitePath, $siteName, $uri)
/**
* Rewrite URLs that look like "versions12345/" to remove
* the versions12345/ part
* the versions12345/ part.
*
* @param string $route
* @param string $route
*/
private function handleForVersions($route)
{
@@ -85,9 +84,9 @@ private function handleForVersions($route)
}
/**
* Determine the current MAGE_MODE
* Determine the current MAGE_MODE.
*
* @param string $sitePath
* @param string $sitePath
*/
private function checkMageMode($sitePath)
{
@@ -95,13 +94,14 @@ private function checkMageMode($sitePath)
// We have already figure out mode, no need to check it again
return;
}
if (!file_exists($sitePath . '/index.php')) {
if (! file_exists($sitePath.'/index.php')) {
$this->mageMode = 'production'; // Can't use developer mode without index.php in project root
return;
}
$mageConfig = [];
if (file_exists($sitePath . '/app/etc/env.php')) {
$mageConfig = require $sitePath . '/app/etc/env.php';
if (file_exists($sitePath.'/app/etc/env.php')) {
$mageConfig = require $sitePath.'/app/etc/env.php';
}
if (array_key_exists('MAGE_MODE', $mageConfig)) {
$this->mageMode = $mageConfig['MAGE_MODE'];
@@ -112,31 +112,32 @@ private function checkMageMode($sitePath)
* Checks to see if route is referencing any directory inside pub. This is a dynamic check so that if any new
* directories are added to pub this driver will not need to be updated.
*
* @param string $sitePath
* @param string $route
* @param string $pub
* @param string $sitePath
* @param string $route
* @param string $pub
* @return bool
*/
private function isPubDirectory($sitePath, $route, $pub = '')
{
$sitePath .= '/pub/';
$dirs = glob($sitePath . '*', GLOB_ONLYDIR);
$dirs = glob($sitePath.'*', GLOB_ONLYDIR);
$dirs = str_replace($sitePath, '', $dirs);
foreach ($dirs as $dir) {
if (strpos($route, $pub . $dir . '/') === 0) {
if (strpos($route, $pub.$dir.'/') === 0) {
return true;
}
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
@@ -145,9 +146,11 @@ public function frontControllerPath($sitePath, $siteName, $uri)
if ('developer' === $this->mageMode) {
$_SERVER['DOCUMENT_ROOT'] = $sitePath;
return $sitePath . '/index.php';
return $sitePath.'/index.php';
}
$_SERVER['DOCUMENT_ROOT'] = $sitePath . '/pub';
return $sitePath . '/pub/index.php';
$_SERVER['DOCUMENT_ROOT'] = $sitePath.'/pub';
return $sitePath.'/pub/index.php';
}
}

View File

@@ -28,6 +28,7 @@ public function isStaticFile($sitePath, $siteName, $uri)
if ($this->isActualFile($staticFilePath = $sitePath.'/Web'.$uri)) {
return $staticFilePath;
}
return false;
}
@@ -45,6 +46,7 @@ public function frontControllerPath($sitePath, $siteName, $uri)
putenv('FLOW_REWRITEURLS=1');
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/Web/index.php';
$_SERVER['SCRIPT_NAME'] = '/index.php';
return $sitePath.'/Web/index.php';
}
}

View File

@@ -69,26 +69,26 @@ public function frontControllerPath($sitePath, $siteName, $uri)
$sitePathPrefix = ($isAboveWebroot) ? $sitePath.'/public' : $sitePath;
if ($locale = $this->getUriLocale($uri)) {
if ($this->isActualFile($localeIndexPath = $sitePathPrefix . '/' . $locale . '/index.php')) {
if ($this->isActualFile($localeIndexPath = $sitePathPrefix.'/'.$locale.'/index.php')) {
// Force trailing slashes on locale roots.
if ($uri === '/' . $locale) {
header('Location: ' . $uri . '/');
die;
if ($uri === '/'.$locale) {
header('Location: '.$uri.'/');
exit;
}
$indexPath = $localeIndexPath;
$scriptName = '/' . $locale . '/index.php';
$scriptName = '/'.$locale.'/index.php';
}
}
$_SERVER['SCRIPT_NAME'] = $scriptName;
$_SERVER['SCRIPT_FILENAME'] = $sitePathPrefix . $scriptName;
$_SERVER['SCRIPT_FILENAME'] = $sitePathPrefix.$scriptName;
return $indexPath;
}
/**
* Get the locale from this URI
* Get the locale from this URI.
*
* @param string $uri
* @return string|null
@@ -106,7 +106,7 @@ public function getUriLocale($uri)
}
/**
* Get the list of possible locales used in the first segment of a URI
* Get the list of possible locales used in the first segment of a URI.
*
* @return array
*/
@@ -131,9 +131,9 @@ public function getLocales()
}
/**
* Get the path to a statically cached page
* Get the path to a statically cached page.
*
* @param string $sitePath
* @param string $sitePath
* @return string
*/
protected function getStaticPath($sitePath)
@@ -141,6 +141,6 @@ protected function getStaticPath($sitePath)
$parts = parse_url($_SERVER['REQUEST_URI']);
$query = isset($parts['query']) ? $parts['query'] : '';
return $sitePath . '/static' . $parts['path'] . '_' . $query . '.html';
return $sitePath.'/static'.$parts['path'].'_'.$query.'.html';
}
}

View File

@@ -14,8 +14,7 @@ public function serves($sitePath, $siteName, $uri)
{
return (file_exists($sitePath.'/web/app_dev.php') || file_exists($sitePath.'/web/app.php')) &&
(file_exists($sitePath.'/app/AppKernel.php')) || (file_exists($sitePath.'/public/index.php')) &&
(file_exists($sitePath.'/src/Kernel.php'))
;
(file_exists($sitePath.'/src/Kernel.php'));
}
/**
@@ -58,6 +57,7 @@ public function frontControllerPath($sitePath, $siteName, $uri)
}
$_SERVER['SCRIPT_FILENAME'] = $frontControllerPath;
return $frontControllerPath;
}
}

View File

@@ -12,7 +12,7 @@ class Typo3ValetDriver extends ValetDriver
| Document Root Subdirectory
|--------------------------------------------------------------------------
|
| This subdirectory contains the public server resources, such as the
| This subdirectory contains the public server resources, such as the
| index.php, the typo3 and fileadmin system directories. Change it
| to '', if you don't use a subdirectory but valet link directly.
|
@@ -48,7 +48,8 @@ class Typo3ValetDriver extends ValetDriver
*/
public function serves($sitePath, $siteName, $uri)
{
$typo3Dir = $sitePath . $this->documentRoot . '/typo3';
$typo3Dir = $sitePath.$this->documentRoot.'/typo3';
return file_exists($typo3Dir) && is_dir($typo3Dir);
}
@@ -66,17 +67,15 @@ public function isStaticFile($sitePath, $siteName, $uri)
{
// May the file contains a cache busting version string like filename.12345678.css
// If that is the case, the file cannot be found on disk, so remove the version
// identifier before retrying below.
if (!$this->isActualFile($filePath = $sitePath . $this->documentRoot . $uri))
{
$uri = preg_replace("@^(.+)\.(\d+)\.(js|css|png|jpg|gif|gzip)$@", "$1.$3", $uri);
// identifier before retrying below.
if (! $this->isActualFile($filePath = $sitePath.$this->documentRoot.$uri)) {
$uri = preg_replace("@^(.+)\.(\d+)\.(js|css|png|jpg|gif|gzip)$@", '$1.$3', $uri);
}
// Now that any possible version string is cleared from the filename, the resulting
// URI should be a valid file on disc. So assemble the absolut file name with the
// same schema as above and if it exists, authorize access and return its path.
if ($this->isActualFile($filePath = $sitePath . $this->documentRoot . $uri))
{
if ($this->isActualFile($filePath = $sitePath.$this->documentRoot.$uri)) {
return $this->isAccessAuthorized($uri) ? $filePath : false;
}
@@ -87,18 +86,17 @@ public function isStaticFile($sitePath, $siteName, $uri)
/**
* Determines if the given URI is blacklisted so that access is prevented.
*
* @param string $uri
* @return boolean
* @param string $uri
* @return bool
*/
private function isAccessAuthorized($uri)
{
foreach ($this->forbiddenUriPatterns as $forbiddenUriPattern)
{
if (preg_match("@$forbiddenUriPattern@", $uri))
{
foreach ($this->forbiddenUriPatterns as $forbiddenUriPattern) {
if (preg_match("@$forbiddenUriPattern@", $uri)) {
return false;
}
}
return true;
}
@@ -121,24 +119,18 @@ public function frontControllerPath($sitePath, $siteName, $uri)
$uri = rtrim($uri, '/');
// try to find the responsible script file for the requested folder / script URI
if (file_exists($absoluteFilePath = $sitePath . $this->documentRoot . $uri))
{
if (is_dir($absoluteFilePath))
{
if (file_exists($absoluteFilePath . '/index.php'))
{
if (file_exists($absoluteFilePath = $sitePath.$this->documentRoot.$uri)) {
if (is_dir($absoluteFilePath)) {
if (file_exists($absoluteFilePath.'/index.php')) {
// this folder can be served by index.php
return $this->serveScript($sitePath, $siteName, $uri . '/index.php');
return $this->serveScript($sitePath, $siteName, $uri.'/index.php');
}
if (file_exists($absoluteFilePath . '/index.html'))
{
if (file_exists($absoluteFilePath.'/index.html')) {
// this folder can be served by index.html
return $absoluteFilePath . '/index.html';
return $absoluteFilePath.'/index.html';
}
}
else if (pathinfo($absoluteFilePath, PATHINFO_EXTENSION) === 'php')
{
} elseif (pathinfo($absoluteFilePath, PATHINFO_EXTENSION) === 'php') {
// this file can be served directly
return $this->serveScript($sitePath, $siteName, $uri);
}
@@ -153,20 +145,18 @@ public function frontControllerPath($sitePath, $siteName, $uri)
* sysext install script. domain.dev/typo3 will be redirected to /typo3/, because
* the generated JavaScript URIs on the login screen would be broken on /typo3.
*
* @param string $uri
* @param string $uri
*/
private function handleRedirectBackendShorthandUris($uri)
{
if (rtrim($uri, '/') === '/typo3/install')
{
if (rtrim($uri, '/') === '/typo3/install') {
header('Location: /typo3/sysext/install/Start/Install.php');
die();
exit();
}
if ($uri === '/typo3')
{
if ($uri === '/typo3') {
header('Location: /typo3/');
die();
exit();
}
}
@@ -182,10 +172,10 @@ private function handleRedirectBackendShorthandUris($uri)
*/
private function serveScript($sitePath, $siteName, $uri)
{
$docroot = $sitePath . $this->documentRoot;
$abspath = $docroot . $uri;
$docroot = $sitePath.$this->documentRoot;
$abspath = $docroot.$uri;
$_SERVER['SERVER_NAME'] = $siteName . '.dev';
$_SERVER['SERVER_NAME'] = $siteName.'.dev';
$_SERVER['DOCUMENT_ROOT'] = $docroot;
$_SERVER['DOCUMENT_URI'] = $uri;
$_SERVER['SCRIPT_FILENAME'] = $abspath;

View File

@@ -166,7 +166,7 @@ public function serveStaticFile($staticFilePath, $sitePath, $siteName, $uri)
header('Content-Type: text/html');
header_remove('Content-Type');
header('X-Accel-Redirect: /' . VALET_STATIC_PREFIX . $staticFilePath);
header('X-Accel-Redirect: /'.VALET_STATIC_PREFIX.$staticFilePath);
}
/**
@@ -182,7 +182,7 @@ protected function isActualFile($path)
/**
* Load server environment variables if available.
* Processes any '*' entries first, and then adds site-specific entries
* Processes any '*' entries first, and then adds site-specific entries.
*
* @param string $sitePath
* @param string $siteName
@@ -190,9 +190,9 @@ protected function isActualFile($path)
*/
public function loadServerEnvironmentVariables($sitePath, $siteName)
{
$varFilePath = $sitePath . '/.valet-env.php';
$varFilePath = $sitePath.'/.valet-env.php';
if (! file_exists($varFilePath)) {
$varFilePath = VALET_HOME_PATH . '/.valet-env.php';
$varFilePath = VALET_HOME_PATH.'/.valet-env.php';
}
if (! file_exists($varFilePath)) {
return;
@@ -207,11 +207,12 @@ public function loadServerEnvironmentVariables($sitePath, $siteName)
}
foreach ($variablesToSet as $key => $value) {
if (! is_string($key)) continue;
if (! is_string($key)) {
continue;
}
$_SERVER[$key] = $value;
$_ENV[$key] = $value;
putenv($key . '=' . $value);
putenv($key.'='.$value);
}
}
}

View File

@@ -25,7 +25,7 @@ public function serves($sitePath, $siteName, $uri)
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
$_SERVER['PHP_SELF'] = $uri;
$_SERVER['PHP_SELF'] = $uri;
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
@@ -37,13 +37,14 @@ public function frontControllerPath($sitePath, $siteName, $uri)
/**
* Redirect to uri with trailing slash.
*
* @param string $uri
* @param string $uri
* @return string
*/
private function forceTrailingSlash($uri)
{
if (substr($uri, -1 * strlen('/wp-admin')) == '/wp-admin') {
header('Location: '.$uri.'/'); die;
header('Location: '.$uri.'/');
exit;
}
return $uri;

View File

@@ -1,6 +1,6 @@
<?php
if (php_sapi_name() !== "cli") {
if (php_sapi_name() !== 'cli') {
// Allow bypassing these checks if using Valet in a non-CLI app
return;
}
@@ -17,7 +17,7 @@
}
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
echo "Valet requires PHP 5.6 or later.";
echo 'Valet requires PHP 5.6 or later.';
exit(1);
}

View File

@@ -29,14 +29,36 @@ public static function __callStatic($method, $parameters)
}
}
class Brew extends Facade {}
class Nginx extends Facade {}
class CommandLine extends Facade {}
class Configuration extends Facade {}
class Diagnose extends Facade {}
class DnsMasq extends Facade {}
class Filesystem extends Facade {}
class Ngrok extends Facade {}
class PhpFpm extends Facade {}
class Site extends Facade {}
class Valet extends Facade {}
class Brew extends Facade
{
}
class Nginx extends Facade
{
}
class CommandLine extends Facade
{
}
class Configuration extends Facade
{
}
class Diagnose extends Facade
{
}
class DnsMasq extends Facade
{
}
class Filesystem extends Facade
{
}
class Ngrok extends Facade
{
}
class PhpFpm extends Facade
{
}
class Site extends Facade
{
}
class Valet extends Facade
{
}

View File

@@ -8,15 +8,15 @@
use Symfony\Component\Console\Output\ConsoleOutput;
/**
* Define constants
* Define constants.
*/
if (! defined('VALET_LOOPBACK')) {
define('VALET_LOOPBACK', '127.0.0.1');
define('VALET_HOME_PATH', $_SERVER['HOME'] . '/.config/valet');
define('VALET_SERVER_PATH', realpath(__DIR__ . '/../../server.php'));
define('VALET_HOME_PATH', $_SERVER['HOME'].'/.config/valet');
define('VALET_SERVER_PATH', realpath(__DIR__.'/../../server.php'));
define('VALET_STATIC_PREFIX', '41c270e4-5535-4daa-b23e-c269744c2f45');
define('VALET_LEGACY_HOME_PATH', $_SERVER['HOME'] . '/.valet');
define('VALET_LEGACY_HOME_PATH', $_SERVER['HOME'].'/.valet');
define('BREW_PREFIX', (new CommandLine())->runAsUser('printf $(brew --prefix)'));
}
@@ -29,7 +29,7 @@
*/
function info($output)
{
output('<info>' . $output . '</info>');
output('<info>'.$output.'</info>');
}
/**
@@ -40,14 +40,14 @@ function info($output)
*/
function warning($output)
{
output('<fg=red>' . $output . '</>');
output('<fg=red>'.$output.'</>');
}
/**
* Output a table to the console.
*
* @param array $headers
* @param array $rows
* @param array $headers
* @param array $rows
* @return void
*/
function table(array $headers = [], array $rows = [])
@@ -165,12 +165,14 @@ function tap($value, callable $callback)
* @param string|array $needles
* @return bool
*/
function ends_with($haystack, $needles) {
function ends_with($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if (substr($haystack, -strlen($needle)) === (string) $needle) {
return true;
}
}
return false;
}
}
@@ -196,7 +198,7 @@ function starts_with($haystack, $needles)
}
/**
* Get the user
* Get the user.
*/
function user()
{

View File

@@ -12,8 +12,8 @@
require getenv('HOME').'/.composer/vendor/autoload.php';
}
use Silly\Application;
use Illuminate\Container\Container;
use Silly\Application;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use function Valet\info;
use function Valet\output;
@@ -23,7 +23,7 @@
/**
* Relocate config dir to ~/.config/valet/ if found in old location.
*/
if (is_dir(VALET_LEGACY_HOME_PATH) && !is_dir(VALET_HOME_PATH)) {
if (is_dir(VALET_LEGACY_HOME_PATH) && ! is_dir(VALET_HOME_PATH)) {
Configuration::createConfigurationDirectory();
}
@@ -66,7 +66,7 @@
*/
if (is_dir(VALET_HOME_PATH)) {
/**
* Upgrade helper: ensure the tld config exists or the loopback config exists
* Upgrade helper: ensure the tld config exists or the loopback config exists.
*/
if (empty(Configuration::read()['tld']) || empty(Configuration::read()['loopback'])) {
Configuration::writeBaseConfiguration();
@@ -126,11 +126,11 @@
$app->command('park [path]', function ($path = null) {
Configuration::addPath($path ?: getcwd());
info(($path === null ? "This" : "The [{$path}]") . " directory has been added to Valet's paths.");
info(($path === null ? 'This' : "The [{$path}]")." directory has been added to Valet's paths.");
})->descriptions('Register the current working (or specified) directory with Valet');
/**
* Get all the current sites within paths parked with 'park {path}'
* Get all the current sites within paths parked with 'park {path}'.
*/
$app->command('parked', function () {
$parked = Site::parked();
@@ -144,7 +144,7 @@
$app->command('forget [path]', function ($path = null) {
Configuration::removePath($path ?: getcwd());
info(($path === null ? "This" : "The [{$path}]") . " directory has been removed from Valet's paths.");
info(($path === null ? 'This' : "The [{$path}]")." directory has been removed from Valet's paths.");
}, ['unpark'])->descriptions('Remove the current working (or specified) directory from Valet\'s list of paths');
/**
@@ -195,6 +195,7 @@
$app->command('unsecure [domain] [--all]', function ($domain = null, $all = null) {
if ($all) {
Site::unsecureAll();
return;
}
@@ -208,17 +209,17 @@
})->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');
/**
* Create an Nginx proxy config for the specified domain
* Create an Nginx proxy config for the specified domain.
*/
$app->command('proxy domain host [--secure]', function ($domain, $host, $secure) {
Site::proxyCreate($domain, $host, $secure);
Nginx::restart();
})->descriptions('Create an Nginx proxy site for the specified host. Useful for docker, mailhog etc.', [
'--secure' => 'Create a proxy with a trusted TLS certificate'
'--secure' => 'Create a proxy with a trusted TLS certificate',
]);
/**
* Delete an Nginx proxy config
* Delete an Nginx proxy config.
*/
$app->command('unproxy domain', function ($domain) {
Site::proxyDelete($domain);
@@ -266,15 +267,15 @@
* Open the current or given directory in the browser.
*/
$app->command('open [domain]', function ($domain = null) {
$url = "http://".($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];
CommandLine::runAsUser("open ".escapeshellarg($url));
$url = 'http://'.($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];
CommandLine::runAsUser('open '.escapeshellarg($url));
})->descriptions('Open the site for the current (or specified) directory in your browser');
/**
* Generate a publicly accessible URL for your project.
*/
$app->command('share', function () {
warning("It looks like you are running `cli/valet.php` directly, please use the `valet` script in the project root instead.");
warning('It looks like you are running `cli/valet.php` directly, please use the `valet` script in the project root instead.');
})->descriptions('Generate a publicly accessible URL for your project');
/**
@@ -391,7 +392,8 @@
info('Removing sudoers entries...');
Brew::removeSudoersEntry();
Valet::removeSudoersEntry();
return output("<fg=red>NOTE:</>
return output('<fg=red>NOTE:</>
<comment>Valet has attempted to uninstall itself, but there are some steps you need to do manually:</comment>
Run <info>php -v</info> to see what PHP version you are now really using.
Run <info>composer global update</info> to update your globally-installed Composer packages to work with your default PHP.
@@ -399,17 +401,17 @@
Thus, you may need to delete things from your <info>~/.composer/composer.json</info> file before running <info>composer global update</info> successfully.
Then to finish removing any Composer fragments of Valet:
Run <info>composer global remove laravel/valet</info>
and then <info>rm ".BREW_PREFIX."/bin/valet</info> to remove the Valet bin link if it still exists.
and then <info>rm '.BREW_PREFIX.'/bin/valet</info> to remove the Valet bin link if it still exists.
Optional:
- <info>brew list --formula</info> will show any other Homebrew services installed, in case you want to make changes to those as well.
- <info>brew doctor</info> can indicate if there might be any broken things left behind.
- <info>brew cleanup</info> can purge old cached Homebrew downloads.
<fg=red>If you had customized your Mac DNS settings in System Preferences->Network, you will need to remove 127.0.0.1 from that list.</>
Additionally you might also want to open Keychain Access and search for <comment>valet</comment> to remove any leftover trust certificates.
");
');
}
output("WAIT! Before you uninstall things, consider cleaning things up in the following order. (Or skip to the bottom for troubleshooting suggestions.):
output('WAIT! Before you uninstall things, consider cleaning things up in the following order. (Or skip to the bottom for troubleshooting suggestions.):
<info>You did not pass the <fg=red>--force</> parameter so we are NOT ACTUALLY uninstalling anything.</info>
A --force removal WILL delete your custom configuration information, so you will want to make backups first.
@@ -428,13 +430,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>".BREW_PREFIX."/etc/</comment> and <comment>".BREW_PREFIX."/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 --formula | 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 ".BREW_PREFIX."/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 --formula</comment>
@@ -449,7 +451,7 @@
<comment>composer global update</comment> to apply updates to packages
<comment>composer global outdated</comment> to identify outdated packages
<comment>composer global diagnose</comment> to run diagnostics
");
');
// Stopping PHP so the ~/.config/valet/valet.sock file is released so the directory can be deleted if desired
PhpFpm::stopRunning();
Nginx::stop();
@@ -483,22 +485,22 @@
info('Sudoers entries have been added for Brew and Valet.');
})->descriptions('Add sudoers files for Brew and Valet to make Valet commands run without passwords', [
'--off' => 'Remove the sudoers files so normal sudo password prompts are required.'
'--off' => 'Remove the sudoers files so normal sudo password prompts are required.',
]);
/**
* Allow the user to change the version of php valet uses
* Allow the user to change the version of php valet uses.
*/
$app->command('use [phpVersion] [--force]', function ($phpVersion, $force) {
if (!$phpVersion) {
$path = getcwd() . '/.valetphprc';
if (! $phpVersion) {
$path = getcwd().'/.valetphprc';
$linkedVersion = Brew::linkedPhp();
if (!file_exists($path)) {
if (! file_exists($path)) {
return info(sprintf('Valet is using %s.', $linkedVersion));
}
$phpVersion = trim(file_get_contents($path));
info('Found \'' . $path . '\' specifying version: ' . $phpVersion);
info('Found \''.$path.'\' specifying version: '.$phpVersion);
if ($linkedVersion == $phpVersion) {
return info(sprintf('Valet is already using %s.', $linkedVersion));
@@ -510,7 +512,7 @@
$newVersion = PhpFpm::useVersion($phpVersion, $force);
Nginx::restart();
info(sprintf('Valet is now using %s.', $newVersion) . PHP_EOL);
info(sprintf('Valet is now using %s.', $newVersion).PHP_EOL);
info('Note that you might need to run <comment>composer global update</comment> if your PHP version change affects the dependencies of global packages required by Composer.');
})->descriptions('Change the version of PHP used by valet', [
'phpVersion' => 'The PHP version you want to use, e.g php@7.3',
@@ -585,8 +587,8 @@
})->descriptions('Tail log file');
/**
* Configure or display the directory-listing setting.
*/
* Configure or display the directory-listing setting.
*/
$app->command('directory-listing [status]', function ($status = null) {
$key = 'directory-listing';
$config = Configuration::read();
@@ -594,13 +596,14 @@
if (in_array($status, ['on', 'off'])) {
$config[$key] = $status;
Configuration::write($config);
return output('Directory listing setting is now: '.$status);
}
$current = isset($config[$key]) ? $config[$key] : 'off';
output('Directory listing is '.$current);
})->descriptions('Determine directory-listing behavior. Default is off, which means a 404 will display.', [
'status' => 'on or off. (default=off) will show a 404 page; [on] will display a listing if project folder exists but requested URI not found'
'status' => 'on or off. (default=off) will show a 404 page; [on] will display a listing if project folder exists but requested URI not found',
]);
/**

View File

@@ -3,7 +3,6 @@
/**
* Define the user's "~/.config/valet" path.
*/
define('VALET_HOME_PATH', posix_getpwuid(fileowner(__FILE__))['dir'].'/.config/valet');
define('VALET_STATIC_PREFIX', '41c270e4-5535-4daa-b23e-c269744c2f45');
@@ -25,7 +24,7 @@ function show_directory_listing($valetSitePath, $uri)
$is_root = ($uri == '/');
$directory = ($is_root) ? $valetSitePath : $valetSitePath.$uri;
if (!file_exists($directory)) {
if (! file_exists($directory)) {
show_valet_404();
}
@@ -37,9 +36,10 @@ function show_directory_listing($valetSitePath, $uri)
// Output the HTML for the directory listing
echo "<h1>Index of $uri</h1>";
echo "<hr>";
echo '<hr>';
echo implode("<br>\n", array_map(function ($path) use ($uri, $is_root) {
$file = basename($path);
return ($is_root) ? "<a href='/$file'>/$file</a>" : "<a href='$uri/$file'>$uri/$file/</a>";
}, $paths));
@@ -49,7 +49,7 @@ function show_directory_listing($valetSitePath, $uri)
/**
* You may use wildcard DNS providers xip.io or nip.io as a tool for testing your site via an IP address.
* It's simple to use: First determine the IP address of your local computer (like 192.168.0.10).
* Then simply use http://project.your-ip.xip.io - ie: http://laravel.192.168.0.10.xip.io
* Then simply use http://project.your-ip.xip.io - ie: http://laravel.192.168.0.10.xip.io.
*/
function valet_support_wildcard_dns($domain, $config)
{
@@ -67,12 +67,12 @@ function valet_support_wildcard_dns($domain, $config)
foreach ($services as $service) {
$pattern = preg_quote($service, '#');
$pattern = str_replace('\*', '.*', $pattern);
$patterns[] = '(.*)' . $pattern;
$patterns[] = '(.*)'.$pattern;
}
$pattern = implode('|', $patterns);
if (preg_match('#(?:' . $pattern . ')\z#u', $domain, $matches)) {
if (preg_match('#(?:'.$pattern.')\z#u', $domain, $matches)) {
$domain = array_pop($matches);
}
@@ -84,8 +84,7 @@ function valet_support_wildcard_dns($domain, $config)
}
/**
* @param array $config Valet configuration array
*
* @param array $config Valet configuration array
* @return string|null If set, default site path for uncaught urls
* */
function valet_default_site_path($config)
@@ -108,7 +107,7 @@ function valet_default_site_path($config)
* Parse the URI and site / host for the incoming request.
*/
$uri = rawurldecode(
explode("?", $_SERVER['REQUEST_URI'])[0]
explode('?', $_SERVER['REQUEST_URI'])[0]
);
$siteName = basename(
@@ -190,7 +189,7 @@ function get_valet_site_path($valetConfig, $siteName, $domain)
/**
* ngrok uses the X-Original-Host to store the forwarded hostname.
*/
if (isset($_SERVER['HTTP_X_ORIGINAL_HOST']) && !isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
if (isset($_SERVER['HTTP_X_ORIGINAL_HOST']) && ! isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_X_ORIGINAL_HOST'];
}

View File

@@ -1,13 +1,13 @@
<?php
use Illuminate\Container\Container;
use Illuminate\Support\Collection;
use Valet\Brew;
use Valet\Filesystem;
use Valet\CommandLine;
use function Valet\user;
use Valet\Filesystem;
use function Valet\resolve;
use function Valet\swap;
use Illuminate\Support\Collection;
use Illuminate\Container\Container;
use function Valet\user;
class BrewTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
@@ -139,6 +139,7 @@ public function test_linked_php_returns_linked_php_formula_name()
$getBrewMock = function ($filesystem) {
$brewMock = Mockery::mock(Brew::class, [new CommandLine, $filesystem])->makePartial();
$brewMock->shouldReceive('hasLinkedPhp')->once()->andReturn(true);
return $brewMock;
};
@@ -314,8 +315,8 @@ public function test_getRunningServices_will_pass_to_brew_services_list_and_retu
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->withArgs([
'brew services list | grep started | awk \'{ print $1; }\'',
Mockery::type('callable')
])->andReturn('service1' . PHP_EOL . 'service2' . PHP_EOL . PHP_EOL . 'service3' . PHP_EOL);
Mockery::type('callable'),
])->andReturn('service1'.PHP_EOL.'service2'.PHP_EOL.PHP_EOL.'service3'.PHP_EOL);
swap(CommandLine::class, $cli);
$result = resolve(Brew::class)->getRunningServices('term');
@@ -338,6 +339,7 @@ public function test_get_parsed_linked_php_will_return_matches_for_linked_php($p
$getBrewMock = function ($filesystem) {
$brewMock = Mockery::mock(Brew::class, [new CommandLine, $filesystem])->makePartial();
$brewMock->shouldReceive('hasLinkedPhp')->once()->andReturn(true);
return $brewMock;
};
@@ -370,7 +372,7 @@ public function test_restart_linked_php_will_pass_through_linked_php_formula_to_
}
/**
* Provider of php links and their expected split matches
* Provider of php links and their expected split matches.
*
* @return array
*/
@@ -397,7 +399,7 @@ public function supportedPhpLinkPathProvider()
'7.4',
'.13',
],
'php@7.4'
'php@7.4',
],
[
'/test/path/php/7.4.9_2/test',

View File

@@ -1,13 +1,13 @@
<?php
use Illuminate\Container\Container;
use Valet\Brew;
use Valet\Valet;
use Valet\Filesystem;
use Valet\Configuration;
use function Valet\user;
use Valet\Filesystem;
use function Valet\resolve;
use function Valet\swap;
use Illuminate\Container\Container;
use function Valet\user;
use Valet\Valet;
class ConfigurationTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{

View File

@@ -1,14 +1,14 @@
<?php
use Illuminate\Container\Container;
use Valet\Brew;
use Valet\DnsMasq;
use Valet\Filesystem;
use Valet\CommandLine;
use Valet\Configuration;
use function Valet\user;
use Valet\DnsMasq;
use Valet\Filesystem;
use function Valet\resolve;
use function Valet\swap;
use Illuminate\Container\Container;
use function Valet\user;
class DnsMasqTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
@@ -38,7 +38,6 @@ public function test_install_installs_and_places_configuration_files_in_proper_l
$dnsMasq = resolve(StubForCreatingCustomDnsMasqConfigFiles::class);
$dnsMasq->dnsmasqMasterConfigFile = __DIR__.'/output/dnsmasq.conf';
$dnsMasq->dnsmasqSystemConfDir = __DIR__.'/output/dnsmasq.d';
$dnsMasq->resolverPath = __DIR__.'/output/resolver';
@@ -50,7 +49,7 @@ public function test_install_installs_and_places_configuration_files_in_proper_l
$this->assertSame('nameserver '.VALET_LOOPBACK.PHP_EOL, file_get_contents(__DIR__.'/output/resolver/test'));
$this->assertSame('address=/.test/'.VALET_LOOPBACK.PHP_EOL.'listen-address='.VALET_LOOPBACK.PHP_EOL, file_get_contents(__DIR__.'/output/tld-test.conf'));
$this->assertSame('test-contents
' . PHP_EOL . 'conf-dir='.BREW_PREFIX.'/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

@@ -1,13 +1,13 @@
<?php
use Valet\Site;
use Valet\Nginx;
use Valet\Filesystem;
use Valet\Configuration;
use function Valet\user;
use function Valet\resolve;
use function Valet\swap;
use Illuminate\Container\Container;
use Valet\Configuration;
use Valet\Filesystem;
use Valet\Nginx;
use function Valet\resolve;
use Valet\Site;
use function Valet\swap;
use function Valet\user;
class NginxTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{

View File

@@ -1,13 +1,13 @@
<?php
use Valet\Brew;
use Valet\PhpFpm;
use Valet\Filesystem;
use Valet\CommandLine;
use function Valet\user;
use function Valet\swap;
use function Valet\resolve;
use Illuminate\Container\Container;
use Valet\Brew;
use Valet\CommandLine;
use Valet\Filesystem;
use Valet\PhpFpm;
use function Valet\resolve;
use function Valet\swap;
use function Valet\user;
class PhpFpmTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
@@ -36,7 +36,7 @@ public function test_fpm_is_configured_with_the_correct_user_group_and_port()
$contents = file_get_contents(__DIR__.'/output/fpm.conf');
$this->assertStringContainsString(sprintf("\nuser = %s", user()), $contents);
$this->assertStringContainsString("\ngroup = staff", $contents);
$this->assertStringContainsString("\nlisten = ".VALET_HOME_PATH."/valet.sock", $contents);
$this->assertStringContainsString("\nlisten = ".VALET_HOME_PATH.'/valet.sock', $contents);
}
public function test_stopRunning_will_pass_filtered_result_of_getRunningServices_to_stopService()
@@ -136,10 +136,9 @@ public function test_use_version_if_already_linked_php_will_unlink_before_instal
}
}
class StubForUpdatingFpmConfigFiles extends PhpFpm
{
function fpmConfigPath()
public function fpmConfigPath()
{
return __DIR__.'/output/fpm.conf';
}

View File

@@ -1,13 +1,13 @@
<?php
use Valet\CommandLine;
use Valet\Site;
use Valet\Filesystem;
use Valet\Configuration;
use function Valet\user;
use function Valet\resolve;
use function Valet\swap;
use Illuminate\Container\Container;
use Valet\CommandLine;
use Valet\Configuration;
use Valet\Filesystem;
use function Valet\resolve;
use Valet\Site;
use function Valet\swap;
use function Valet\user;
class SiteTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
@@ -63,7 +63,7 @@ public function test_get_sites_will_return_if_secured()
->andReturn(false);
$files->shouldReceive('realpath')
->twice()
->andReturn($dirPath . '/sitetwo', $dirPath . '/sitethree');
->andReturn($dirPath.'/sitetwo', $dirPath.'/sitethree');
$files->shouldReceive('isDir')->andReturn(true);
$files->shouldReceive('ensureDirExists')
->once()
@@ -95,13 +95,13 @@ public function test_get_sites_will_return_if_secured()
'site' => 'sitetwo',
'secured' => '',
'url' => 'http://sitetwo.local',
'path' => $dirPath . '/sitetwo',
'path' => $dirPath.'/sitetwo',
], $sites->first());
$this->assertSame([
'site' => 'sitethree',
'secured' => ' X',
'url' => 'https://sitethree.local',
'path' => $dirPath . '/sitethree',
'path' => $dirPath.'/sitethree',
], $sites->last());
}
@@ -115,13 +115,13 @@ public function test_get_sites_will_work_with_non_symlinked_path()
->andReturn(['sitetwo']);
$files->shouldReceive('isLink')
->once()
->with($dirPath . '/sitetwo')
->with($dirPath.'/sitetwo')
->andReturn(false);
$files->shouldReceive('realpath')
->once()
->with($dirPath . '/sitetwo')
->andReturn($dirPath . '/sitetwo');
$files->shouldReceive('isDir')->once()->with($dirPath . '/sitetwo')->andReturn(true);
->with($dirPath.'/sitetwo')
->andReturn($dirPath.'/sitetwo');
$files->shouldReceive('isDir')->once()->with($dirPath.'/sitetwo')->andReturn(true);
$files->shouldReceive('ensureDirExists')
->once()
->with($dirPath, user());
@@ -143,7 +143,7 @@ public function test_get_sites_will_work_with_non_symlinked_path()
'site' => 'sitetwo',
'secured' => '',
'url' => 'http://sitetwo.local',
'path' => $dirPath . '/sitetwo',
'path' => $dirPath.'/sitetwo',
], $sites->first());
}
@@ -156,7 +156,7 @@ public function test_get_sites_will_not_return_if_path_is_not_directory()
->with($dirPath)
->andReturn(['sitetwo', 'siteone']);
$files->shouldReceive('isLink')->andReturn(false);
$files->shouldReceive('realpath')->andReturn($dirPath . '/sitetwo', $dirPath . '/siteone');
$files->shouldReceive('realpath')->andReturn($dirPath.'/sitetwo', $dirPath.'/siteone');
$files->shouldReceive('isDir')->twice()
->andReturn(false, true);
$files->shouldReceive('ensureDirExists')
@@ -180,7 +180,7 @@ public function test_get_sites_will_not_return_if_path_is_not_directory()
'site' => 'siteone',
'secured' => '',
'url' => 'http://siteone.local',
'path' => $dirPath . '/siteone',
'path' => $dirPath.'/siteone',
], $sites->first());
}
@@ -194,11 +194,11 @@ public function test_get_sites_will_work_with_symlinked_path()
->andReturn(['siteone']);
$files->shouldReceive('isLink')
->once()
->with($dirPath . '/siteone')
->with($dirPath.'/siteone')
->andReturn(true);
$files->shouldReceive('readLink')
->once()
->with($dirPath . '/siteone')
->with($dirPath.'/siteone')
->andReturn($linkedPath = '/Users/usertest/linkedpath/siteone');
$files->shouldReceive('isDir')->andReturn(true);
$files->shouldReceive('ensureDirExists')
@@ -368,7 +368,6 @@ public function test_add_proxy()
], $site->proxies()->all());
}
public function test_add_non_secure_proxy()
{
$config = Mockery::mock(Configuration::class);
@@ -402,7 +401,6 @@ public function test_add_non_secure_proxy()
], $site->proxies()->all());
}
public function test_add_proxy_clears_previous_proxy_certificate()
{
$config = Mockery::mock(Configuration::class);
@@ -530,7 +528,6 @@ public function test_remove_proxy()
}
}
class CommandLineFake extends CommandLine
{
public function runCommand($command, callable $onError = null)
@@ -545,7 +542,6 @@ public function runCommand($command, callable $onError = null)
}
}
class FixturesSiteFake extends Site
{
private $valetHomePath;
@@ -652,7 +648,6 @@ public function assertCertificateExistsWithCounterValue($urlWithTld, $counter)
}
}
class StubForRemovingLinks extends Site
{
public function sitesPath($additionalPath = null)