Skip to content

Commit dce6b3c

Browse files
authored
Merge branch 'master' into cloudflared
2 parents ca1518a + e67f5b0 commit dce6b3c

28 files changed

+206
-111
lines changed

.github/ISSUE_TEMPLATE/1_Bug_report.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Bug Report
2-
description: "Report a general library issue."
2+
description: "Report something that's broken."
33
body:
44
- type: markdown
55
attributes:

.github/workflows/coding-standards.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: fix code styling
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- '*.x'
48

59
jobs:
610
lint:

CHANGELOG.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
# Release Notes
22

3-
## [Unreleased](https://github.com/laravel/valet/compare/v4.6.1...master)
3+
## [Unreleased](https://github.com/laravel/valet/compare/v4.7.1...master)
4+
5+
## [v4.7.1](https://github.com/laravel/valet/compare/v4.7.0...v4.7.1) - 2024-06-25
6+
7+
* Require Trusting CA when securing sites by [@adrum](https://github.com/adrum) in https://github.com/laravel/valet/pull/1488
8+
9+
## [v4.7.0](https://github.com/laravel/valet/compare/v4.6.3...v4.7.0) - 2024-06-18
10+
11+
* Trust CA Certificate only by [@adrum](https://github.com/adrum) in https://github.com/laravel/valet/pull/1463
12+
* Allow specifying php version to restart by [@N-Silbernagel](https://github.com/N-Silbernagel) in https://github.com/laravel/valet/pull/1469
13+
* Update KirbyValetDriver.php by [@Werbschaft](https://github.com/Werbschaft) in https://github.com/laravel/valet/pull/1471
14+
* fix: Warning: Constant VALET_* already defined in X by [@NickSdot](https://github.com/NickSdot) in https://github.com/laravel/valet/pull/1485
15+
* Add values() call to reset keys after modifying paths by [@adriaanzon](https://github.com/adriaanzon) in https://github.com/laravel/valet/pull/1477
16+
* Adding support for Nette Framework. by [@antonL95](https://github.com/antonL95) in https://github.com/laravel/valet/pull/1486
17+
18+
## [v4.6.3](https://github.com/laravel/valet/compare/v4.6.2...v4.6.3) - 2024-05-21
19+
20+
* add server name to valet.conf by [@Oleg339](https://github.com/Oleg339) in https://github.com/laravel/valet/pull/1458
21+
22+
## [v4.6.2](https://github.com/laravel/valet/compare/v4.6.1...v4.6.2) - 2024-05-07
23+
24+
* Add quotes around $PHP by [@drbyte](https://github.com/drbyte) in https://github.com/laravel/valet/pull/1473
25+
* Support Illuminate:11 and Symfony:7 by [@drbyte](https://github.com/drbyte) in https://github.com/laravel/valet/pull/1481
26+
* Ignore invalid paths by [@ahmedash95](https://github.com/ahmedash95) in https://github.com/laravel/valet/pull/1478
427

528
## [v4.6.1](https://github.com/laravel/valet/compare/v4.6.0...v4.6.1) - 2024-01-01
629

cli/Valet/Brew.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class Brew
3838

3939
const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1';
4040

41-
public function __construct(public CommandLine $cli, public Filesystem $files)
42-
{
43-
}
41+
public function __construct(public CommandLine $cli, public Filesystem $files) {}
4442

4543
/**
4644
* Ensure the formula exists in the current Homebrew configuration.

cli/Valet/CommandLine.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public function runAsUser(string $command, ?callable $onError = null): string
5151
*/
5252
public function runCommand(string $command, ?callable $onError = null): string
5353
{
54-
$onError = $onError ?: function () {
55-
};
54+
$onError = $onError ?: function () {};
5655

5756
// Symfony's 4.x Process component has deprecated passing a command string
5857
// to the constructor, but older versions (which Valet's Composer

cli/Valet/Composer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
class Composer
88
{
9-
public function __construct(public CommandLine $cli)
10-
{
11-
}
9+
public function __construct(public CommandLine $cli) {}
1210

1311
public function installed(string $namespacedPackage): bool
1412
{

cli/Valet/Configuration.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
class Configuration
66
{
7-
public function __construct(public Filesystem $files)
8-
{
9-
}
7+
public function __construct(public Filesystem $files) {}
108

119
/**
1210
* Install the Valet configuration file.
@@ -117,7 +115,7 @@ public function addPath(string $path, bool $prepend = false): void
117115
$this->write(tap($this->read(), function (&$config) use ($path, $prepend) {
118116
$method = $prepend ? 'prepend' : 'push';
119117

120-
$config['paths'] = collect($config['paths'])->{$method}($path)->unique()->all();
118+
$config['paths'] = collect($config['paths'])->{$method}($path)->unique()->values()->all();
121119
}));
122120
}
123121

cli/Valet/Diagnose.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ class Diagnose
5555

5656
public $progressBar;
5757

58-
public function __construct(public CommandLine $cli, public Filesystem $files)
59-
{
60-
}
58+
public function __construct(public CommandLine $cli, public Filesystem $files) {}
6159

6260
/**
6361
* Run diagnostics.

cli/Valet/DnsMasq.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ class DnsMasq
1010

1111
public $resolverPath = '/etc/resolver';
1212

13-
public function __construct(public Brew $brew, public CommandLine $cli, public Filesystem $files, public Configuration $configuration)
14-
{
15-
}
13+
public function __construct(public Brew $brew, public CommandLine $cli, public Filesystem $files, public Configuration $configuration) {}
1614

1715
/**
1816
* Install and configure DnsMasq.

cli/Valet/Drivers/Specific/KirbyValetDriver.php

+11
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ public function frontControllerPath(string $sitePath, string $siteName, string $
4848
$indexPath = $sitePath.'/panel/index.php';
4949
}
5050

51+
// add this block
52+
if (preg_match('/^\/(?!(kirby|site|content)\/).+\.php$/', $uri)) {
53+
if (
54+
$this->isActualFile($sitePath.$uri) ||
55+
$isAboveWebroot && $this->isActualFile($sitePath.'/public'.$uri)
56+
) {
57+
$scriptName = $uri;
58+
$indexPath = $sitePath.$scriptName;
59+
}
60+
}
61+
5162
$sitePathPrefix = ($isAboveWebroot) ? $sitePath.'/public' : $sitePath;
5263

5364
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Valet\Drivers\Specific;
4+
5+
use Valet\Drivers\ValetDriver;
6+
7+
class NetteValetDriver extends ValetDriver
8+
{
9+
/**
10+
* Determine if the driver serves the request.
11+
*/
12+
public function serves(string $sitePath, string $siteName, string $uri): bool
13+
{
14+
return file_exists($sitePath.'/www/index.php')
15+
&& file_exists($sitePath.'/www/.htaccess')
16+
&& file_exists($sitePath.'/config/common.neon')
17+
&& file_exists($sitePath.'/config/services.neon');
18+
}
19+
20+
/**
21+
* Determine if the incoming request is for a static file.
22+
*/
23+
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
24+
{
25+
if ($this->isActualFile($staticFilePath = $sitePath.'/www/'.$uri)) {
26+
return $staticFilePath;
27+
}
28+
29+
return false;
30+
}
31+
32+
/**
33+
* Get the fully resolved path to the application's front controller.
34+
*/
35+
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
36+
{
37+
$_SERVER['DOCUMENT_ROOT'] = $sitePath.'/www';
38+
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/www/index.php';
39+
$_SERVER['SCRIPT_NAME'] = '/index.php';
40+
$_SERVER['PHP_SELF'] = '/index.php';
41+
42+
return $sitePath.'/www/index.php';
43+
}
44+
}

cli/Valet/Expose.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
class Expose
99
{
10-
public function __construct(public Composer $composer, public CommandLine $cli)
11-
{
12-
}
10+
public function __construct(public Composer $composer, public CommandLine $cli) {}
1311

1412
public function currentTunnelUrl(?string $domain = null): ?string
1513
{

cli/Valet/Nginx.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ class Nginx
1010
const NGINX_CONF = BREW_PREFIX.'/etc/nginx/nginx.conf';
1111

1212
public function __construct(public Brew $brew, public CommandLine $cli, public Filesystem $files,
13-
public Configuration $configuration, public Site $site)
14-
{
15-
}
13+
public Configuration $configuration, public Site $site) {}
1614

1715
/**
1816
* Install the configuration files for Nginx.

cli/Valet/Ngrok.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class Ngrok
1313
'http://127.0.0.1:4041/api/tunnels',
1414
];
1515

16-
public function __construct(public CommandLine $cli, public Brew $brew)
17-
{
18-
}
16+
public function __construct(public CommandLine $cli, public Brew $brew) {}
1917

2018
/**
2119
* Get the current tunnel URL from the Ngrok API.

cli/Valet/PhpFpm.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class PhpFpm
1212
'shivammathur/php',
1313
];
1414

15-
public function __construct(public Brew $brew, public CommandLine $cli, public Filesystem $files, public Configuration $config, public Site $site, public Nginx $nginx)
16-
{
17-
}
15+
public function __construct(public Brew $brew, public CommandLine $cli, public Filesystem $files, public Configuration $config, public Site $site, public Nginx $nginx) {}
1816

1917
/**
2018
* Install and configure PhpFpm.

cli/Valet/Server.php

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ public function sitePath(string $siteName): ?string
160160
$domain = static::domainFromSiteName($siteName);
161161

162162
foreach ($this->config['paths'] as $path) {
163+
if (! is_dir($path)) {
164+
continue;
165+
}
166+
163167
$handle = opendir($path);
164168

165169
if ($handle === false) {

cli/Valet/Site.php

+23-12
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
class Site
1111
{
12-
public function __construct(public Brew $brew, public Configuration $config, public CommandLine $cli, public Filesystem $files)
13-
{
14-
}
12+
public function __construct(public Brew $brew, public Configuration $config, public CommandLine $cli, public Filesystem $files) {}
1513

1614
/**
1715
* Get the name of the site.
@@ -477,17 +475,18 @@ public function secure(string $url, ?string $siteConf = null, int $certificateEx
477475
// Extract in order to later preserve custom PHP version config when securing
478476
$phpVersion = $this->customPhpVersion($url);
479477

480-
$this->unsecure($url);
481-
478+
// Create the CA if it doesn't exist.
479+
// If the user cancels the trust operation, the old certificate will not be removed.
482480
$this->files->ensureDirExists($this->caPath(), user());
481+
$caExpireInDate = (new \DateTime())->diff(new \DateTime("+{$caExpireInYears} years"));
482+
$this->createCa($caExpireInDate->format('%a'));
483+
484+
$this->unsecure($url);
483485

484486
$this->files->ensureDirExists($this->certificatesPath(), user());
485487

486488
$this->files->ensureDirExists($this->nginxPath(), user());
487489

488-
$caExpireInDate = (new \DateTime())->diff(new \DateTime("+{$caExpireInYears} years"));
489-
490-
$this->createCa($caExpireInDate->format('%a'));
491490
$this->createCertificate($url, $certificateExpireInDays);
492491

493492
$siteConf = $this->buildSecureNginxServer($url, $siteConf);
@@ -525,6 +524,15 @@ public function createCa(int $caExpireInDays): void
525524
$caKeyPath = $this->caPath('LaravelValetCASelfSigned.key');
526525

527526
if ($this->files->exists($caKeyPath) && $this->files->exists($caPemPath)) {
527+
528+
$isTrusted = $this->cli->run(sprintf(
529+
'security verify-cert -c "%s"', $caPemPath
530+
));
531+
532+
if (strpos($isTrusted, '...certificate verification successful.') === false) {
533+
$this->trustCa($caPemPath);
534+
}
535+
528536
return;
529537
}
530538

@@ -607,8 +615,6 @@ public function createCertificate(string $url, int $caExpireInDays): void
607615
$caExpireInDays, $caPemPath, $caKeyPath, $caSrlParam, $csrPath, $crtPath, $confPath
608616
));
609617
}
610-
611-
$this->trustCertificate($crtPath);
612618
}
613619

614620
/**
@@ -635,9 +641,14 @@ public function createSigningRequest(string $url, string $keyPath, string $csrPa
635641
*/
636642
public function trustCa(string $caPemPath): void
637643
{
638-
$this->cli->run(sprintf(
639-
'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "%s"', $caPemPath
644+
info('Trusting Laravel Valet Certificate Authority...');
645+
$result = $this->cli->run(sprintf(
646+
'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "%s"',
647+
$caPemPath
640648
));
649+
if ($result) {
650+
throw new DomainException('The Certificate Authority must be trusted. Please run the command again.');
651+
}
641652
}
642653

643654
/**

cli/Valet/Status.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ class Status
1010

1111
public $debugInstructions = [];
1212

13-
public function __construct(public Configuration $config, public Brew $brew, public CommandLine $cli, public Filesystem $files)
14-
{
15-
}
13+
public function __construct(public Configuration $config, public Brew $brew, public CommandLine $cli, public Filesystem $files) {}
1614

1715
/**
1816
* Check the status of the entire Valet ecosystem and return a status boolean

cli/Valet/Upgrader.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
class Upgrader
99
{
10-
public function __construct(public Filesystem $files)
11-
{
12-
}
10+
public function __construct(public Filesystem $files) {}
1311

1412
/**
1513
* Run all the upgrades that should be run every time Valet commands are run.

cli/Valet/Valet.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class Valet
88
{
99
public $valetBin = BREW_PREFIX.'/bin/valet';
1010

11-
public function __construct(public CommandLine $cli, public Filesystem $files)
12-
{
13-
}
11+
public function __construct(public CommandLine $cli, public Filesystem $files) {}
1412

1513
/**
1614
* Symlink the Valet Bash script into the user's local bin.

cli/app.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
Container::setInstance(new Container);
3535

36-
$version = '4.6.1';
36+
$version = '4.7.1';
3737

3838
$app = new Application('Laravel Valet', $version);
3939

@@ -499,6 +499,13 @@ function (ConsoleCommandEvent $event) {
499499
return info('PHP has been restarted.');
500500
}
501501

502+
// Handle restarting specific PHP version (e.g. `valet restart php@8.2`)
503+
if (str_contains($service, 'php')) {
504+
PhpFpm::restart($normalized = PhpFpm::normalizePhpVersion($service));
505+
506+
return info($normalized.' has been restarted.');
507+
}
508+
502509
return warning(sprintf('Invalid valet service name [%s]', $service));
503510
})->descriptions('Restart the Valet services');
504511

0 commit comments

Comments
 (0)