From 12c10e0b03f9b4f8073e4d131bfbd89ce5d0a644 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 28 Aug 2023 14:38:42 -0400 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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;