Skip to content

Commit a3ea286

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feat/proxy-multiple-domains
2 parents bb36a3b + 0fef72b commit a3ea286

36 files changed

+379
-237
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: true
1818
matrix:
19-
php: ['8.0', 8.1, 8.2]
19+
php: ['8.0', 8.1, 8.2, 8.3]
2020

2121
name: PHP ${{ matrix.php }}
2222

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Release Notes
22

3-
## [Unreleased](https://github.com/laravel/valet/compare/v4.1.4...master)
3+
## [Unreleased](https://github.com/laravel/valet/compare/v4.4.0...master)
4+
5+
## [v4.4.0](https://github.com/laravel/valet/compare/v4.3.0...v4.4.0) - 2023-09-26
6+
7+
- Allow LaravelValetDriver to serve other /public/*.php files by [@drbyte](https://github.com/drbyte) in https://github.com/laravel/valet/pull/1439
8+
- Support static caching in Statamic by [@jasonvarga](https://github.com/jasonvarga) in https://github.com/laravel/valet/pull/1440
9+
- Fix link command's `--isolate` argument with custom name by [@mcaskill](https://github.com/mcaskill) in https://github.com/laravel/valet/pull/1428
10+
11+
## [v4.3.0](https://github.com/laravel/valet/compare/v4.1.4...v4.3.0) - 2023-09-05
12+
13+
- Add "valet stop dnsmasq" option by [@drbyte](https://github.com/drbyte) in https://github.com/laravel/valet/pull/1422
14+
- Drop Mailhog and Redis from default logs list, since Valet doesn't install them by [@mattstauffer](https://github.com/mattstauffer) in https://github.com/laravel/valet/pull/1438
415

516
## [v4.1.4](https://github.com/laravel/valet/compare/v4.1.3...v4.1.4) - 2023-08-14
617

cli/Valet/Brew.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Brew
1111
// This is the array of PHP versions that Valet will attempt to install/configure when requested
1212
const SUPPORTED_PHP_VERSIONS = [
1313
'php',
14+
1415
1516
1617

cli/Valet/DnsMasq.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public function uninstall(): void
5252
}
5353
}
5454

55+
/**
56+
* Stop the dnsmasq service.
57+
*/
58+
public function stop(): void
59+
{
60+
$this->brew->stopService(['dnsmasq']);
61+
}
62+
5563
/**
5664
* Tell Homebrew to restart dnsmasq.
5765
*/
@@ -70,7 +78,7 @@ public function ensureUsingDnsmasqDForConfigs(): void
7078
// set primary config to look for configs in /usr/local/etc/dnsmasq.d/*.conf
7179
$contents = $this->files->get($this->dnsmasqMasterConfigFile);
7280
// ensure the line we need to use is present, and uncomment it if needed
73-
if (false === strpos($contents, 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf')) {
81+
if (strpos($contents, 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf') === false) {
7482
$contents .= PHP_EOL.'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf'.PHP_EOL;
7583
}
7684
$contents = str_replace('#conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf', 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf', $contents);

cli/Valet/Drivers/LaravelValetDriver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public function isStaticFile(string $sitePath, string $siteName, string $uri)/*:
5252
*/
5353
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
5454
{
55+
if (file_exists($staticFilePath = $sitePath.'/public'.$uri)
56+
&& $this->isActualFile($staticFilePath)) {
57+
return $staticFilePath;
58+
}
59+
5560
return $sitePath.'/public/index.php';
5661
}
5762
}

cli/Valet/Drivers/Specific/ContaoValetDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function frontControllerPath(string $sitePath, string $siteName, string $
3535
return $sitePath.'/web/install.php';
3636
}
3737

38-
if (0 === strncmp($uri, '/app_dev.php', 12)) {
38+
if (strncmp($uri, '/app_dev.php', 12) === 0) {
3939
$_SERVER['SCRIPT_NAME'] = '/app_dev.php';
4040
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/app_dev.php';
4141

cli/Valet/Drivers/Specific/Magento2ValetDriver.php

Lines changed: 13 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -7,137 +7,45 @@
77
class Magento2ValetDriver extends ValetDriver
88
{
99
/**
10-
* Holds the MAGE_MODE from app/etc/config.php or $ENV.
11-
*
12-
* Can't be correctly typed yet because PHP 7.3.
13-
*
14-
* @param string|null
15-
*/
16-
private $mageMode = null;
17-
18-
/**
19-
* Determine if the driver serves the request.
10+
* {@inheritdoc}
2011
*/
2112
public function serves(string $sitePath, string $siteName, string $uri): bool
2213
{
2314
return file_exists($sitePath.'/bin/magento') && file_exists($sitePath.'/pub/index.php');
2415
}
2516

2617
/**
27-
* Determine if the incoming request is for a static file.
18+
* {@inheritdoc}
2819
*/
2920
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
3021
{
31-
$this->checkMageMode($sitePath);
32-
33-
$uri = $this->handleForVersions($uri);
34-
$route = parse_url(substr($uri, 1))['path'];
35-
36-
$pub = '';
37-
if ('developer' === $this->mageMode) {
38-
$pub = 'pub/';
39-
}
40-
41-
if (! $this->isPubDirectory($sitePath, $route, $pub)) {
42-
return false;
43-
}
44-
45-
$magentoPackagePubDir = $sitePath;
46-
if ('developer' !== $this->mageMode) {
47-
$magentoPackagePubDir .= '/pub';
48-
}
49-
50-
$file = $magentoPackagePubDir.'/'.$route;
22+
$uri = preg_replace('/^\/static(\/version[\d]+)/', '/static', $uri);
5123

52-
if (file_exists($file)) {
53-
return $magentoPackagePubDir.$uri;
24+
if (file_exists($staticFilePath = $sitePath.'/pub'.$uri)) {
25+
return $staticFilePath;
5426
}
5527

56-
if (strpos($route, $pub.'static/') === 0) {
57-
$route = preg_replace('#'.$pub.'static/#', '', $route, 1);
58-
$_GET['resource'] = $route;
59-
include $magentoPackagePubDir.'/'.$pub.'static.php';
28+
if (strpos($uri, '/static/') === 0) {
29+
$_GET['resource'] = preg_replace('#static/#', '', $uri, 1);
30+
include $sitePath.'/pub/static.php';
6031
exit;
6132
}
6233

63-
if (strpos($route, $pub.'media/') === 0) {
64-
include $magentoPackagePubDir.'/'.$pub.'get.php';
34+
if (strpos($uri, '/media/') === 0) {
35+
include $sitePath.'/pub/get.php';
6536
exit;
6637
}
6738

6839
return false;
6940
}
7041

7142
/**
72-
* Rewrite URLs that look like "versions12345/" to remove
73-
* the versions12345/ part.
74-
*/
75-
private function handleForVersions($route): string
76-
{
77-
return preg_replace('/version\d*\//', '', $route);
78-
}
79-
80-
/**
81-
* Determine the current MAGE_MODE.
82-
*/
83-
private function checkMageMode($sitePath): void
84-
{
85-
if (null !== $this->mageMode) {
86-
// We have already figure out mode, no need to check it again
87-
return;
88-
}
89-
90-
if (! file_exists($sitePath.'/index.php')) {
91-
$this->mageMode = 'production'; // Can't use developer mode without index.php in project root
92-
93-
return;
94-
}
95-
96-
$mageConfig = [];
97-
98-
if (file_exists($sitePath.'/app/etc/env.php')) {
99-
$mageConfig = require $sitePath.'/app/etc/env.php';
100-
}
101-
102-
if (array_key_exists('MAGE_MODE', $mageConfig)) {
103-
$this->mageMode = $mageConfig['MAGE_MODE'];
104-
}
105-
}
106-
107-
/**
108-
* Checks to see if route is referencing any directory inside pub. This is a dynamic check so that if any new
109-
* directories are added to pub this driver will not need to be updated.
110-
*/
111-
private function isPubDirectory($sitePath, $route, $pub = ''): bool
112-
{
113-
$sitePath .= '/pub/';
114-
$dirs = glob($sitePath.'*', GLOB_ONLYDIR);
115-
116-
$dirs = str_replace($sitePath, '', $dirs);
117-
118-
foreach ($dirs as $dir) {
119-
if (strpos($route, $pub.$dir.'/') === 0) {
120-
return true;
121-
}
122-
}
123-
124-
return false;
125-
}
126-
127-
/**
128-
* Get the fully resolved path to the application's front controller.
43+
* {@inheritdoc}
12944
*/
13045
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
13146
{
132-
$this->checkMageMode($sitePath);
133-
134-
if ('developer' === $this->mageMode) {
135-
$_SERVER['DOCUMENT_ROOT'] = $sitePath;
136-
137-
return $sitePath.'/index.php';
138-
}
139-
140-
$_SERVER['DOCUMENT_ROOT'] = $sitePath.'/pub';
47+
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
48+
$_SERVER['DOCUMENT_ROOT'] = $sitePath;
14149

14250
return $sitePath.'/pub/index.php';
14351
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
namespace Valet\Drivers\Specific;
4+
5+
use Valet\Drivers\ValetDriver;
6+
7+
class StatamicV2ValetDriver 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 is_dir($sitePath.'/statamic');
15+
}
16+
17+
/**
18+
* Determine if the incoming request is for a static file.
19+
*/
20+
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
21+
{
22+
if (strpos($uri, '/site') === 0 && strpos($uri, '/site/themes') !== 0) {
23+
return false;
24+
} elseif (strpos($uri, '/local') === 0 || strpos($uri, '/statamic') === 0) {
25+
return false;
26+
} elseif ($this->isActualFile($staticFilePath = $sitePath.$uri)) {
27+
return $staticFilePath;
28+
} elseif ($this->isActualFile($staticFilePath = $sitePath.'/public'.$uri)) {
29+
return $staticFilePath;
30+
}
31+
32+
return false;
33+
}
34+
35+
/**
36+
* Get the fully resolved path to the application's front controller.
37+
*/
38+
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
39+
{
40+
if ($_SERVER['REQUEST_METHOD'] === 'GET' && $this->isActualFile($staticPath = $this->getStaticPath($sitePath))) {
41+
return $staticPath;
42+
}
43+
44+
if ($uri === '/installer.php') {
45+
return $sitePath.'/installer.php';
46+
}
47+
48+
$scriptName = '/index.php';
49+
50+
if ($this->isActualFile($sitePath.'/index.php')) {
51+
$indexPath = $sitePath.'/index.php';
52+
}
53+
54+
if ($isAboveWebroot = $this->isActualFile($sitePath.'/public/index.php')) {
55+
$indexPath = $sitePath.'/public/index.php';
56+
}
57+
58+
$sitePathPrefix = ($isAboveWebroot) ? $sitePath.'/public' : $sitePath;
59+
60+
if ($locale = $this->getUriLocale($uri)) {
61+
if ($this->isActualFile($localeIndexPath = $sitePathPrefix.'/'.$locale.'/index.php')) {
62+
// Force trailing slashes on locale roots.
63+
if ($uri === '/'.$locale) {
64+
header('Location: '.$uri.'/');
65+
exit;
66+
}
67+
68+
$indexPath = $localeIndexPath;
69+
$scriptName = '/'.$locale.'/index.php';
70+
}
71+
}
72+
73+
$_SERVER['SCRIPT_NAME'] = $scriptName;
74+
$_SERVER['SCRIPT_FILENAME'] = $sitePathPrefix.$scriptName;
75+
76+
return $indexPath;
77+
}
78+
79+
/**
80+
* Get the locale from this URI.
81+
*/
82+
public function getUriLocale(string $uri): ?string
83+
{
84+
$parts = explode('/', $uri);
85+
$locale = $parts[1];
86+
87+
if (count($parts) < 2 || ! in_array($locale, $this->getLocales())) {
88+
return null;
89+
}
90+
91+
return $locale;
92+
}
93+
94+
/**
95+
* Get the list of possible locales used in the first segment of a URI.
96+
*/
97+
public function getLocales(): array
98+
{
99+
return [
100+
'af', 'ax', 'al', 'dz', 'as', 'ad', 'ao', 'ai', 'aq', 'ag', 'ar', 'am', 'aw', 'au', 'at', 'az', 'bs', 'bh',
101+
'bd', 'bb', 'by', 'be', 'bz', 'bj', 'bm', 'bt', 'bo', 'bq', 'ba', 'bw', 'bv', 'br', 'io', 'bn', 'bg', 'bf',
102+
'bi', 'cv', 'kh', 'cm', 'ca', 'ky', 'cf', 'td', 'cl', 'cn', 'cx', 'cc', 'co', 'km', 'cg', 'cd', 'ck', 'cr',
103+
'ci', 'hr', 'cu', 'cw', 'cy', 'cz', 'dk', 'dj', 'dm', 'do', 'ec', 'eg', 'sv', 'gq', 'er', 'ee', 'et', 'fk',
104+
'fo', 'fj', 'fi', 'fr', 'gf', 'pf', 'tf', 'ga', 'gm', 'ge', 'de', 'gh', 'gi', 'gr', 'gl', 'gd', 'gp', 'gu',
105+
'gt', 'gg', 'gn', 'gw', 'gy', 'ht', 'hm', 'va', 'hn', 'hk', 'hu', 'is', 'in', 'id', 'ir', 'iq', 'ie', 'im',
106+
'il', 'it', 'jm', 'jp', 'je', 'jo', 'kz', 'ke', 'ki', 'kp', 'kr', 'kw', 'kg', 'la', 'lv', 'lb', 'ls', 'lr',
107+
'ly', 'li', 'lt', 'lu', 'mo', 'mk', 'mg', 'mw', 'my', 'mv', 'ml', 'mt', 'mh', 'mq', 'mr', 'mu', 'yt', 'mx',
108+
'fm', 'md', 'mc', 'mn', 'me', 'ms', 'ma', 'mz', 'mm', 'na', 'nr', 'np', 'nl', 'nc', 'nz', 'ni', 'ne', 'ng',
109+
'nu', 'nf', 'mp', 'no', 'om', 'pk', 'pw', 'ps', 'pa', 'pg', 'py', 'pe', 'ph', 'pn', 'pl', 'pt', 'pr', 'qa',
110+
're', 'ro', 'ru', 'rw', 'bl', 'sh', 'kn', 'lc', 'mf', 'pm', 'vc', 'ws', 'sm', 'st', 'sa', 'sn', 'rs', 'sc',
111+
'sl', 'sg', 'sx', 'sk', 'si', 'sb', 'so', 'za', 'gs', 'ss', 'es', 'lk', 'sd', 'sr', 'sj', 'sz', 'se', 'ch',
112+
'sy', 'tw', 'tj', 'tz', 'th', 'tl', 'tg', 'tk', 'to', 'tt', 'tn', 'tr', 'tm', 'tc', 'tv', 'ug', 'ua', 'ae',
113+
'gb', 'us', 'um', 'uy', 'uz', 'vu', 've', 'vn', 'vg', 'vi', 'wf', 'eh', 'ye', 'zm', 'zw', 'en', 'zh',
114+
];
115+
}
116+
117+
/**
118+
* Get the path to a statically cached page.
119+
*/
120+
protected function getStaticPath(string $sitePath): string
121+
{
122+
$parts = parse_url($_SERVER['REQUEST_URI']);
123+
$query = isset($parts['query']) ? $parts['query'] : '';
124+
125+
return $sitePath.'/static'.$parts['path'].'_'.$query.'.html';
126+
}
127+
}

0 commit comments

Comments
 (0)