Skip to content

Commit c0a2c7e

Browse files
committed
Merge branch 'master' into feature/trust-ca-cert
2 parents c79bc98 + 59b19a2 commit c0a2c7e

19 files changed

+230
-51
lines changed

cli/Valet/Brew.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ function ($version) use ($resolvedPhpVersion) {
292292
*
293293
* @param string|null $phpVersion For example, "php@8.1"
294294
*/
295-
public function getPhpExecutablePath(string $phpVersion = null): string
295+
public function getPhpExecutablePath(?string $phpVersion = null): string
296296
{
297297
if (! $phpVersion) {
298298
return BREW_PREFIX.'/bin/php';

cli/Valet/CommandLine.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ public function passthru(string $command): void
3333
/**
3434
* Run the given command as the non-root user.
3535
*/
36-
public function run(string $command, callable $onError = null): string
36+
public function run(string $command, ?callable $onError = null): string
3737
{
3838
return $this->runCommand($command, $onError);
3939
}
4040

4141
/**
4242
* Run the given command.
4343
*/
44-
public function runAsUser(string $command, callable $onError = null): string
44+
public function runAsUser(string $command, ?callable $onError = null): string
4545
{
4646
return $this->runCommand('sudo -u "'.user().'" '.$command, $onError);
4747
}
4848

4949
/**
5050
* Run the given command.
5151
*/
52-
public function runCommand(string $command, callable $onError = null): string
52+
public function runCommand(string $command, ?callable $onError = null): string
5353
{
5454
$onError = $onError ?: function () {
5555
};

cli/Valet/Expose.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function __construct(public Composer $composer, public CommandLine $cli)
1111
{
1212
}
1313

14-
public function currentTunnelUrl(string $domain = null): ?string
14+
public function currentTunnelUrl(?string $domain = null): ?string
1515
{
1616
$endpoint = 'http://127.0.0.1:4040/api/tunnels';
1717

cli/Valet/Filesystem.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function isDir(string $path): bool
1919
/**
2020
* Create a directory.
2121
*/
22-
public function mkdir(string $path, string $owner = null, int $mode = 0755): void
22+
public function mkdir(string $path, ?string $owner = null, int $mode = 0755): void
2323
{
2424
mkdir($path, $mode, true);
2525

@@ -31,7 +31,7 @@ public function mkdir(string $path, string $owner = null, int $mode = 0755): voi
3131
/**
3232
* Ensure that the given directory exists.
3333
*/
34-
public function ensureDirExists(string $path, string $owner = null, int $mode = 0755): void
34+
public function ensureDirExists(string $path, ?string $owner = null, int $mode = 0755): void
3535
{
3636
if (! $this->isDir($path)) {
3737
$this->mkdir($path, $owner, $mode);
@@ -49,7 +49,7 @@ public function mkdirAsUser(string $path, int $mode = 0755): void
4949
/**
5050
* Touch the given path.
5151
*/
52-
public function touch(string $path, string $owner = null): string
52+
public function touch(string $path, ?string $owner = null): string
5353
{
5454
touch($path);
5555

@@ -87,7 +87,7 @@ public function get(string $path): string
8787
/**
8888
* Write to the given file.
8989
*/
90-
public function put(string $path, string $contents, string $owner = null): void
90+
public function put(string $path, string $contents, ?string $owner = null): void
9191
{
9292
file_put_contents($path, $contents);
9393

@@ -107,7 +107,7 @@ public function putAsUser(string $path, ?string $contents): void
107107
/**
108108
* Append the contents to the given file.
109109
*/
110-
public function append(string $path, string $contents, string $owner = null): void
110+
public function append(string $path, string $contents, ?string $owner = null): void
111111
{
112112
file_put_contents($path, $contents, FILE_APPEND);
113113

cli/Valet/Ngrok.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(public CommandLine $cli, public Brew $brew)
2020
/**
2121
* Get the current tunnel URL from the Ngrok API.
2222
*/
23-
public function currentTunnelUrl(string $domain = null): string
23+
public function currentTunnelUrl(?string $domain = null): string
2424
{
2525
// wait a second for ngrok to start before attempting to find available tunnels
2626
sleep(1);
@@ -51,20 +51,30 @@ public function currentTunnelUrl(string $domain = null): string
5151
}
5252

5353
/**
54-
* Find the HTTP tunnel URL from the list of tunnels.
54+
* Find the HTTP/HTTPS tunnel URL from the list of tunnels.
5555
*/
5656
public function findHttpTunnelUrl(array $tunnels, string $domain): ?string
5757
{
58+
$httpTunnel = null;
59+
$httpsTunnel = null;
60+
5861
// If there are active tunnels on the Ngrok instance we will spin through them and
5962
// find the one responding on HTTP. Each tunnel has an HTTP and a HTTPS address
60-
// but for local dev purposes we just desire the plain HTTP URL endpoint.
63+
// if no HTTP tunnel is found we will return the HTTPS tunnel as a fallback.
64+
65+
// Iterate through tunnels to find both HTTP and HTTPS tunnels
6166
foreach ($tunnels as $tunnel) {
62-
if ($tunnel->proto === 'http' && strpos($tunnel->config->addr, strtolower($domain))) {
63-
return $tunnel->public_url;
67+
if (stripos($tunnel->config->addr, $domain)) {
68+
if ($tunnel->proto === 'http') {
69+
$httpTunnel = $tunnel->public_url;
70+
} elseif ($tunnel->proto === 'https') {
71+
$httpsTunnel = $tunnel->public_url;
72+
}
6473
}
6574
}
6675

67-
return null;
76+
// Return HTTP tunnel if available; HTTPS tunnel if not; null if neither
77+
return $httpTunnel ?? $httpsTunnel;
6878
}
6979

7080
/**

cli/Valet/PhpFpm.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function createConfigurationFiles(string $phpVersion): void
102102
/**
103103
* Restart the PHP FPM process (if one specified) or processes (if none specified).
104104
*/
105-
public function restart(string $phpVersion = null): void
105+
public function restart(?string $phpVersion = null): void
106106
{
107107
$this->brew->restartService($phpVersion ?: $this->utilizedPhpVersions());
108108
}
@@ -122,7 +122,7 @@ public function stop(): void
122122
/**
123123
* Get the path to the FPM configuration file for the current PHP version.
124124
*/
125-
public function fpmConfigPath(string $phpVersion = null): string
125+
public function fpmConfigPath(?string $phpVersion = null): string
126126
{
127127
if (! $phpVersion) {
128128
$phpVersion = $this->brew->linkedPhp();
@@ -152,7 +152,7 @@ public function stopRunning(): void
152152
/**
153153
* Stop a given PHP version, if that specific version isn't being used globally or by any sites.
154154
*/
155-
public function stopIfUnused(string $phpVersion = null): void
155+
public function stopIfUnused(?string $phpVersion = null): void
156156
{
157157
if (! $phpVersion) {
158158
return;
@@ -305,7 +305,7 @@ public function validateRequestedVersion(string $version): string
305305
/**
306306
* Get FPM sock file name for a given PHP version.
307307
*/
308-
public static function fpmSockName(string $phpVersion = null): string
308+
public static function fpmSockName(?string $phpVersion = null): string
309309
{
310310
$versionInteger = preg_replace('~[^\d]~', '', $phpVersion);
311311

cli/Valet/Site.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function getSiteUrl(string $directory): string
189189
/**
190190
* Identify whether a site is for a proxy by reading the host name from its config file.
191191
*/
192-
public function getProxyHostForSite(string $site, string $configContents = null): ?string
192+
public function getProxyHostForSite(string $site, ?string $configContents = null): ?string
193193
{
194194
$siteConf = $configContents ?: $this->getSiteConfigFileContents($site);
195195

@@ -208,7 +208,7 @@ public function getProxyHostForSite(string $site, string $configContents = null)
208208
/**
209209
* Get the contents of the configuration for the given site.
210210
*/
211-
public function getSiteConfigFileContents(string $site, string $suffix = null): ?string
211+
public function getSiteConfigFileContents(string $site, ?string $suffix = null): ?string
212212
{
213213
$config = $this->config->read();
214214
$suffix = $suffix ?: '.'.$config['tld'];
@@ -220,7 +220,7 @@ public function getSiteConfigFileContents(string $site, string $suffix = null):
220220
/**
221221
* Get all certificates from config folder.
222222
*/
223-
public function getCertificates(string $path = null): Collection
223+
public function getCertificates(?string $path = null): Collection
224224
{
225225
$path = $path ?: $this->certificatesPath();
226226

@@ -284,7 +284,7 @@ public function getSites(string $path, Collection $certs): Collection
284284
/**
285285
* Unlink the given symbolic link.
286286
*/
287-
public function unlink(string $name = null): string
287+
public function unlink(?string $name = null): string
288288
{
289289
$name = $this->getSiteLinkName($name);
290290

@@ -442,8 +442,7 @@ public function secured(): array
442442
public function securedWithDates(): array
443443
{
444444
return collect($this->secured())->map(function ($site) {
445-
446-
$filePath = $this->certificatesPath() . '/' . $site . '.crt';
445+
$filePath = $this->certificatesPath().'/'.$site.'.crt';
447446

448447
$expiration = $this->cli->run("openssl x509 -enddate -noout -in $filePath");
449448

@@ -473,7 +472,7 @@ public function isSecured(string $site): bool
473472
*
474473
* @see https://github.com/cabforum/servercert/blob/main/docs/BR.md
475474
*/
476-
public function secure(string $url, string $siteConf = null, int $certificateExpireInDays = 396, int $caExpireInYears = 20): void
475+
public function secure(string $url, ?string $siteConf = null, int $certificateExpireInDays = 396, int $caExpireInYears = 20): void
477476
{
478477
// Extract in order to later preserve custom PHP version config when securing
479478
$phpVersion = $this->customPhpVersion($url);
@@ -511,7 +510,7 @@ public function renew($expireIn): void
511510

512511
$this->secure($url, null, $expireIn);
513512

514-
info('The [' . $url . '] site has been secured with a fresh TLS certificate.');
513+
info('The ['.$url.'] site has been secured with a fresh TLS certificate.');
515514
});
516515
}
517516

@@ -669,11 +668,14 @@ public function buildCertificateConf(string $path, string $url): void
669668
/**
670669
* Build the TLS secured Nginx server for the given URL.
671670
*/
672-
public function buildSecureNginxServer(string $url, string $siteConf = null): string
671+
public function buildSecureNginxServer(string $url, ?string $siteConf = null): string
673672
{
674673
if ($siteConf === null) {
674+
$nginxVersion = str_replace('nginx version: nginx/', '', exec('nginx -v 2>&1'));
675+
$configFile = version_compare($nginxVersion, '1.25.1', '>=') ? 'secure.valet.conf' : 'secure.valet-legacy.conf';
676+
675677
$siteConf = $this->replaceOldLoopbackWithNew(
676-
$this->files->getStub('secure.valet.conf'),
678+
$this->files->getStub($configFile),
677679
'VALET_LOOPBACK',
678680
$this->valetLoopback()
679681
);
@@ -815,8 +817,11 @@ public function proxyCreate(string $url, string $host, bool $secure = false): vo
815817
$proxyUrl .= '.'.$tld;
816818
}
817819

820+
$nginxVersion = str_replace('nginx version: nginx/', '', exec('nginx -v 2>&1'));
821+
$configFile = version_compare($nginxVersion, '1.25.1', '>=') ? 'secure.proxy.valet.conf' : 'secure.proxy.valet-legacy.conf';
822+
818823
$siteConf = $this->replaceOldLoopbackWithNew(
819-
$this->files->getStub($secure ? 'secure.proxy.valet.conf' : 'proxy.valet.conf'),
824+
$this->files->getStub($secure ? $configFile : 'proxy.valet.conf'),
820825
'VALET_LOOPBACK',
821826
$this->valetLoopback()
822827
);
@@ -984,31 +989,31 @@ public function plistPath(): string
984989
/**
985990
* Get the path to Nginx site configuration files.
986991
*/
987-
public function nginxPath(string $additionalPath = null): string
992+
public function nginxPath(?string $additionalPath = null): string
988993
{
989994
return $this->valetHomePath().'/Nginx'.($additionalPath ? '/'.$additionalPath : '');
990995
}
991996

992997
/**
993998
* Get the path to the linked Valet sites.
994999
*/
995-
public function sitesPath(string $link = null): string
1000+
public function sitesPath(?string $link = null): string
9961001
{
9971002
return $this->valetHomePath().'/Sites'.($link ? '/'.$link : '');
9981003
}
9991004

10001005
/**
10011006
* Get the path to the Valet CA certificates.
10021007
*/
1003-
public function caPath(string $caFile = null): string
1008+
public function caPath(?string $caFile = null): string
10041009
{
10051010
return $this->valetHomePath().'/CA'.($caFile ? '/'.$caFile : '');
10061011
}
10071012

10081013
/**
10091014
* Get the path to the Valet TLS certificates.
10101015
*/
1011-
public function certificatesPath(string $url = null, string $extension = null): string
1016+
public function certificatesPath(?string $url = null, ?string $extension = null): string
10121017
{
10131018
$url = $url ? '/'.$url : '';
10141019
$extension = $extension ? '.'.$extension : '';
@@ -1092,7 +1097,7 @@ public function replaceSockFile(string $siteConf, string $phpVersion): string
10921097
/**
10931098
* Get configuration items defined in .valetrc for a site.
10941099
*/
1095-
public function valetRc(string $siteName, string $cwd = null): array
1100+
public function valetRc(string $siteName, ?string $cwd = null): array
10961101
{
10971102
if ($cwd) {
10981103
$path = $cwd.'/.valetrc';
@@ -1118,7 +1123,7 @@ public function valetRc(string $siteName, string $cwd = null): array
11181123
/**
11191124
* Get PHP version from .valetrc or .valetphprc for a site.
11201125
*/
1121-
public function phpRcVersion(string $siteName, string $cwd = null): ?string
1126+
public function phpRcVersion(string $siteName, ?string $cwd = null): ?string
11221127
{
11231128
if ($cwd) {
11241129
$oldPath = $cwd.'/.valetphprc';

cli/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function (ConsoleCommandEvent $event) {
280280
* Display all of the currently secured sites.
281281
*/
282282
$app->command('secured [--expiring] [--days=]', function (OutputInterface $output, $expiring = null, $days = 60) {
283-
$now = (new Datetime())->add(new DateInterval('P' . $days . 'D'));
283+
$now = (new Datetime())->add(new DateInterval('P'.$days.'D'));
284284
$sites = collect(Site::securedWithDates())
285285
->when($expiring, fn ($collection) => $collection->filter(fn ($row) => $row['exp'] < $now))
286286
->map(function ($row) {

cli/includes/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* Set or get a global console writer.
3434
*/
35-
function writer(OutputInterface $writer = null): OutputInterface|\NullWriter|null
35+
function writer(?OutputInterface $writer = null): OutputInterface|\NullWriter|null
3636
{
3737
$container = Container::getInstance();
3838

cli/stubs/etc-phpfpm-valet.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ pm.start_servers = 2
2424
pm.min_spare_servers = 1
2525
pm.max_spare_servers = 3
2626

27+
;; these are an attempt to mitigate 502 errors caused by segfaults in upstream processes caused by krb5 v1.21 added in June 2023 to php's core build. Ref Issue #1433
28+
; for gettext
29+
env['LC_ALL'] = C
30+
; for postgres
31+
env['PGGSSENCMODE'] = disable
32+

0 commit comments

Comments
 (0)