From 269d157b0abe24ab2c2716a030d7ffd769392cbd Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Tue, 20 Jun 2023 16:30:04 -0400 Subject: [PATCH 01/28] Add "valet stop dnsmasq" option Fixes #1419 Adds: - `valet stop dnsmasq` - `valet stop all` (which includes php, nginx, dnsmasq) - When `valet stop` is called without a service name, a message indicates that dnsmasq can also be stopped via `valet stop dnsmasq` - Aside: phpfpm now also displays a message when stopping; previously it was silent. --- cli/Valet/DnsMasq.php | 8 ++++++++ cli/Valet/PhpFpm.php | 2 ++ cli/app.php | 14 ++++++++++++-- tests/CliTest.php | 17 ++++++++++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/cli/Valet/DnsMasq.php b/cli/Valet/DnsMasq.php index 2806824..29d9ba7 100644 --- a/cli/Valet/DnsMasq.php +++ b/cli/Valet/DnsMasq.php @@ -47,6 +47,14 @@ public function uninstall(): void $this->files->unlink($this->resolverPath.'/'.$tld); } + /** + * Stop the dnsmasq service. + */ + public function stop(): void + { + $this->brew->stopService(['dnsmasq']); + } + /** * Tell Homebrew to restart dnsmasq. */ diff --git a/cli/Valet/PhpFpm.php b/cli/Valet/PhpFpm.php index e56cea1..39d5558 100644 --- a/cli/Valet/PhpFpm.php +++ b/cli/Valet/PhpFpm.php @@ -112,6 +112,7 @@ public function restart(?string $phpVersion = null): void */ public function stop(): void { + info('Stopping phpfpm...'); call_user_func_array( [$this->brew, 'stopService'], Brew::SUPPORTED_PHP_VERSIONS @@ -138,6 +139,7 @@ public function fpmConfigPath(?string $phpVersion = null): string */ public function stopRunning(): void { + info('Stopping phpfpm...'); $this->brew->stopService( $this->brew->getAllRunningServices() ->filter(function ($service) { diff --git a/cli/app.php b/cli/app.php index 5e66c10..042750a 100644 --- a/cli/app.php +++ b/cli/app.php @@ -506,7 +506,13 @@ function (ConsoleCommandEvent $event) { PhpFpm::stopRunning(); Nginx::stop(); - return info('Valet services have been stopped.'); + return info('Valet core services have been stopped. To also stop dnsmasq, run: valet stop dnsmasq'); + case 'all': + PhpFpm::stopRunning(); + Nginx::stop(); + Dnsmasq::stop(); + + return info('All Valet services have been stopped.'); case 'nginx': Nginx::stop(); @@ -515,10 +521,14 @@ function (ConsoleCommandEvent $event) { PhpFpm::stopRunning(); return info('PHP has been stopped.'); + case 'dnsmasq': + Dnsmasq::stop(); + + return info('dnsmasq has been stopped.'); } return warning(sprintf('Invalid valet service name [%s]', $service)); - })->descriptions('Stop the Valet services'); + })->descriptions('Stop the core Valet services, or all services by specifying "all".'); /** * Uninstall Valet entirely. Requires --force to actually remove; otherwise manual instructions are displayed. diff --git a/tests/CliTest.php b/tests/CliTest.php index b2c6fdd..cdc7e9a 100644 --- a/tests/CliTest.php +++ b/tests/CliTest.php @@ -759,7 +759,7 @@ public function test_stop_command() $tester->run(['command' => 'stop']); $tester->assertCommandIsSuccessful(); - $this->assertStringContainsString('Valet services have been stopped.', $tester->getDisplay()); + $this->assertStringContainsString('Valet core services have been stopped.', $tester->getDisplay()); } public function test_stop_command_stops_nginx() @@ -792,6 +792,21 @@ public function test_stop_command_stops_php() $this->assertStringContainsString('PHP has been stopped', $tester->getDisplay()); } + public function test_stop_all_command_stops_dnsmasq() + { + [$app, $tester] = $this->appAndTester(); + + $phpfpm = Mockery::mock(DnsMasq::class); + $phpfpm->shouldReceive('stop'); + + swap(DnsMasq::class, $phpfpm); + + $tester->run(['command' => 'stop', 'service' => 'dnsmasq']); + $tester->assertCommandIsSuccessful(); + + $this->assertStringContainsString('dnsmasq has been stopped', $tester->getDisplay()); + } + public function test_stop_command_handles_bad_services() { [$app, $tester] = $this->appAndTester(); From 9a4a7a1693d3b4286146f65c6a607d0902191e63 Mon Sep 17 00:00:00 2001 From: mattstauffer Date: Sun, 27 Aug 2023 02:47:47 +0000 Subject: [PATCH 02/28] Fix code styling --- cli/app.php | 1 + tests/BrewTest.php | 1 + tests/CliTest.php | 3 ++- tests/ComposerTest.php | 1 + tests/ConfigurationTest.php | 3 ++- tests/DnsMasqTest.php | 1 + tests/NginxTest.php | 3 ++- tests/NgrokTest.php | 1 + tests/PhpFpmTest.php | 3 ++- tests/ServerTest.php | 1 + tests/SiteTest.php | 3 ++- tests/StatusTest.php | 3 ++- 12 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cli/app.php b/cli/app.php index a705290..2b95918 100644 --- a/cli/app.php +++ b/cli/app.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\EventDispatcher\EventDispatcher; use Valet\Drivers\ValetDriver; + use function Valet\info; use function Valet\output; use function Valet\table; diff --git a/tests/BrewTest.php b/tests/BrewTest.php index f2cbee1..51b7b78 100644 --- a/tests/BrewTest.php +++ b/tests/BrewTest.php @@ -5,6 +5,7 @@ use Valet\Brew; use Valet\CommandLine; use Valet\Filesystem; + use function Valet\resolve; use function Valet\swap; use function Valet\user; diff --git a/tests/CliTest.php b/tests/CliTest.php index cdc7e9a..b902c13 100644 --- a/tests/CliTest.php +++ b/tests/CliTest.php @@ -11,9 +11,10 @@ use Valet\Ngrok; use Valet\PhpFpm; use Valet\Site as RealSite; -use function Valet\swap; use Valet\Valet; +use function Valet\swap; + /** * @requires PHP >= 8.0 */ diff --git a/tests/ComposerTest.php b/tests/ComposerTest.php index ad36428..808ab40 100644 --- a/tests/ComposerTest.php +++ b/tests/ComposerTest.php @@ -3,6 +3,7 @@ use Illuminate\Container\Container; use Valet\CommandLine; use Valet\Composer; + use function Valet\resolve; use function Valet\swap; use function Valet\user; diff --git a/tests/ConfigurationTest.php b/tests/ConfigurationTest.php index 187e302..34acd4d 100644 --- a/tests/ConfigurationTest.php +++ b/tests/ConfigurationTest.php @@ -4,10 +4,11 @@ use Valet\Brew; use Valet\Configuration; use Valet\Filesystem; +use Valet\Valet; + use function Valet\resolve; use function Valet\swap; use function Valet\user; -use Valet\Valet; class ConfigurationTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase { diff --git a/tests/DnsMasqTest.php b/tests/DnsMasqTest.php index 5f9b581..a6c99cf 100644 --- a/tests/DnsMasqTest.php +++ b/tests/DnsMasqTest.php @@ -6,6 +6,7 @@ use Valet\Configuration; use Valet\DnsMasq; use Valet\Filesystem; + use function Valet\resolve; use function Valet\swap; use function Valet\user; diff --git a/tests/NginxTest.php b/tests/NginxTest.php index 6b0141b..facf948 100644 --- a/tests/NginxTest.php +++ b/tests/NginxTest.php @@ -4,8 +4,9 @@ use Valet\Configuration; use Valet\Filesystem; use Valet\Nginx; -use function Valet\resolve; use Valet\Site; + +use function Valet\resolve; use function Valet\swap; use function Valet\user; diff --git a/tests/NgrokTest.php b/tests/NgrokTest.php index 23e61b7..7f37da6 100644 --- a/tests/NgrokTest.php +++ b/tests/NgrokTest.php @@ -2,6 +2,7 @@ use Illuminate\Container\Container; use Valet\Ngrok; + use function Valet\resolve; use function Valet\user; diff --git a/tests/PhpFpmTest.php b/tests/PhpFpmTest.php index eaea2bf..9d4e503 100644 --- a/tests/PhpFpmTest.php +++ b/tests/PhpFpmTest.php @@ -7,8 +7,9 @@ use Valet\Filesystem; use Valet\Nginx; use Valet\PhpFpm; -use function Valet\resolve; use Valet\Site; + +use function Valet\resolve; use function Valet\swap; use function Valet\user; diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 8c4b16d..55243a9 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -2,6 +2,7 @@ use Illuminate\Container\Container; use Valet\Server; + use function Valet\user; class ServerTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase diff --git a/tests/SiteTest.php b/tests/SiteTest.php index 52b9e7d..14b310e 100644 --- a/tests/SiteTest.php +++ b/tests/SiteTest.php @@ -5,8 +5,9 @@ use Valet\CommandLine; use Valet\Configuration; use Valet\Filesystem; -use function Valet\resolve; use Valet\Site; + +use function Valet\resolve; use function Valet\swap; use function Valet\user; diff --git a/tests/StatusTest.php b/tests/StatusTest.php index d0bfb1d..e1d196e 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -2,8 +2,9 @@ use Illuminate\Container\Container; use Valet\CommandLine; -use function Valet\resolve; use Valet\Status; + +use function Valet\resolve; use function Valet\swap; use function Valet\user; From e03de8856f9f57e5acc5220cc034dd8a8f404fde Mon Sep 17 00:00:00 2001 From: Matt Stauffer Date: Sun, 27 Aug 2023 11:13:47 -0400 Subject: [PATCH 03/28] Drop Mailhog and Redis from default logs list, since Valet doesn't install them --- cli/app.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/app.php b/cli/app.php index 2b95918..b78b5a3 100644 --- a/cli/app.php +++ b/cli/app.php @@ -728,8 +728,6 @@ function (ConsoleCommandEvent $event) { $defaultLogs = [ 'php-fpm' => BREW_PREFIX.'/var/log/php-fpm.log', 'nginx' => VALET_HOME_PATH.'/Log/nginx-error.log', - 'mailhog' => BREW_PREFIX.'/var/log/mailhog.log', - 'redis' => BREW_PREFIX.'/var/log/redis.log', ]; $configLogs = data_get(Configuration::read(), 'logs'); From cda54e17ea9b7bdc38bfc0310506884ba3c1241f Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Sun, 27 Aug 2023 13:55:07 -0400 Subject: [PATCH 04/28] Allow LaravelValetDriver to serve other /public/*.php files When PHP files other than index.php exist in /public/ this allows them to be served by the Laravel driver. I discussed this previously at: https://github.com/laravel/valet/discussions/1430#discussioncomment-6536474 ... but I think it's safe to include in the core LaravelValetDriver by default. --- cli/Valet/Drivers/LaravelValetDriver.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cli/Valet/Drivers/LaravelValetDriver.php b/cli/Valet/Drivers/LaravelValetDriver.php index f5b8ded..22b576c 100644 --- a/cli/Valet/Drivers/LaravelValetDriver.php +++ b/cli/Valet/Drivers/LaravelValetDriver.php @@ -52,6 +52,11 @@ public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: */ public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string { + if (file_exists($staticFilePath = $sitePath.'/public'.$uri) + && $this->isActualFile($staticFilePath)) { + return $staticFilePath; + } + return $sitePath.'/public/index.php'; } } From 12c10e0b03f9b4f8073e4d131bfbd89ce5d0a644 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 28 Aug 2023 14:38:42 -0400 Subject: [PATCH 05/28] add statamic driver --- .../Specific/StatamicV3ValetDriver.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 cli/Valet/Drivers/Specific/StatamicV3ValetDriver.php diff --git a/cli/Valet/Drivers/Specific/StatamicV3ValetDriver.php b/cli/Valet/Drivers/Specific/StatamicV3ValetDriver.php new file mode 100644 index 0000000..6543f4b --- /dev/null +++ b/cli/Valet/Drivers/Specific/StatamicV3ValetDriver.php @@ -0,0 +1,40 @@ +isActualFile($staticPath = $this->getStaticPath($sitePath))) { + return $staticPath; + } + + return parent::frontControllerPath($sitePath, $siteName, $uri); + } + + /** + * Get the path to the static file. + */ + protected function getStaticPath(string $sitePath): string + { + $parts = parse_url($_SERVER['REQUEST_URI']); + $query = $parts['query'] ?? ''; + + return $sitePath.'/public/static'.$parts['path'].'_'.$query.'.html'; + } +} From fadd0d46b89b7d7cdda2f90352765c3809992d86 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 28 Aug 2023 14:38:58 -0400 Subject: [PATCH 06/28] attempt statamic driver first --- cli/Valet/Drivers/ValetDriver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index 7ce2498..2dc5c45 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -45,8 +45,9 @@ public static function assign(string $sitePath, string $siteName, string $uri): $drivers = array_merge($drivers, static::customDrivers()); // Queue Valet-shipped drivers + $drivers[] = 'Specific\StatamicV3ValetDriver'; $drivers[] = 'LaravelValetDriver'; - $drivers = array_merge($drivers, $specificDrivers); + $drivers = array_unique(array_merge($drivers, $specificDrivers)); $drivers[] = 'BasicWithPublicValetDriver'; $drivers[] = 'BasicValetDriver'; From ee5391def6fb75bb89e59df6b340732b9deb9ae7 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 28 Aug 2023 15:14:38 -0400 Subject: [PATCH 07/28] rename --- .../Specific/StatamicV2ValetDriver.php | 127 ++++++++++++++++++ .../Specific/StatamicV3ValetDriver.php | 40 ------ .../Drivers/Specific/StatamicValetDriver.php | 107 ++------------- cli/Valet/Drivers/ValetDriver.php | 2 +- 4 files changed, 138 insertions(+), 138 deletions(-) create mode 100644 cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php delete mode 100644 cli/Valet/Drivers/Specific/StatamicV3ValetDriver.php diff --git a/cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php b/cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php new file mode 100644 index 0000000..4eee35c --- /dev/null +++ b/cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php @@ -0,0 +1,127 @@ +isActualFile($staticFilePath = $sitePath.$uri)) { + return $staticFilePath; + } elseif ($this->isActualFile($staticFilePath = $sitePath.'/public'.$uri)) { + return $staticFilePath; + } + + return false; + } + + /** + * Get the fully resolved path to the application's front controller. + */ + public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string + { + if ($_SERVER['REQUEST_METHOD'] === 'GET' && $this->isActualFile($staticPath = $this->getStaticPath($sitePath))) { + return $staticPath; + } + + if ($uri === '/installer.php') { + return $sitePath.'/installer.php'; + } + + $scriptName = '/index.php'; + + if ($this->isActualFile($sitePath.'/index.php')) { + $indexPath = $sitePath.'/index.php'; + } + + if ($isAboveWebroot = $this->isActualFile($sitePath.'/public/index.php')) { + $indexPath = $sitePath.'/public/index.php'; + } + + $sitePathPrefix = ($isAboveWebroot) ? $sitePath.'/public' : $sitePath; + + if ($locale = $this->getUriLocale($uri)) { + if ($this->isActualFile($localeIndexPath = $sitePathPrefix.'/'.$locale.'/index.php')) { + // Force trailing slashes on locale roots. + if ($uri === '/'.$locale) { + header('Location: '.$uri.'/'); + exit; + } + + $indexPath = $localeIndexPath; + $scriptName = '/'.$locale.'/index.php'; + } + } + + $_SERVER['SCRIPT_NAME'] = $scriptName; + $_SERVER['SCRIPT_FILENAME'] = $sitePathPrefix.$scriptName; + + return $indexPath; + } + + /** + * Get the locale from this URI. + */ + public function getUriLocale(string $uri): ?string + { + $parts = explode('/', $uri); + $locale = $parts[1]; + + if (count($parts) < 2 || ! in_array($locale, $this->getLocales())) { + return null; + } + + return $locale; + } + + /** + * Get the list of possible locales used in the first segment of a URI. + */ + public function getLocales(): array + { + return [ + 'af', 'ax', 'al', 'dz', 'as', 'ad', 'ao', 'ai', 'aq', 'ag', 'ar', 'am', 'aw', 'au', 'at', 'az', 'bs', 'bh', + 'bd', 'bb', 'by', 'be', 'bz', 'bj', 'bm', 'bt', 'bo', 'bq', 'ba', 'bw', 'bv', 'br', 'io', 'bn', 'bg', 'bf', + 'bi', 'cv', 'kh', 'cm', 'ca', 'ky', 'cf', 'td', 'cl', 'cn', 'cx', 'cc', 'co', 'km', 'cg', 'cd', 'ck', 'cr', + 'ci', 'hr', 'cu', 'cw', 'cy', 'cz', 'dk', 'dj', 'dm', 'do', 'ec', 'eg', 'sv', 'gq', 'er', 'ee', 'et', 'fk', + 'fo', 'fj', 'fi', 'fr', 'gf', 'pf', 'tf', 'ga', 'gm', 'ge', 'de', 'gh', 'gi', 'gr', 'gl', 'gd', 'gp', 'gu', + 'gt', 'gg', 'gn', 'gw', 'gy', 'ht', 'hm', 'va', 'hn', 'hk', 'hu', 'is', 'in', 'id', 'ir', 'iq', 'ie', 'im', + 'il', 'it', 'jm', 'jp', 'je', 'jo', 'kz', 'ke', 'ki', 'kp', 'kr', 'kw', 'kg', 'la', 'lv', 'lb', 'ls', 'lr', + 'ly', 'li', 'lt', 'lu', 'mo', 'mk', 'mg', 'mw', 'my', 'mv', 'ml', 'mt', 'mh', 'mq', 'mr', 'mu', 'yt', 'mx', + 'fm', 'md', 'mc', 'mn', 'me', 'ms', 'ma', 'mz', 'mm', 'na', 'nr', 'np', 'nl', 'nc', 'nz', 'ni', 'ne', 'ng', + 'nu', 'nf', 'mp', 'no', 'om', 'pk', 'pw', 'ps', 'pa', 'pg', 'py', 'pe', 'ph', 'pn', 'pl', 'pt', 'pr', 'qa', + 're', 'ro', 'ru', 'rw', 'bl', 'sh', 'kn', 'lc', 'mf', 'pm', 'vc', 'ws', 'sm', 'st', 'sa', 'sn', 'rs', 'sc', + 'sl', 'sg', 'sx', 'sk', 'si', 'sb', 'so', 'za', 'gs', 'ss', 'es', 'lk', 'sd', 'sr', 'sj', 'sz', 'se', 'ch', + 'sy', 'tw', 'tj', 'tz', 'th', 'tl', 'tg', 'tk', 'to', 'tt', 'tn', 'tr', 'tm', 'tc', 'tv', 'ug', 'ua', 'ae', + 'gb', 'us', 'um', 'uy', 'uz', 'vu', 've', 'vn', 'vg', 'vi', 'wf', 'eh', 'ye', 'zm', 'zw', 'en', 'zh', + ]; + } + + /** + * Get the path to a statically cached page. + */ + protected function getStaticPath(string $sitePath): string + { + $parts = parse_url($_SERVER['REQUEST_URI']); + $query = isset($parts['query']) ? $parts['query'] : ''; + + return $sitePath.'/static'.$parts['path'].'_'.$query.'.html'; + } +} diff --git a/cli/Valet/Drivers/Specific/StatamicV3ValetDriver.php b/cli/Valet/Drivers/Specific/StatamicV3ValetDriver.php deleted file mode 100644 index 6543f4b..0000000 --- a/cli/Valet/Drivers/Specific/StatamicV3ValetDriver.php +++ /dev/null @@ -1,40 +0,0 @@ -isActualFile($staticPath = $this->getStaticPath($sitePath))) { - return $staticPath; - } - - return parent::frontControllerPath($sitePath, $siteName, $uri); - } - - /** - * Get the path to the static file. - */ - protected function getStaticPath(string $sitePath): string - { - $parts = parse_url($_SERVER['REQUEST_URI']); - $query = $parts['query'] ?? ''; - - return $sitePath.'/public/static'.$parts['path'].'_'.$query.'.html'; - } -} diff --git a/cli/Valet/Drivers/Specific/StatamicValetDriver.php b/cli/Valet/Drivers/Specific/StatamicValetDriver.php index 7392a6a..208a24b 100644 --- a/cli/Valet/Drivers/Specific/StatamicValetDriver.php +++ b/cli/Valet/Drivers/Specific/StatamicValetDriver.php @@ -2,126 +2,39 @@ namespace Valet\Drivers\Specific; -use Valet\Drivers\ValetDriver; +use Valet\Drivers\LaravelValetDriver; -class StatamicValetDriver extends ValetDriver +class StatamicValetDriver extends LaravelValetDriver { /** * Determine if the driver serves the request. */ public function serves(string $sitePath, string $siteName, string $uri): bool { - return is_dir($sitePath.'/statamic'); - } - - /** - * Determine if the incoming request is for a static file. - */ - public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */ - { - if (strpos($uri, '/site') === 0 && strpos($uri, '/site/themes') !== 0) { - return false; - } elseif (strpos($uri, '/local') === 0 || strpos($uri, '/statamic') === 0) { - return false; - } elseif ($this->isActualFile($staticFilePath = $sitePath.$uri)) { - return $staticFilePath; - } elseif ($this->isActualFile($staticFilePath = $sitePath.'/public'.$uri)) { - return $staticFilePath; - } - - return false; + return file_exists($sitePath.'/please') + && parent::serves($sitePath, $siteName, $uri); } /** * Get the fully resolved path to the application's front controller. */ - public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string + public function frontControllerPath(string $sitePath, string $siteName, string $uri): string { - if ($_SERVER['REQUEST_METHOD'] === 'GET' && $this->isActualFile($staticPath = $this->getStaticPath($sitePath))) { + if ($this->isActualFile($staticPath = $this->getStaticPath($sitePath))) { return $staticPath; } - if ($uri === '/installer.php') { - return $sitePath.'/installer.php'; - } - - $scriptName = '/index.php'; - - if ($this->isActualFile($sitePath.'/index.php')) { - $indexPath = $sitePath.'/index.php'; - } - - if ($isAboveWebroot = $this->isActualFile($sitePath.'/public/index.php')) { - $indexPath = $sitePath.'/public/index.php'; - } - - $sitePathPrefix = ($isAboveWebroot) ? $sitePath.'/public' : $sitePath; - - if ($locale = $this->getUriLocale($uri)) { - if ($this->isActualFile($localeIndexPath = $sitePathPrefix.'/'.$locale.'/index.php')) { - // Force trailing slashes on locale roots. - if ($uri === '/'.$locale) { - header('Location: '.$uri.'/'); - exit; - } - - $indexPath = $localeIndexPath; - $scriptName = '/'.$locale.'/index.php'; - } - } - - $_SERVER['SCRIPT_NAME'] = $scriptName; - $_SERVER['SCRIPT_FILENAME'] = $sitePathPrefix.$scriptName; - - return $indexPath; + return parent::frontControllerPath($sitePath, $siteName, $uri); } /** - * Get the locale from this URI. - */ - public function getUriLocale(string $uri): ?string - { - $parts = explode('/', $uri); - $locale = $parts[1]; - - if (count($parts) < 2 || ! in_array($locale, $this->getLocales())) { - return null; - } - - return $locale; - } - - /** - * Get the list of possible locales used in the first segment of a URI. - */ - public function getLocales(): array - { - return [ - 'af', 'ax', 'al', 'dz', 'as', 'ad', 'ao', 'ai', 'aq', 'ag', 'ar', 'am', 'aw', 'au', 'at', 'az', 'bs', 'bh', - 'bd', 'bb', 'by', 'be', 'bz', 'bj', 'bm', 'bt', 'bo', 'bq', 'ba', 'bw', 'bv', 'br', 'io', 'bn', 'bg', 'bf', - 'bi', 'cv', 'kh', 'cm', 'ca', 'ky', 'cf', 'td', 'cl', 'cn', 'cx', 'cc', 'co', 'km', 'cg', 'cd', 'ck', 'cr', - 'ci', 'hr', 'cu', 'cw', 'cy', 'cz', 'dk', 'dj', 'dm', 'do', 'ec', 'eg', 'sv', 'gq', 'er', 'ee', 'et', 'fk', - 'fo', 'fj', 'fi', 'fr', 'gf', 'pf', 'tf', 'ga', 'gm', 'ge', 'de', 'gh', 'gi', 'gr', 'gl', 'gd', 'gp', 'gu', - 'gt', 'gg', 'gn', 'gw', 'gy', 'ht', 'hm', 'va', 'hn', 'hk', 'hu', 'is', 'in', 'id', 'ir', 'iq', 'ie', 'im', - 'il', 'it', 'jm', 'jp', 'je', 'jo', 'kz', 'ke', 'ki', 'kp', 'kr', 'kw', 'kg', 'la', 'lv', 'lb', 'ls', 'lr', - 'ly', 'li', 'lt', 'lu', 'mo', 'mk', 'mg', 'mw', 'my', 'mv', 'ml', 'mt', 'mh', 'mq', 'mr', 'mu', 'yt', 'mx', - 'fm', 'md', 'mc', 'mn', 'me', 'ms', 'ma', 'mz', 'mm', 'na', 'nr', 'np', 'nl', 'nc', 'nz', 'ni', 'ne', 'ng', - 'nu', 'nf', 'mp', 'no', 'om', 'pk', 'pw', 'ps', 'pa', 'pg', 'py', 'pe', 'ph', 'pn', 'pl', 'pt', 'pr', 'qa', - 're', 'ro', 'ru', 'rw', 'bl', 'sh', 'kn', 'lc', 'mf', 'pm', 'vc', 'ws', 'sm', 'st', 'sa', 'sn', 'rs', 'sc', - 'sl', 'sg', 'sx', 'sk', 'si', 'sb', 'so', 'za', 'gs', 'ss', 'es', 'lk', 'sd', 'sr', 'sj', 'sz', 'se', 'ch', - 'sy', 'tw', 'tj', 'tz', 'th', 'tl', 'tg', 'tk', 'to', 'tt', 'tn', 'tr', 'tm', 'tc', 'tv', 'ug', 'ua', 'ae', - 'gb', 'us', 'um', 'uy', 'uz', 'vu', 've', 'vn', 'vg', 'vi', 'wf', 'eh', 'ye', 'zm', 'zw', 'en', 'zh', - ]; - } - - /** - * Get the path to a statically cached page. + * Get the path to the static file. */ protected function getStaticPath(string $sitePath): string { $parts = parse_url($_SERVER['REQUEST_URI']); - $query = isset($parts['query']) ? $parts['query'] : ''; + $query = $parts['query'] ?? ''; - return $sitePath.'/static'.$parts['path'].'_'.$query.'.html'; + return $sitePath.'/public/static'.$parts['path'].'_'.$query.'.html'; } } diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index 2dc5c45..9d6fff1 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -45,7 +45,7 @@ public static function assign(string $sitePath, string $siteName, string $uri): $drivers = array_merge($drivers, static::customDrivers()); // Queue Valet-shipped drivers - $drivers[] = 'Specific\StatamicV3ValetDriver'; + $drivers[] = 'Specific\StatamicValetDriver'; $drivers[] = 'LaravelValetDriver'; $drivers = array_unique(array_merge($drivers, $specificDrivers)); $drivers[] = 'BasicWithPublicValetDriver'; From a93f267c0398a288c7e0ba5c35290d011096cc91 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 28 Aug 2023 15:40:33 -0400 Subject: [PATCH 08/28] adjust tests --- tests/Drivers/StatamicV2ValetDriverTest.php | 31 +++++++++++++++++++ tests/Drivers/StatamicValetDriverTest.php | 16 ++++++---- .../statamic/{statamic/.gitkeep => artisan} | 0 tests/Drivers/projects/statamic/please | 0 .../projects/statamic/public/index.php | 0 .../statamic/public/static/test_.html | 0 .../public/static/test_foo=bar&baz=qux.html | 0 tests/Drivers/projects/statamicv2/index.php | 0 .../projects/statamicv2/statamic/.gitkeep | 0 9 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 tests/Drivers/StatamicV2ValetDriverTest.php rename tests/Drivers/projects/statamic/{statamic/.gitkeep => artisan} (100%) create mode 100644 tests/Drivers/projects/statamic/please create mode 100644 tests/Drivers/projects/statamic/public/index.php create mode 100644 tests/Drivers/projects/statamic/public/static/test_.html create mode 100644 tests/Drivers/projects/statamic/public/static/test_foo=bar&baz=qux.html create mode 100644 tests/Drivers/projects/statamicv2/index.php create mode 100644 tests/Drivers/projects/statamicv2/statamic/.gitkeep diff --git a/tests/Drivers/StatamicV2ValetDriverTest.php b/tests/Drivers/StatamicV2ValetDriverTest.php new file mode 100644 index 0000000..630e6d1 --- /dev/null +++ b/tests/Drivers/StatamicV2ValetDriverTest.php @@ -0,0 +1,31 @@ +assertTrue($driver->serves($this->projectDir('statamicv2'), 'my-site', '/')); + } + + public function test_it_doesnt_serve_non_statamic_projects() + { + $driver = new StatamicV2ValetDriver(); + + $this->assertFalse($driver->serves($this->projectDir('public-with-index-non-laravel'), 'my-site', '/')); + } + + public function test_it_gets_front_controller() + { + $driver = new StatamicV2ValetDriver(); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['REQUEST_URI'] = '/about/'; + + $projectPath = $this->projectDir('statamicv2'); + $this->assertEquals($projectPath.'/index.php', $driver->frontControllerPath($projectPath, 'my-site', '/')); + } +} diff --git a/tests/Drivers/StatamicValetDriverTest.php b/tests/Drivers/StatamicValetDriverTest.php index ecd0eed..5b41238 100644 --- a/tests/Drivers/StatamicValetDriverTest.php +++ b/tests/Drivers/StatamicValetDriverTest.php @@ -11,21 +11,25 @@ public function test_it_serves_statamic_projects() $this->assertTrue($driver->serves($this->projectDir('statamic'), 'my-site', '/')); } - public function test_it_doesnt_serve_non_statamic_projects() + public function test_it_doesnt_serve_non_statamic_projects_with_public_directory() { $driver = new StatamicValetDriver(); $this->assertFalse($driver->serves($this->projectDir('public-with-index-non-laravel'), 'my-site', '/')); } + public function test_it_doesnt_serve_laravel_projects() + { + $driver = new StatamicValetDriver(); + + $this->assertFalse($driver->serves($this->projectDir('laravel'), 'my-site', '/')); + } + public function test_it_gets_front_controller() { $driver = new StatamicValetDriver(); - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['REQUEST_URI'] = '/about/'; - - $projectPath = $this->projectDir('statamicv1'); - $this->assertEquals($projectPath.'/index.php', $driver->frontControllerPath($projectPath, 'my-site', '/')); + $projectPath = $this->projectDir('statamic'); + $this->assertEquals($projectPath.'/public/index.php', $driver->frontControllerPath($projectPath, 'my-site', '/')); } } diff --git a/tests/Drivers/projects/statamic/statamic/.gitkeep b/tests/Drivers/projects/statamic/artisan similarity index 100% rename from tests/Drivers/projects/statamic/statamic/.gitkeep rename to tests/Drivers/projects/statamic/artisan diff --git a/tests/Drivers/projects/statamic/please b/tests/Drivers/projects/statamic/please new file mode 100644 index 0000000..e69de29 diff --git a/tests/Drivers/projects/statamic/public/index.php b/tests/Drivers/projects/statamic/public/index.php new file mode 100644 index 0000000..e69de29 diff --git a/tests/Drivers/projects/statamic/public/static/test_.html b/tests/Drivers/projects/statamic/public/static/test_.html new file mode 100644 index 0000000..e69de29 diff --git a/tests/Drivers/projects/statamic/public/static/test_foo=bar&baz=qux.html b/tests/Drivers/projects/statamic/public/static/test_foo=bar&baz=qux.html new file mode 100644 index 0000000..e69de29 diff --git a/tests/Drivers/projects/statamicv2/index.php b/tests/Drivers/projects/statamicv2/index.php new file mode 100644 index 0000000..e69de29 diff --git a/tests/Drivers/projects/statamicv2/statamic/.gitkeep b/tests/Drivers/projects/statamicv2/statamic/.gitkeep new file mode 100644 index 0000000..e69de29 From e52b9014158ebe55946383422788374a38f7a588 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 28 Aug 2023 15:41:41 -0400 Subject: [PATCH 09/28] add test for static caching --- tests/Drivers/StatamicValetDriverTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Drivers/StatamicValetDriverTest.php b/tests/Drivers/StatamicValetDriverTest.php index 5b41238..5d2f0ee 100644 --- a/tests/Drivers/StatamicValetDriverTest.php +++ b/tests/Drivers/StatamicValetDriverTest.php @@ -32,4 +32,17 @@ public function test_it_gets_front_controller() $projectPath = $this->projectDir('statamic'); $this->assertEquals($projectPath.'/public/index.php', $driver->frontControllerPath($projectPath, 'my-site', '/')); } + + public function test_it_serves_statically_cached_pages() + { + $driver = new StatamicValetDriver(); + + $projectPath = $this->projectDir('statamic'); + + $_SERVER['REQUEST_URI'] = '/test'; + $this->assertEquals($projectPath.'/public/static/test_.html', $driver->frontControllerPath($projectPath, 'my-site', '/test')); + + $_SERVER['REQUEST_URI'] = '/test?foo=bar&baz=qux'; + $this->assertEquals($projectPath.'/public/static/test_foo=bar&baz=qux.html', $driver->frontControllerPath($projectPath, 'my-site', '/test')); + } } From b55140a079315a16fc0e3071036b73639b3ba3a4 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 28 Aug 2023 15:42:12 -0400 Subject: [PATCH 10/28] adjust so that server variable doesnt need to be defined in all tests --- cli/Valet/Drivers/Specific/StatamicValetDriver.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cli/Valet/Drivers/Specific/StatamicValetDriver.php b/cli/Valet/Drivers/Specific/StatamicValetDriver.php index 208a24b..cb233d5 100644 --- a/cli/Valet/Drivers/Specific/StatamicValetDriver.php +++ b/cli/Valet/Drivers/Specific/StatamicValetDriver.php @@ -20,7 +20,9 @@ public function serves(string $sitePath, string $siteName, string $uri): bool */ public function frontControllerPath(string $sitePath, string $siteName, string $uri): string { - if ($this->isActualFile($staticPath = $this->getStaticPath($sitePath))) { + $staticPath = $this->getStaticPath($sitePath); + + if ($staticPath && $this->isActualFile($staticPath)) { return $staticPath; } @@ -30,9 +32,13 @@ public function frontControllerPath(string $sitePath, string $siteName, string $ /** * Get the path to the static file. */ - protected function getStaticPath(string $sitePath): string + private function getStaticPath(string $sitePath) { - $parts = parse_url($_SERVER['REQUEST_URI']); + if (! $uri = $_SERVER['REQUEST_URI'] ?? null) { + return; + } + + $parts = parse_url($uri); $query = $parts['query'] ?? ''; return $sitePath.'/public/static'.$parts['path'].'_'.$query.'.html'; From df9e1effe4850d01e375dda3a94c46acbfd8b239 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 28 Aug 2023 16:09:24 -0400 Subject: [PATCH 11/28] priority test --- tests/Drivers/ValetDriverTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Drivers/ValetDriverTest.php b/tests/Drivers/ValetDriverTest.php index 4f71bfc..74360a9 100644 --- a/tests/Drivers/ValetDriverTest.php +++ b/tests/Drivers/ValetDriverTest.php @@ -30,6 +30,15 @@ public function test_it_prioritizes_non_basic_matches() $this->assertNotEquals('Valet\Drivers\BasicValetDriver', get_class($assignedDriver)); } + public function test_it_prioritizes_statamic() + { + $assignedDriver = ValetDriver::assign($this->projectDir('statamic'), 'my-site', '/'); + $this->assertEquals('Valet\Drivers\Specific\StatamicValetDriver', get_class($assignedDriver)); + + $assignedDriver = ValetDriver::assign($this->projectDir('laravel'), 'my-site', '/'); + $this->assertEquals('Valet\Drivers\LaravelValetDriver', get_class($assignedDriver)); + } + public function test_it_checks_composer_dependencies() { $driver = new BasicValetDriver; From 11c6ae1206b314cd2a542a599677ac5017c1fca6 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 29 Aug 2023 17:32:16 +0200 Subject: [PATCH 12/28] Update app.php --- cli/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/app.php b/cli/app.php index 2b95918..0facd89 100644 --- a/cli/app.php +++ b/cli/app.php @@ -33,7 +33,7 @@ */ Container::setInstance(new Container); -$version = '4.1.4'; +$version = '4.2.0'; $app = new Application('Laravel Valet', $version); From 92c135e2dd8f7e55af8a879730cd1d1487275467 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 5 Sep 2023 17:49:55 +0200 Subject: [PATCH 13/28] Update app.php --- cli/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/app.php b/cli/app.php index 318ecae..c5edfe5 100644 --- a/cli/app.php +++ b/cli/app.php @@ -33,7 +33,7 @@ */ Container::setInstance(new Container); -$version = '4.2.0'; +$version = '4.3.0'; $app = new Application('Laravel Valet', $version); From f37a474700b3320db7a201d26952fce4e81c4d10 Mon Sep 17 00:00:00 2001 From: driesvints Date: Tue, 5 Sep 2023 15:50:18 +0000 Subject: [PATCH 14/28] Fix code styling --- cli/Valet/Drivers/Specific/Magento2ValetDriver.php | 8 ++++---- cli/Valet/PhpFpm.php | 2 +- cli/Valet/Server.php | 6 +++--- cli/Valet/Site.php | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cli/Valet/Drivers/Specific/Magento2ValetDriver.php b/cli/Valet/Drivers/Specific/Magento2ValetDriver.php index 1651926..ad25b67 100644 --- a/cli/Valet/Drivers/Specific/Magento2ValetDriver.php +++ b/cli/Valet/Drivers/Specific/Magento2ValetDriver.php @@ -34,7 +34,7 @@ public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: $route = parse_url(substr($uri, 1))['path']; $pub = ''; - if ('developer' === $this->mageMode) { + if ($this->mageMode === 'developer') { $pub = 'pub/'; } @@ -43,7 +43,7 @@ public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: } $magentoPackagePubDir = $sitePath; - if ('developer' !== $this->mageMode) { + if ($this->mageMode !== 'developer') { $magentoPackagePubDir .= '/pub'; } @@ -82,7 +82,7 @@ private function handleForVersions($route): string */ private function checkMageMode($sitePath): void { - if (null !== $this->mageMode) { + if ($this->mageMode !== null) { // We have already figure out mode, no need to check it again return; } @@ -131,7 +131,7 @@ public function frontControllerPath(string $sitePath, string $siteName, string $ { $this->checkMageMode($sitePath); - if ('developer' === $this->mageMode) { + if ($this->mageMode === 'developer') { $_SERVER['DOCUMENT_ROOT'] = $sitePath; return $sitePath.'/index.php'; diff --git a/cli/Valet/PhpFpm.php b/cli/Valet/PhpFpm.php index f88cd66..75c92d8 100644 --- a/cli/Valet/PhpFpm.php +++ b/cli/Valet/PhpFpm.php @@ -224,7 +224,7 @@ public function useVersion(string $version, bool $force = false): ?string $version = $this->validateRequestedVersion($version); try { - if ($this->brew->linkedPhp() === $version && ! $force) { + if ($version === $this->brew->linkedPhp() && ! $force) { output(sprintf('Valet is already using version: %s. To re-link and re-configure use the --force parameter.'.PHP_EOL, $version)); exit(); diff --git a/cli/Valet/Server.php b/cli/Valet/Server.php index 85c37ed..0436f5c 100644 --- a/cli/Valet/Server.php +++ b/cli/Valet/Server.php @@ -168,7 +168,7 @@ public function sitePath(string $siteName): ?string $dirs = []; - while (false !== ($file = readdir($handle))) { + while (($file = readdir($handle)) !== false) { if (is_dir($path.'/'.$file) && ! in_array($file, ['.', '..'])) { $dirs[] = $file; } @@ -178,12 +178,12 @@ public function sitePath(string $siteName): ?string // Note: strtolower used below because Nginx only tells us lowercase names foreach ($dirs as $dir) { - if (strtolower($dir) === $siteName) { + if ($siteName === strtolower($dir)) { // early return when exact match for linked subdomain return $path.'/'.$dir; } - if (strtolower($dir) === $domain) { + if ($domain === strtolower($dir)) { // no early return here because the foreach may still have some subdomains to process with higher priority $valetSitePath = $path.'/'.$dir; } diff --git a/cli/Valet/Site.php b/cli/Valet/Site.php index f178251..f7af251 100644 --- a/cli/Valet/Site.php +++ b/cli/Valet/Site.php @@ -52,7 +52,7 @@ private function getLinkNameByCurrentDir(): ?string public function host(string $path): ?string { foreach ($this->files->scandir($this->sitesPath()) as $link) { - if (realpath($this->sitesPath($link)) === $path) { + if ($path === realpath($this->sitesPath($link))) { return $link; } } From cdc8c19eff1bfef2494e7677cd067d7121a3e3a9 Mon Sep 17 00:00:00 2001 From: driesvints Date: Tue, 5 Sep 2023 15:50:38 +0000 Subject: [PATCH 15/28] Update CHANGELOG --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd8646e..28aa5ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Release Notes -## [Unreleased](https://github.com/laravel/valet/compare/v4.1.4...master) +## [Unreleased](https://github.com/laravel/valet/compare/v4.3.0...master) + +## [v4.3.0](https://github.com/laravel/valet/compare/v4.1.4...v4.3.0) - 2023-09-05 + +- Add "valet stop dnsmasq" option by [@drbyte](https://github.com/drbyte) in https://github.com/laravel/valet/pull/1422 +- 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 ## [v4.1.4](https://github.com/laravel/valet/compare/v4.1.3...v4.1.4) - 2023-08-14 From f378dc75de31c104824e31a2ee88d8541a1fb454 Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Sun, 16 Jul 2023 13:39:28 -0400 Subject: [PATCH 16/28] Improve link command's secure and isolate sub-commands Passing a custom hostname to the `link` command with the `--isolate` argument will result in either a mismatched site being isolated or the site not being found ("The [example] site could not be found in Valet's site list."). The reason for this is because the `isolate` command defaults to using the current directory's _name_ which won't match the custom hostname. This issue does not affect the `secure` command because it resolves the hostname from the current directory's _full path_. This commit passes the hostname (either custom or the current directory's name) to both sub-commands to ensure consistency of operations. Note: A bug introduced in mnapoli/silly v1.8.1 breaks all arguments in `runCommand()` method. See mnapoli/silly#69 for details and mnapoli/silly#70 for pull request. --- cli/app.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/app.php b/cli/app.php index c5edfe5..380fb14 100644 --- a/cli/app.php +++ b/cli/app.php @@ -197,12 +197,12 @@ function (ConsoleCommandEvent $event) { info('A ['.$name.'] symbolic link has been created in ['.$linkPath.'].'); if ($secure) { - $this->runCommand('secure'); + $this->runCommand('secure '.$name); } if ($isolate) { if (Site::phpRcVersion($name)) { - $this->runCommand('isolate'); + $this->runCommand('isolate --site='.$name); } else { warning('Valet could not determine which PHP version to use for this site.'); } From a268179535642fc7052532c049deb1b0a0878081 Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Sun, 16 Jul 2023 14:56:10 -0400 Subject: [PATCH 17/28] Ensure link command checks current directory for PHP version This matches the isolate command's usage of `Site::phpRcVersion()`. --- cli/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/app.php b/cli/app.php index 380fb14..3aa0c00 100644 --- a/cli/app.php +++ b/cli/app.php @@ -201,7 +201,7 @@ function (ConsoleCommandEvent $event) { } if ($isolate) { - if (Site::phpRcVersion($name)) { + if (Site::phpRcVersion($name, getcwd())) { $this->runCommand('isolate --site='.$name); } else { warning('Valet could not determine which PHP version to use for this site.'); From 24e7ed8ab94fbe386ea9c93598271ad065d32169 Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Sun, 16 Jul 2023 14:57:31 -0400 Subject: [PATCH 18/28] Add test of link command's isolate flag Based on `PhpFpmTest::test_isolate_will_isolate_a_site()` and `CliTest::test_link_command_with_secure_flag_secures()`. --- tests/CliTest.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/CliTest.php b/tests/CliTest.php index b902c13..52d4abd 100644 --- a/tests/CliTest.php +++ b/tests/CliTest.php @@ -10,6 +10,7 @@ use Valet\Nginx; use Valet\Ngrok; use Valet\PhpFpm; +use function Valet\resolve; use Valet\Site as RealSite; use Valet\Valet; @@ -254,6 +255,70 @@ public function test_link_command_with_secure_flag_secures() $this->assertStringContainsString('site has been secured', $tester->getDisplay()); } + public function test_link_command_with_isolate_flag_isolates() + { + [$app, $tester] = $this->appAndTester(); + + $cwd = getcwd(); + $name = 'tighten'; + $host = $name.'.test'; + + $customPhpVersion = '82'; + $phpRcVersion = '8.2'; + $fullPhpVersion = 'php@8.2'; + + $brewMock = Mockery::mock(Brew::class); + $nginxMock = Mockery::mock(Nginx::class); + $siteMock = Mockery::mock(RealSite::class); + + $phpFpmMock = Mockery::mock(PhpFpm::class, [ + $brewMock, + resolve(CommandLine::class), + resolve(Filesystem::class), + resolve(RealConfiguration::class), + $siteMock, + $nginxMock, + ])->makePartial(); + + swap(Brew::class, $brewMock); + swap(Nginx::class, $nginxMock); + swap(PhpFpm::class, $phpFpmMock); + swap(RealSite::class, $siteMock); + + $brewMock->shouldReceive('supportedPhpVersions')->andReturn(collect([ + 'php@8.2', + 'php@8.1', + ])); + + $brewMock->shouldReceive('ensureInstalled')->with($fullPhpVersion, [], $phpFpmMock->taps); + $brewMock->shouldReceive('installed')->with($fullPhpVersion); + $brewMock->shouldReceive('determineAliasedVersion')->with($fullPhpVersion)->andReturn($fullPhpVersion); + + $siteMock->shouldReceive('link')->with($cwd, $name)->once(); + $siteMock->shouldReceive('getSiteUrl')->with($name)->andReturn($host); + $siteMock->shouldReceive('phpRcVersion')->with($name, $cwd)->andReturn($phpRcVersion); + $siteMock->shouldReceive('customPhpVersion')->with($host)->andReturn($customPhpVersion); + $siteMock->shouldReceive('isolate')->with($host, $fullPhpVersion); + + $phpFpmMock->shouldReceive('stopIfUnused')->with($customPhpVersion)->once(); + $phpFpmMock->shouldReceive('createConfigurationFiles')->with($fullPhpVersion)->once(); + $phpFpmMock->shouldReceive('restart')->with($fullPhpVersion)->once(); + + $nginxMock->shouldReceive('restart')->once(); + + // These should only run when doing global PHP switches + $brewMock->shouldNotReceive('stopService'); + $brewMock->shouldNotReceive('link'); + $brewMock->shouldNotReceive('unlink'); + $phpFpmMock->shouldNotReceive('stopRunning'); + $phpFpmMock->shouldNotReceive('install'); + + $tester->run(['command' => 'link', 'name' => 'tighten', '--isolate' => true]); + $tester->assertCommandIsSuccessful(); + + $this->assertStringContainsString('is now using '.$fullPhpVersion, $tester->getDisplay()); + } + public function test_links_command() { [$app, $tester] = $this->appAndTester(); From 35539feef491cd2a31f7b8fb34bcbef61476a57e Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Mon, 17 Jul 2023 09:06:57 -0400 Subject: [PATCH 19/28] Bump requirement for mnapoli/silly to 1.5+ Silly v1.5.0 introduced improvements on command arguments and options that are used by Valet. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c72ddd3..3837550 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "php": "^7.1|^8.0", "illuminate/collections": "^8.0|^9.0|^10.0", "illuminate/container": "~5.1|^6.0|^7.0|^8.0|^9.0|^10.0", - "mnapoli/silly": "^1.0", + "mnapoli/silly": "^1.5", "symfony/console": "^3.0|^4.0|^5.0|^6.0", "symfony/process": "^3.0|^4.0|^5.0|^6.0", "guzzlehttp/guzzle": "^6.0|^7.4", From c02361beb13c0b8b69aa38c82929a2cd7cd632b8 Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Mon, 17 Jul 2023 09:07:57 -0400 Subject: [PATCH 20/28] =?UTF-8?q?Add=20conflict=20about=20mnapoli/silly=20?= =?UTF-8?q?1.8.1=E2=80=931.8.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 3837550..26dcddf 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,9 @@ "tests/Drivers/BaseDriverTestCase.php" ] }, + "conflict": { + "mnapoli/silly": ">=1.8.1 <1.8.3" + }, "require": { "php": "^7.1|^8.0", "illuminate/collections": "^8.0|^9.0|^10.0", From f9ee253db3eef9f4ce7b26d1e1963446b7442f5b Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Wed, 26 Jul 2023 09:58:09 +0200 Subject: [PATCH 21/28] Update tests/CliTest.php --- tests/CliTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/CliTest.php b/tests/CliTest.php index 52d4abd..c34630f 100644 --- a/tests/CliTest.php +++ b/tests/CliTest.php @@ -259,17 +259,17 @@ public function test_link_command_with_isolate_flag_isolates() { [$app, $tester] = $this->appAndTester(); - $cwd = getcwd(); + $cwd = getcwd(); $name = 'tighten'; $host = $name.'.test'; $customPhpVersion = '82'; - $phpRcVersion = '8.2'; - $fullPhpVersion = 'php@8.2'; + $phpRcVersion = '8.2'; + $fullPhpVersion = 'php@8.2'; - $brewMock = Mockery::mock(Brew::class); + $brewMock = Mockery::mock(Brew::class); $nginxMock = Mockery::mock(Nginx::class); - $siteMock = Mockery::mock(RealSite::class); + $siteMock = Mockery::mock(RealSite::class); $phpFpmMock = Mockery::mock(PhpFpm::class, [ $brewMock, From 55078675f49ebd127b39c4434dd17bb2a5b9724c Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 21 Sep 2023 21:30:35 +0200 Subject: [PATCH 22/28] PHP 8.3 (#1448) * PHP 8.3 * PHP 8.3 (#1449) --------- Co-authored-by: Chris Brown --- .github/workflows/tests.yml | 2 +- cli/Valet/Brew.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3f82dff..47540d8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: true matrix: - php: ['8.0', 8.1, 8.2] + php: ['8.0', 8.1, 8.2, 8.3] name: PHP ${{ matrix.php }} diff --git a/cli/Valet/Brew.php b/cli/Valet/Brew.php index d7e5109..121a139 100644 --- a/cli/Valet/Brew.php +++ b/cli/Valet/Brew.php @@ -11,6 +11,7 @@ class Brew // This is the array of PHP versions that Valet will attempt to install/configure when requested const SUPPORTED_PHP_VERSIONS = [ 'php', + 'php@8.3', 'php@8.2', 'php@8.1', 'php@8.0', From 03bb9cc131ffe47d73a06bc5f821b9485f0a6550 Mon Sep 17 00:00:00 2001 From: driesvints Date: Thu, 21 Sep 2023 19:31:00 +0000 Subject: [PATCH 23/28] Fix code styling --- cli/Valet/DnsMasq.php | 2 +- cli/Valet/Drivers/Specific/ContaoValetDriver.php | 2 +- cli/app.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/Valet/DnsMasq.php b/cli/Valet/DnsMasq.php index d5e21be..a0d74eb 100644 --- a/cli/Valet/DnsMasq.php +++ b/cli/Valet/DnsMasq.php @@ -78,7 +78,7 @@ public function ensureUsingDnsmasqDForConfigs(): void // set primary config to look for configs in /usr/local/etc/dnsmasq.d/*.conf $contents = $this->files->get($this->dnsmasqMasterConfigFile); // ensure the line we need to use is present, and uncomment it if needed - if (false === strpos($contents, 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf')) { + if (strpos($contents, 'conf-dir='.BREW_PREFIX.'/etc/dnsmasq.d/,*.conf') === false) { $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); diff --git a/cli/Valet/Drivers/Specific/ContaoValetDriver.php b/cli/Valet/Drivers/Specific/ContaoValetDriver.php index 293e62a..6649b1b 100644 --- a/cli/Valet/Drivers/Specific/ContaoValetDriver.php +++ b/cli/Valet/Drivers/Specific/ContaoValetDriver.php @@ -35,7 +35,7 @@ public function frontControllerPath(string $sitePath, string $siteName, string $ return $sitePath.'/web/install.php'; } - if (0 === strncmp($uri, '/app_dev.php', 12)) { + if (strncmp($uri, '/app_dev.php', 12) === 0) { $_SERVER['SCRIPT_NAME'] = '/app_dev.php'; $_SERVER['SCRIPT_FILENAME'] = $sitePath.'/app_dev.php'; diff --git a/cli/app.php b/cli/app.php index c5edfe5..bf1cbd8 100644 --- a/cli/app.php +++ b/cli/app.php @@ -117,7 +117,7 @@ function (ConsoleCommandEvent $event) { false ); - if (false === $helper->ask($input, $output, $question)) { + if ($helper->ask($input, $output, $question) === false) { return warning('No new Valet tld was set.'); } @@ -409,7 +409,7 @@ function (ConsoleCommandEvent $event) { $helper = $this->getHelperSet()->get('question'); $question = new ConfirmationQuestion('Would you like to install Expose now? [y/N] ', false); - if (false === $helper->ask($input, $output, $question)) { + if ($helper->ask($input, $output, $question) === false) { info('Proceeding without installing Expose.'); return; @@ -425,7 +425,7 @@ function (ConsoleCommandEvent $event) { $helper = $this->getHelperSet()->get('question'); $question = new ConfirmationQuestion('Would you like to install ngrok via Homebrew now? [y/N] ', false); - if (false === $helper->ask($input, $output, $question)) { + if ($helper->ask($input, $output, $question) === false) { info('Proceeding without installing ngrok.'); return; @@ -540,7 +540,7 @@ function (ConsoleCommandEvent $event) { $helper = $this->getHelperSet()->get('question'); $question = new ConfirmationQuestion('Are you sure you want to proceed? [y/N]', false); - if (false === $helper->ask($input, $output, $question)) { + if ($helper->ask($input, $output, $question) === false) { return warning('Uninstall aborted.'); } From a48540d3b4acd39df06b5bd83a9d6f09c1fcbcbe Mon Sep 17 00:00:00 2001 From: mattstauffer Date: Mon, 25 Sep 2023 16:55:28 +0000 Subject: [PATCH 24/28] Fix code styling --- tests/CliTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CliTest.php b/tests/CliTest.php index c34630f..374e8fb 100644 --- a/tests/CliTest.php +++ b/tests/CliTest.php @@ -10,10 +10,10 @@ use Valet\Nginx; use Valet\Ngrok; use Valet\PhpFpm; -use function Valet\resolve; use Valet\Site as RealSite; use Valet\Valet; +use function Valet\resolve; use function Valet\swap; /** From 15185fcabb8ae7c0d002e40e87d01b11afb386de Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 26 Sep 2023 18:38:05 +0200 Subject: [PATCH 25/28] version --- cli/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/app.php b/cli/app.php index 88d20bf..98252b1 100644 --- a/cli/app.php +++ b/cli/app.php @@ -33,7 +33,7 @@ */ Container::setInstance(new Container); -$version = '4.3.0'; +$version = '4.4.0'; $app = new Application('Laravel Valet', $version); From 68528ba6da6c7ba0df8acc2a46231174ec10a833 Mon Sep 17 00:00:00 2001 From: driesvints Date: Tue, 26 Sep 2023 16:38:46 +0000 Subject: [PATCH 26/28] Update CHANGELOG --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28aa5ad..d4f5e5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Release Notes -## [Unreleased](https://github.com/laravel/valet/compare/v4.3.0...master) +## [Unreleased](https://github.com/laravel/valet/compare/v4.4.0...master) + +## [v4.4.0](https://github.com/laravel/valet/compare/v4.3.0...v4.4.0) - 2023-09-26 + +- Allow LaravelValetDriver to serve other /public/*.php files by [@drbyte](https://github.com/drbyte) in https://github.com/laravel/valet/pull/1439 +- Support static caching in Statamic by [@jasonvarga](https://github.com/jasonvarga) in https://github.com/laravel/valet/pull/1440 +- Fix link command's `--isolate` argument with custom name by [@mcaskill](https://github.com/mcaskill) in https://github.com/laravel/valet/pull/1428 ## [v4.3.0](https://github.com/laravel/valet/compare/v4.1.4...v4.3.0) - 2023-09-05 From 108bbf75b08c2ec8adb699cdcb8cc2cdc64b2d0c Mon Sep 17 00:00:00 2001 From: Mischa Braam <19824986+mischabraam@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:24:05 +0200 Subject: [PATCH 27/28] Fix magento2 driver (#1420) + simplify, let mode determine by Magento env config --- .../Drivers/Specific/Magento2ValetDriver.php | 118 ++---------------- 1 file changed, 13 insertions(+), 105 deletions(-) diff --git a/cli/Valet/Drivers/Specific/Magento2ValetDriver.php b/cli/Valet/Drivers/Specific/Magento2ValetDriver.php index ad25b67..3bf799a 100644 --- a/cli/Valet/Drivers/Specific/Magento2ValetDriver.php +++ b/cli/Valet/Drivers/Specific/Magento2ValetDriver.php @@ -7,16 +7,7 @@ class Magento2ValetDriver extends ValetDriver { /** - * Holds the MAGE_MODE from app/etc/config.php or $ENV. - * - * Can't be correctly typed yet because PHP 7.3. - * - * @param string|null - */ - private $mageMode = null; - - /** - * Determine if the driver serves the request. + * @inheritdoc */ public function serves(string $sitePath, string $siteName, string $uri): bool { @@ -24,44 +15,24 @@ public function serves(string $sitePath, string $siteName, string $uri): bool } /** - * Determine if the incoming request is for a static file. + * @inheritdoc */ public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */ { - $this->checkMageMode($sitePath); + $uri = preg_replace('/^\/static(\/version[\d]+)/', '/static', $uri); - $uri = $this->handleForVersions($uri); - $route = parse_url(substr($uri, 1))['path']; - - $pub = ''; - if ($this->mageMode === 'developer') { - $pub = 'pub/'; + if (file_exists($staticFilePath = $sitePath . '/pub' . $uri)) { + return $staticFilePath; } - if (! $this->isPubDirectory($sitePath, $route, $pub)) { - return false; - } - - $magentoPackagePubDir = $sitePath; - if ($this->mageMode !== 'developer') { - $magentoPackagePubDir .= '/pub'; - } - - $file = $magentoPackagePubDir.'/'.$route; - - if (file_exists($file)) { - return $magentoPackagePubDir.$uri; - } - - if (strpos($route, $pub.'static/') === 0) { - $route = preg_replace('#'.$pub.'static/#', '', $route, 1); - $_GET['resource'] = $route; - include $magentoPackagePubDir.'/'.$pub.'static.php'; + if (strpos($uri, '/static/') === 0) { + $_GET['resource'] = preg_replace('#static/#', '', $uri, 1); + include($sitePath . '/pub/static.php'); exit; } - if (strpos($route, $pub.'media/') === 0) { - include $magentoPackagePubDir.'/'.$pub.'get.php'; + if (strpos($uri, '/media/') === 0) { + include($sitePath . '/pub/get.php'); exit; } @@ -69,75 +40,12 @@ public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: } /** - * Rewrite URLs that look like "versions12345/" to remove - * the versions12345/ part. - */ - private function handleForVersions($route): string - { - return preg_replace('/version\d*\//', '', $route); - } - - /** - * Determine the current MAGE_MODE. - */ - private function checkMageMode($sitePath): void - { - if ($this->mageMode !== null) { - // We have already figure out mode, no need to check it again - return; - } - - 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 (array_key_exists('MAGE_MODE', $mageConfig)) { - $this->mageMode = $mageConfig['MAGE_MODE']; - } - } - - /** - * 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. - */ - private function isPubDirectory($sitePath, $route, $pub = ''): bool - { - $sitePath .= '/pub/'; - $dirs = glob($sitePath.'*', GLOB_ONLYDIR); - - $dirs = str_replace($sitePath, '', $dirs); - - foreach ($dirs as $dir) { - if (strpos($route, $pub.$dir.'/') === 0) { - return true; - } - } - - return false; - } - - /** - * Get the fully resolved path to the application's front controller. + * @inheritdoc */ public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string { - $this->checkMageMode($sitePath); - - if ($this->mageMode === 'developer') { - $_SERVER['DOCUMENT_ROOT'] = $sitePath; - - return $sitePath.'/index.php'; - } - - $_SERVER['DOCUMENT_ROOT'] = $sitePath.'/pub'; + $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; + $_SERVER['DOCUMENT_ROOT'] = $sitePath; return $sitePath.'/pub/index.php'; } From 0fef72b64b96d76141c887ce4f002551a4ba3858 Mon Sep 17 00:00:00 2001 From: driesvints Date: Thu, 28 Sep 2023 14:24:39 +0000 Subject: [PATCH 28/28] Fix code styling --- cli/Valet/Drivers/Specific/Magento2ValetDriver.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/Valet/Drivers/Specific/Magento2ValetDriver.php b/cli/Valet/Drivers/Specific/Magento2ValetDriver.php index 3bf799a..c6c7d43 100644 --- a/cli/Valet/Drivers/Specific/Magento2ValetDriver.php +++ b/cli/Valet/Drivers/Specific/Magento2ValetDriver.php @@ -7,7 +7,7 @@ class Magento2ValetDriver extends ValetDriver { /** - * @inheritdoc + * {@inheritdoc} */ public function serves(string $sitePath, string $siteName, string $uri): bool { @@ -15,24 +15,24 @@ public function serves(string $sitePath, string $siteName, string $uri): bool } /** - * @inheritdoc + * {@inheritdoc} */ public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */ { $uri = preg_replace('/^\/static(\/version[\d]+)/', '/static', $uri); - if (file_exists($staticFilePath = $sitePath . '/pub' . $uri)) { + if (file_exists($staticFilePath = $sitePath.'/pub'.$uri)) { return $staticFilePath; } if (strpos($uri, '/static/') === 0) { $_GET['resource'] = preg_replace('#static/#', '', $uri, 1); - include($sitePath . '/pub/static.php'); + include $sitePath.'/pub/static.php'; exit; } if (strpos($uri, '/media/') === 0) { - include($sitePath . '/pub/get.php'); + include $sitePath.'/pub/get.php'; exit; } @@ -40,11 +40,11 @@ public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: } /** - * @inheritdoc + * {@inheritdoc} */ public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string { - $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; + $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; $_SERVER['DOCUMENT_ROOT'] = $sitePath; return $sitePath.'/pub/index.php';