From 63324614dd204479985cf6942407b3cbf0a3d042 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Wed, 2 Apr 2025 03:23:56 +0100 Subject: [PATCH 01/13] refactor: move all drivers into the PSR-4 autoloaded `Valet` classes directory - Move all drivers into a new `Drivers` directory within the `Valet` directory so they can be autoloaded by PSR-4. - Separate the specific drivers into a new `Specific` subdirectory of `Drivers`, and leave the basic and laravel drivers in the `Drivers` directory. - Namespace all driver classes as `Valet\Drivers` or `Valet\Drivers\Specific`. - Add `use` declarations for classes that need to be used within another class. --- cli/{drivers => Valet/Drivers}/BasicValetDriver.php | 4 +++- cli/{drivers => Valet/Drivers}/LaravelValetDriver.php | 4 +++- .../Drivers/Specific}/BedrockValetDriver.php | 6 +++++- .../Drivers/Specific}/CakeValetDriver.php | 6 +++++- .../Drivers/Specific}/Concrete5ValetDriver.php | 6 +++++- .../Drivers/Specific}/ContaoValetDriver.php | 6 +++++- .../Drivers/Specific}/CraftValetDriver.php | 6 +++++- .../Drivers/Specific}/DrupalValetDriver.php | 6 +++++- .../Drivers/Specific}/JigsawValetDriver.php | 4 ++++ .../Drivers/Specific}/JoomlaValetDriver.php | 4 ++++ .../Drivers/Specific}/KatanaValetDriver.php | 6 +++++- .../Drivers/Specific}/KirbyValetDriver.php | 6 +++++- .../Drivers/Specific}/Magento2ValetDriver.php | 6 +++++- .../Drivers/Specific}/NeosValetDriver.php | 6 +++++- .../Drivers/Specific}/SculpinValetDriver.php | 6 +++++- .../Drivers/Specific}/StatamicV1ValetDriver.php | 6 +++++- .../Drivers/Specific}/StatamicValetDriver.php | 6 +++++- .../Drivers/Specific}/SymfonyValetDriver.php | 6 +++++- .../Drivers/Specific}/Typo3ValetDriver.php | 6 +++++- .../Drivers/Specific}/WordPressValetDriver.php | 6 +++++- cli/{drivers => Valet/Drivers}/ValetDriver.php | 7 +++++++ 21 files changed, 101 insertions(+), 18 deletions(-) rename cli/{drivers => Valet/Drivers}/BasicValetDriver.php (99%) rename cli/{drivers => Valet/Drivers}/LaravelValetDriver.php (98%) rename cli/{drivers => Valet/Drivers/Specific}/BedrockValetDriver.php (95%) rename cli/{drivers => Valet/Drivers/Specific}/CakeValetDriver.php (94%) rename cli/{drivers => Valet/Drivers/Specific}/Concrete5ValetDriver.php (93%) rename cli/{drivers => Valet/Drivers/Specific}/ContaoValetDriver.php (95%) rename cli/{drivers => Valet/Drivers/Specific}/CraftValetDriver.php (98%) rename cli/{drivers => Valet/Drivers/Specific}/DrupalValetDriver.php (97%) rename cli/{drivers => Valet/Drivers/Specific}/JigsawValetDriver.php (87%) rename cli/{drivers => Valet/Drivers/Specific}/JoomlaValetDriver.php (90%) rename cli/{drivers => Valet/Drivers/Specific}/KatanaValetDriver.php (87%) rename cli/{drivers => Valet/Drivers/Specific}/KirbyValetDriver.php (96%) rename cli/{drivers => Valet/Drivers/Specific}/Magento2ValetDriver.php (98%) rename cli/{drivers => Valet/Drivers/Specific}/NeosValetDriver.php (94%) rename cli/{drivers => Valet/Drivers/Specific}/SculpinValetDriver.php (94%) rename cli/{drivers => Valet/Drivers/Specific}/StatamicV1ValetDriver.php (95%) rename cli/{drivers => Valet/Drivers/Specific}/StatamicValetDriver.php (98%) rename cli/{drivers => Valet/Drivers/Specific}/SymfonyValetDriver.php (95%) rename cli/{drivers => Valet/Drivers/Specific}/Typo3ValetDriver.php (98%) rename cli/{drivers => Valet/Drivers/Specific}/WordPressValetDriver.php (94%) rename cli/{drivers => Valet/Drivers}/ValetDriver.php (97%) diff --git a/cli/drivers/BasicValetDriver.php b/cli/Valet/Drivers/BasicValetDriver.php similarity index 99% rename from cli/drivers/BasicValetDriver.php rename to cli/Valet/Drivers/BasicValetDriver.php index 673ae779d..e01eebb2b 100644 --- a/cli/drivers/BasicValetDriver.php +++ b/cli/Valet/Drivers/BasicValetDriver.php @@ -1,5 +1,7 @@ Date: Wed, 2 Apr 2025 03:36:27 +0100 Subject: [PATCH 02/13] fix: user custom drivers by adding legacy drivers that extend the new namespaced drivers. These legacy drivers are deprecated by default as of v3.2.0. --- cli/includes/legacy_drivers/BasicValetDriver.php | 4 ++++ cli/includes/legacy_drivers/BedrockValetDriver.php | 4 ++++ cli/includes/legacy_drivers/CakeValetDriver.php | 4 ++++ cli/includes/legacy_drivers/Concrete5ValetDriver.php | 4 ++++ cli/includes/legacy_drivers/ContaoValetDriver.php | 4 ++++ cli/includes/legacy_drivers/CraftValetDriver.php | 4 ++++ cli/includes/legacy_drivers/DrupalValetDriver.php | 4 ++++ cli/includes/legacy_drivers/JigsawValetDriver.php | 4 ++++ cli/includes/legacy_drivers/JoomlaValetDriver.php | 4 ++++ cli/includes/legacy_drivers/KatanaValetDriver.php | 4 ++++ cli/includes/legacy_drivers/KirbyValetDriver.php | 4 ++++ cli/includes/legacy_drivers/LaravelValetDriver.php | 4 ++++ cli/includes/legacy_drivers/Magento2ValetDriver.php | 4 ++++ cli/includes/legacy_drivers/NeosValetDriver.php | 4 ++++ cli/includes/legacy_drivers/SculpinValetDriver.php | 4 ++++ cli/includes/legacy_drivers/StatamicV1ValetDriver.php | 4 ++++ cli/includes/legacy_drivers/StatamicValetDriver.php | 4 ++++ cli/includes/legacy_drivers/SymfonyValetDriver.php | 4 ++++ cli/includes/legacy_drivers/Typo3ValetDriver.php | 4 ++++ cli/includes/legacy_drivers/ValetDriver.php | 11 +++++++++++ cli/includes/legacy_drivers/WordPressValetDriver.php | 4 ++++ 21 files changed, 91 insertions(+) create mode 100644 cli/includes/legacy_drivers/BasicValetDriver.php create mode 100644 cli/includes/legacy_drivers/BedrockValetDriver.php create mode 100644 cli/includes/legacy_drivers/CakeValetDriver.php create mode 100644 cli/includes/legacy_drivers/Concrete5ValetDriver.php create mode 100644 cli/includes/legacy_drivers/ContaoValetDriver.php create mode 100644 cli/includes/legacy_drivers/CraftValetDriver.php create mode 100644 cli/includes/legacy_drivers/DrupalValetDriver.php create mode 100644 cli/includes/legacy_drivers/JigsawValetDriver.php create mode 100644 cli/includes/legacy_drivers/JoomlaValetDriver.php create mode 100644 cli/includes/legacy_drivers/KatanaValetDriver.php create mode 100644 cli/includes/legacy_drivers/KirbyValetDriver.php create mode 100644 cli/includes/legacy_drivers/LaravelValetDriver.php create mode 100644 cli/includes/legacy_drivers/Magento2ValetDriver.php create mode 100644 cli/includes/legacy_drivers/NeosValetDriver.php create mode 100644 cli/includes/legacy_drivers/SculpinValetDriver.php create mode 100644 cli/includes/legacy_drivers/StatamicV1ValetDriver.php create mode 100644 cli/includes/legacy_drivers/StatamicValetDriver.php create mode 100644 cli/includes/legacy_drivers/SymfonyValetDriver.php create mode 100644 cli/includes/legacy_drivers/Typo3ValetDriver.php create mode 100644 cli/includes/legacy_drivers/ValetDriver.php create mode 100644 cli/includes/legacy_drivers/WordPressValetDriver.php diff --git a/cli/includes/legacy_drivers/BasicValetDriver.php b/cli/includes/legacy_drivers/BasicValetDriver.php new file mode 100644 index 000000000..a7e984d01 --- /dev/null +++ b/cli/includes/legacy_drivers/BasicValetDriver.php @@ -0,0 +1,4 @@ + Date: Wed, 2 Apr 2025 03:44:30 +0100 Subject: [PATCH 03/13] refactor: move the drivers `require` file to the `includes` directory - Move `require.php` into `includes` directory and rename it to `require-drivers.php` and change the require reference in `server.php`. - Add the directory loop to require all legacy drivers. --- cli/drivers/require.php | 12 ------------ cli/includes/require-drivers.php | 26 ++++++++++++++++++++++++++ server.php | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) delete mode 100644 cli/drivers/require.php create mode 100644 cli/includes/require-drivers.php diff --git a/cli/drivers/require.php b/cli/drivers/require.php deleted file mode 100644 index c42bedc32..000000000 --- a/cli/drivers/require.php +++ /dev/null @@ -1,12 +0,0 @@ - Date: Thu, 3 Apr 2025 01:16:39 +0100 Subject: [PATCH 04/13] style: remove extra space in driver's docblock params, and convert string concatenation to interpolation - Remove extra spaces in the all driver's docblock params, and separate the params from the return and description. - Convert string concatenation to string interpolation. eg. $sitePath . '/web/app/' -> "$sitePath/web/app/" or "{$sitePath}/web/app/" --- cli/Valet/Drivers/BasicValetDriver.php | 23 +- cli/Valet/Drivers/LaravelValetDriver.php | 31 +- .../Drivers/Specific/BedrockValetDriver.php | 42 ++- .../Drivers/Specific/CakeValetDriver.php | 33 +- .../Drivers/Specific/Concrete5ValetDriver.php | 32 +- .../Drivers/Specific/ContaoValetDriver.php | 37 +- .../Drivers/Specific/CraftValetDriver.php | 45 +-- .../Drivers/Specific/DrupalValetDriver.php | 53 ++- .../Drivers/Specific/JigsawValetDriver.php | 18 +- .../Drivers/Specific/JoomlaValetDriver.php | 20 +- .../Drivers/Specific/KatanaValetDriver.php | 16 +- .../Drivers/Specific/KirbyValetDriver.php | 45 +-- .../Drivers/Specific/Magento2ValetDriver.php | 72 ++-- .../Drivers/Specific/NeosValetDriver.php | 29 +- .../Drivers/Specific/SculpinValetDriver.php | 43 ++- .../Specific/StatamicV1ValetDriver.php | 33 +- .../Drivers/Specific/StatamicValetDriver.php | 326 +++--------------- .../Drivers/Specific/SymfonyValetDriver.php | 35 +- .../Drivers/Specific/Typo3ValetDriver.php | 66 ++-- .../Drivers/Specific/WordPressValetDriver.php | 25 +- cli/Valet/Drivers/ValetDriver.php | 66 ++-- 21 files changed, 475 insertions(+), 615 deletions(-) diff --git a/cli/Valet/Drivers/BasicValetDriver.php b/cli/Valet/Drivers/BasicValetDriver.php index e01eebb2b..ee210d3db 100644 --- a/cli/Valet/Drivers/BasicValetDriver.php +++ b/cli/Valet/Drivers/BasicValetDriver.php @@ -6,10 +6,11 @@ class BasicValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { return true; @@ -18,9 +19,10 @@ public function serves($sitePath, $siteName, $uri) { /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { @@ -43,9 +45,10 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { diff --git a/cli/Valet/Drivers/LaravelValetDriver.php b/cli/Valet/Drivers/LaravelValetDriver.php index cb2f8f60a..7dfd40b0e 100644 --- a/cli/Valet/Drivers/LaravelValetDriver.php +++ b/cli/Valet/Drivers/LaravelValetDriver.php @@ -6,25 +6,27 @@ class LaravelValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/public/index.php') && file_exists($sitePath . '/artisan'); + return file_exists("$sitePath/public/index.php") && file_exists("$sitePath/artisan"); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { - if (file_exists($staticFilePath = $sitePath . '/public' . $uri)&& is_file($staticFilePath)) { + if (file_exists($staticFilePath = "$sitePath/public$uri") && is_file($staticFilePath)) { return $staticFilePath; } @@ -34,7 +36,7 @@ public function isStaticFile($sitePath, $siteName, $uri) { $storageUri = substr($uri, 8); } - if ($this->isActualFile($storagePath = $sitePath . '/storage/app/public' . $storageUri)) { + if ($this->isActualFile($storagePath = "$sitePath/storage/app/public$storageUri")) { return $storagePath; } @@ -44,9 +46,10 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { @@ -55,6 +58,6 @@ public function frontControllerPath($sitePath, $siteName, $uri) { $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; } - return $sitePath . '/public/index.php'; + return "$sitePath/public/index.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/BedrockValetDriver.php b/cli/Valet/Drivers/Specific/BedrockValetDriver.php index 7c440c73c..40451f2b1 100644 --- a/cli/Valet/Drivers/Specific/BedrockValetDriver.php +++ b/cli/Valet/Drivers/Specific/BedrockValetDriver.php @@ -8,25 +8,27 @@ class BedrockValetDriver extends BasicValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/web/app/mu-plugins/bedrock-autoloader.php') || (is_dir($sitePath . '/web/app/') && file_exists($sitePath . '/web/wp-config.php') && file_exists($sitePath . '/config/application.php')); + return file_exists("$sitePath/web/app/mu-plugins/bedrock-autoloader.php") || (is_dir("$sitePath/web/app/") && file_exists("$sitePath/web/wp-config.php") && file_exists("$sitePath/config/application.php")); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { - $staticFilePath = $sitePath . '/web' . $uri; + $staticFilePath = "$sitePath/web$uri"; if ($this->isActualFile($staticFilePath)) { return $staticFilePath; @@ -38,9 +40,10 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { @@ -48,26 +51,27 @@ public function frontControllerPath($sitePath, $siteName, $uri) { $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; if (strpos($uri, '/wp/') === 0) { - return is_dir($sitePath . '/web' . $uri) - ? $sitePath . '/web' . $this->forceTrailingSlash($uri) . '/index.php' - : $sitePath . '/web' . $uri; + return is_dir("$sitePath/web$uri") + ? "$sitePath/web" . $this->forceTrailingSlash($uri) . '/index.php' + : "$sitePath/web$uri"; } - return $sitePath . '/web/index.php'; + return "$sitePath/web/index.php"; } /** * Redirect to uri with trailing slash. * - * @param string $uri + * @param string $uri + * * @return string */ private function forceTrailingSlash($uri) { if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') { - header('Location: ' . $uri . '/'); + header("Location: $uri/"); exit; } return $uri; } -} \ No newline at end of file +} diff --git a/cli/Valet/Drivers/Specific/CakeValetDriver.php b/cli/Valet/Drivers/Specific/CakeValetDriver.php index 36f51cac6..df2dfdeac 100644 --- a/cli/Valet/Drivers/Specific/CakeValetDriver.php +++ b/cli/Valet/Drivers/Specific/CakeValetDriver.php @@ -8,25 +8,27 @@ class CakeValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/bin/cake'); + return file_exists("{$sitePath}/bin/cake"); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { - if ($this->isActualFile($staticFilePath = $sitePath . '/webroot/' . $uri)) { + if ($this->isActualFile($staticFilePath = "{$sitePath}/webroot/{$uri}")) { return $staticFilePath; } @@ -36,17 +38,18 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - $_SERVER['DOCUMENT_ROOT'] = $sitePath . '/webroot'; - $_SERVER['SCRIPT_FILENAME'] = $sitePath . '/webroot/index.php'; + $_SERVER['DOCUMENT_ROOT'] = "{$sitePath}/webroot"; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/webroot/index.php"; $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php'; - return $sitePath . '/webroot/index.php'; + return "{$sitePath}/webroot/index.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/Concrete5ValetDriver.php b/cli/Valet/Drivers/Specific/Concrete5ValetDriver.php index 32c46b4ed..6d1b6bf21 100644 --- a/cli/Valet/Drivers/Specific/Concrete5ValetDriver.php +++ b/cli/Valet/Drivers/Specific/Concrete5ValetDriver.php @@ -6,21 +6,25 @@ class Concrete5ValetDriver extends BasicValetDriver { /** - * If a concrete directory exists, it's probably c5. + * If a concrete directory exists, it's probably Concrete5. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/concrete/config/install/base'); + return file_exists("{$sitePath}/concrete/config/install/base"); } /** - * @param string $sitePath - * @param string $siteName - * @param string $uri + * Get the fully resolved path to the application's front controller. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { @@ -32,17 +36,17 @@ public function frontControllerPath($sitePath, $siteName, $uri) { if (preg_match('/^\/(.*?)\.php/', $uri, $matches)) { $filename = $matches[0]; - if (file_exists($sitePath . $filename) && !is_dir($sitePath . $filename)) { - $_SERVER['SCRIPT_FILENAME'] = $sitePath . $filename; + if (file_exists("{$sitePath}{$filename}") && !is_dir("{$sitePath}{$filename}")) { + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}{$filename}"; $_SERVER['SCRIPT_NAME'] = $filename; - return $sitePath . $filename; + return "{$sitePath}{$filename}"; } } - $_SERVER['SCRIPT_FILENAME'] = $sitePath . '/index.php'; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/index.php"; $_SERVER['SCRIPT_NAME'] = '/index.php'; - return $sitePath . '/index.php'; + return "{$sitePath}/index.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/ContaoValetDriver.php b/cli/Valet/Drivers/Specific/ContaoValetDriver.php index ce3e67ea5..93a35e620 100644 --- a/cli/Valet/Drivers/Specific/ContaoValetDriver.php +++ b/cli/Valet/Drivers/Specific/ContaoValetDriver.php @@ -8,25 +8,27 @@ class ContaoValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return is_dir($sitePath . '/vendor/contao') && file_exists($sitePath . '/web/app.php'); + return is_dir("{$sitePath}/vendor/contao") && file_exists("{$sitePath}/web/app.php"); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { - if ($this->isActualFile($staticFilePath = $sitePath . '/web' . $uri)) { + if ($this->isActualFile($staticFilePath = "{$sitePath}/web{$uri}")) { return $staticFilePath; } @@ -36,23 +38,24 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { if ($uri === '/install.php') { - return $sitePath . '/web/install.php'; + 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'; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/app_dev.php"; - return $sitePath . '/web/app_dev.php'; + return "{$sitePath}/web/app_dev.php"; } - return $sitePath . '/web/app.php'; + return "{$sitePath}/web/app.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/CraftValetDriver.php b/cli/Valet/Drivers/Specific/CraftValetDriver.php index 6cb2c3114..50f48264c 100644 --- a/cli/Valet/Drivers/Specific/CraftValetDriver.php +++ b/cli/Valet/Drivers/Specific/CraftValetDriver.php @@ -8,45 +8,48 @@ class CraftValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/craft'); + return file_exists("{$sitePath}/craft"); } /** * Determine the name of the directory where the front controller lives. * - * @param string $sitePath + * @param string $sitePath + * * @return string */ public function frontControllerDirectory($sitePath) { $dirs = ['web', 'public']; foreach ($dirs as $dir) { - if (is_dir($sitePath . '/' . $dir)) { + if (is_dir("{$sitePath}/{$dir}")) { return $dir; } } - // Give up, and just return the default - return is_file($sitePath . '/craft') ? 'web' : 'public'; + + return is_file("{$sitePath}/craft") ? 'web' : 'public'; } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { $frontControllerDirectory = $this->frontControllerDirectory($sitePath); - if ($this->isActualFile($staticFilePath = $sitePath . '/' . $frontControllerDirectory . $uri)) { + if ($this->isActualFile($staticFilePath = "{$sitePath}/{$frontControllerDirectory}{$uri}")) { return $staticFilePath; } @@ -56,16 +59,16 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { $frontControllerDirectory = $this->frontControllerDirectory($sitePath); - // Default index path - $indexPath = $sitePath . '/' . $frontControllerDirectory . '/index.php'; + $indexPath = "{$sitePath}/{$frontControllerDirectory}/index.php"; $scriptName = '/index.php'; // Check if the first URL segment matches any of the defined locales @@ -190,12 +193,12 @@ public function frontControllerPath($sitePath, $siteName, $uri) { $parts = explode('/', $uri); if (count($parts) > 1 && in_array($parts[1], $locales)) { - $indexLocalizedPath = $sitePath . '/' . $frontControllerDirectory . '/' . $parts[1] . '/index.php'; + $indexLocalizedPath = "$sitePath/$frontControllerDirectory/{$parts[1]}/index.php"; // Check if index.php exists in the localized folder, this is optional in Craft 3 if (file_exists($indexLocalizedPath)) { $indexPath = $indexLocalizedPath; - $scriptName = '/' . $parts[1] . '/index.php'; + $scriptName = "/{$parts[1]}/index.php"; } } @@ -203,7 +206,7 @@ public function frontControllerPath($sitePath, $siteName, $uri) { $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; $_SERVER['SCRIPT_NAME'] = $scriptName; $_SERVER['PHP_SELF'] = $scriptName; - $_SERVER['DOCUMENT_ROOT'] = $sitePath . '/' . $frontControllerDirectory; + $_SERVER['DOCUMENT_ROOT'] = "$sitePath/$frontControllerDirectory"; return $indexPath; } diff --git a/cli/Valet/Drivers/Specific/DrupalValetDriver.php b/cli/Valet/Drivers/Specific/DrupalValetDriver.php index b2d73df73..606eb9f20 100644 --- a/cli/Valet/Drivers/Specific/DrupalValetDriver.php +++ b/cli/Valet/Drivers/Specific/DrupalValetDriver.php @@ -8,37 +8,32 @@ class DrupalValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { $sitePath = $this->addSubdirectory($sitePath); - /** - * /misc/drupal.js = Drupal 7 - * /core/lib/Drupal.php = Drupal 8. - */ - if (file_exists($sitePath . '/misc/drupal.js') || file_exists($sitePath . '/core/lib/Drupal.php')) { - return true; - } - return false; + return file_exists("{$sitePath}/misc/drupal.js") || file_exists("{$sitePath}/core/lib/Drupal.php"); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { $sitePath = $this->addSubdirectory($sitePath); - if (file_exists($sitePath . $uri) && !is_dir($sitePath . $uri) && pathinfo($sitePath . $uri)['extension'] != 'php') { - return $sitePath . $uri; + if (file_exists("{$sitePath}{$uri}") && !is_dir("{$sitePath}{$uri}") && pathinfo("{$sitePath}{$uri}")['extension'] != 'php') { + return "{$sitePath}{$uri}"; } return false; @@ -47,9 +42,10 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { @@ -62,27 +58,30 @@ public function frontControllerPath($sitePath, $siteName, $uri) { $matches = []; if (preg_match('/^\/(.*?)\.php/', $uri, $matches)) { $filename = $matches[0]; - if (file_exists($sitePath . $filename) && !is_dir($sitePath . $filename)) { - $_SERVER['SCRIPT_FILENAME'] = $sitePath . $filename; + if (file_exists("{$sitePath}{$filename}") && !is_dir("{$sitePath}{$filename}")) { + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}{$filename}"; $_SERVER['SCRIPT_NAME'] = $filename; - return $sitePath . $filename; + return "{$sitePath}{$filename}"; } } - // Fallback - $_SERVER['SCRIPT_FILENAME'] = $sitePath . '/index.php'; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/index.php"; $_SERVER['SCRIPT_NAME'] = '/index.php'; - return $sitePath . '/index.php'; + return "{$sitePath}/index.php"; } /** * Add any matching subdirectory to the site path. + * + * @param string $sitePath + * + * @return string */ public function addSubdirectory($sitePath) { $paths = array_map(function ($subDir) use ($sitePath) { - return "$sitePath/$subDir"; + return "{$sitePath}/{$subDir}"; }, $this->possibleSubdirectories()); $foundPaths = array_filter($paths, function ($path) { diff --git a/cli/Valet/Drivers/Specific/JigsawValetDriver.php b/cli/Valet/Drivers/Specific/JigsawValetDriver.php index 02f075c9d..8d3fc4c52 100644 --- a/cli/Valet/Drivers/Specific/JigsawValetDriver.php +++ b/cli/Valet/Drivers/Specific/JigsawValetDriver.php @@ -8,22 +8,24 @@ class JigsawValetDriver extends BasicValetDriver { /** * Mutate the incoming URI. * - * @param string $uri + * @param string $uri + * * @return string */ public function mutateUri($uri) { - return rtrim('/build_local' . $uri, '/'); + return rtrim("/build_local{$uri}", '/'); } /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return is_dir($sitePath . '/build_local'); + return is_dir("{$sitePath}/build_local"); } -} +} \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/JoomlaValetDriver.php b/cli/Valet/Drivers/Specific/JoomlaValetDriver.php index 09e6fc3bc..d064b9385 100644 --- a/cli/Valet/Drivers/Specific/JoomlaValetDriver.php +++ b/cli/Valet/Drivers/Specific/JoomlaValetDriver.php @@ -8,21 +8,23 @@ class JoomlaValetDriver extends BasicValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return is_dir($sitePath . '/libraries/joomla'); + return is_dir("{$sitePath}/libraries/joomla"); } /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { @@ -30,4 +32,4 @@ public function frontControllerPath($sitePath, $siteName, $uri) { return parent::frontControllerPath($sitePath, $siteName, $uri); } -} +} \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/KatanaValetDriver.php b/cli/Valet/Drivers/Specific/KatanaValetDriver.php index fb470dffc..81c3b8929 100644 --- a/cli/Valet/Drivers/Specific/KatanaValetDriver.php +++ b/cli/Valet/Drivers/Specific/KatanaValetDriver.php @@ -8,22 +8,24 @@ class KatanaValetDriver extends BasicValetDriver { /** * Mutate the incoming URI. * - * @param string $uri + * @param string $uri The requested URI. + * * @return string */ public function mutateUri($uri) { - return rtrim('/public' . $uri, '/'); + return rtrim("/public{$uri}", '/'); } /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/katana'); + return file_exists("{$sitePath}/katana"); } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/KirbyValetDriver.php b/cli/Valet/Drivers/Specific/KirbyValetDriver.php index a05597ee2..546961190 100644 --- a/cli/Valet/Drivers/Specific/KirbyValetDriver.php +++ b/cli/Valet/Drivers/Specific/KirbyValetDriver.php @@ -8,28 +8,30 @@ class KirbyValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return is_dir($sitePath . '/kirby'); + return is_dir("{$sitePath}/kirby"); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { - if ($this->isActualFile($staticFilePath = $sitePath . $uri)) { + if ($this->isActualFile($staticFilePath = "{$sitePath}{$uri}")) { return $staticFilePath; } - elseif ($this->isActualFile($staticFilePath = $sitePath . '/public' . $uri)) { + elseif ($this->isActualFile($staticFilePath = "{$sitePath}/public{$uri}")) { return $staticFilePath; } @@ -39,32 +41,33 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { $scriptName = '/index.php'; - if ($this->isActualFile($sitePath . '/index.php')) { - $indexPath = $sitePath . '/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'; + if ($isAboveWebroot = $this->isActualFile("$sitePath/public/index.php")) { + $indexPath = "$sitePath/public/index.php"; } - if (preg_match('/^\/panel/', $uri) && $this->isActualFile($sitePath . '/panel/index.php')) { + if (preg_match('/^\/panel/', $uri) && $this->isActualFile("$sitePath/panel/index.php")) { $scriptName = '/panel/index.php'; - $indexPath = $sitePath . '/panel/index.php'; + $indexPath = "$sitePath/panel/index.php"; } - $sitePathPrefix = ($isAboveWebroot) ? $sitePath . '/public' : $sitePath; + $sitePathPrefix = ($isAboveWebroot) ? "$sitePath/public" : $sitePath; $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; $_SERVER['SCRIPT_NAME'] = $scriptName; - $_SERVER['SCRIPT_FILENAME'] = $sitePathPrefix . $scriptName; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePathPrefix}{$scriptName}"; return $indexPath; } diff --git a/cli/Valet/Drivers/Specific/Magento2ValetDriver.php b/cli/Valet/Drivers/Specific/Magento2ValetDriver.php index a166481c8..44792adfc 100644 --- a/cli/Valet/Drivers/Specific/Magento2ValetDriver.php +++ b/cli/Valet/Drivers/Specific/Magento2ValetDriver.php @@ -15,21 +15,23 @@ class Magento2ValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return boolean */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/bin/magento') && file_exists($sitePath . '/pub/index.php'); + return file_exists("{$sitePath}/bin/magento") && file_exists("{$sitePath}/pub/index.php"); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { @@ -52,21 +54,21 @@ public function isStaticFile($sitePath, $siteName, $uri) { $magentoPackagePubDir .= '/pub'; } - $file = $magentoPackagePubDir . '/' . $route; + $file = "{$magentoPackagePubDir}/{$route}"; if (file_exists($file)) { - return $magentoPackagePubDir . $uri; + return "{$magentoPackagePubDir}{$uri}"; } - if (strpos($route, $pub . 'static/') === 0) { - $route = preg_replace('#' . $pub . 'static/#', '', $route, 1); + if (strpos($route, "{$pub}static/") === 0) { + $route = preg_replace("#{$pub}static/#", '', $route, 1); $_GET['resource'] = $route; - include $magentoPackagePubDir . '/' . $pub . 'static.php'; + include "{$magentoPackagePubDir}/{$pub}static.php"; exit; } - if (strpos($route, $pub . 'media/') === 0) { - include $magentoPackagePubDir . '/' . $pub . 'get.php'; + if (strpos($route, "{$pub}media/") === 0) { + include "{$magentoPackagePubDir}/{$pub}get.php"; exit; } @@ -77,7 +79,8 @@ public function isStaticFile($sitePath, $siteName, $uri) { * Rewrite URLs that look like "versions12345/" to remove * the versions12345/ part. * - * @param string $route + * @param string $route + * * @return string */ private function handleForVersions($route) { @@ -87,7 +90,9 @@ private function handleForVersions($route) { /** * Determine the current MAGE_MODE. * - * @param string $sitePath + * @param string $sitePath + * + * @return void */ private function checkMageMode($sitePath) { if (null !== $this->mageMode) { @@ -95,7 +100,7 @@ private function checkMageMode($sitePath) { return; } - if (!file_exists($sitePath . '/index.php')) { + if (!file_exists("{$sitePath}/index.php")) { $this->mageMode = 'production'; // Can't use developer mode without index.php in project root return; @@ -103,8 +108,8 @@ private function checkMageMode($sitePath) { $mageConfig = []; - if (file_exists($sitePath . '/app/etc/env.php')) { - $mageConfig = require $sitePath . '/app/etc/env.php'; + if (file_exists("{$sitePath}/app/etc/env.php")) { + $mageConfig = require "{$sitePath}/app/etc/env.php"; } if (array_key_exists('MAGE_MODE', $mageConfig)) { @@ -113,21 +118,23 @@ private function checkMageMode($sitePath) { } /** - * 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. + * 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. + * + * @param string $sitePath + * @param string $route + * @param string $pub * - * @param string $sitePath - * @param string $route - * @param string $pub * @return bool */ private function isPubDirectory($sitePath, $route, $pub = '') { $sitePath .= '/pub/'; - $dirs = glob($sitePath . '*', GLOB_ONLYDIR); + $dirs = glob("{$sitePath}*", GLOB_ONLYDIR); $dirs = str_replace($sitePath, '', $dirs); foreach ($dirs as $dir) { - if (strpos($route, $pub . $dir . '/') === 0) { + if (strpos($route, "{$pub}{$dir}/") === 0) { return true; } } @@ -138,9 +145,10 @@ private function isPubDirectory($sitePath, $route, $pub = '') { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { @@ -149,11 +157,11 @@ public function frontControllerPath($sitePath, $siteName, $uri) { if ('developer' === $this->mageMode) { $_SERVER['DOCUMENT_ROOT'] = $sitePath; - return $sitePath . '/index.php'; + return "{$sitePath}/index.php"; } - $_SERVER['DOCUMENT_ROOT'] = $sitePath . '/pub'; + $_SERVER['DOCUMENT_ROOT'] = "{$sitePath}/pub"; - return $sitePath . '/pub/index.php'; + return "{$sitePath}/pub/index.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/NeosValetDriver.php b/cli/Valet/Drivers/Specific/NeosValetDriver.php index 443ee490b..6ab2f8a8e 100644 --- a/cli/Valet/Drivers/Specific/NeosValetDriver.php +++ b/cli/Valet/Drivers/Specific/NeosValetDriver.php @@ -8,25 +8,27 @@ class NeosValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return boolean */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/flow') && is_dir($sitePath . '/Web'); + return file_exists("{$sitePath}/flow") && is_dir("{$sitePath}/Web"); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { - if ($this->isActualFile($staticFilePath = $sitePath . '/Web' . $uri)) { + if ($this->isActualFile($staticFilePath = "{$sitePath}/Web{$uri}")) { return $staticFilePath; } @@ -36,17 +38,18 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { putenv('FLOW_CONTEXT=Development'); putenv('FLOW_REWRITEURLS=1'); - $_SERVER['SCRIPT_FILENAME'] = $sitePath . '/Web/index.php'; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/Web/index.php"; $_SERVER['SCRIPT_NAME'] = '/index.php'; - return $sitePath . '/Web/index.php'; + return "{$sitePath}/Web/index.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/SculpinValetDriver.php b/cli/Valet/Drivers/Specific/SculpinValetDriver.php index df6e40fa8..3973f546b 100644 --- a/cli/Valet/Drivers/Specific/SculpinValetDriver.php +++ b/cli/Valet/Drivers/Specific/SculpinValetDriver.php @@ -8,29 +8,51 @@ class SculpinValetDriver extends BasicValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { return $this->isModernSculpinProject($sitePath) || $this->isLegacySculpinProject($sitePath); } + /** + * Determine if the project is a modern Sculpin project. + * + * @param string $sitePath + * + * @return bool + */ private function isModernSculpinProject($sitePath) { - return is_dir($sitePath . '/source') && is_dir($sitePath . '/output_dev') && $this->composerRequiresSculpin($sitePath); + return is_dir("{$sitePath}/source") && is_dir("{$sitePath}/output_dev") && $this->composerRequiresSculpin($sitePath); } + /** + * Determine if the project is a legacy Sculpin project. + * + * @param string $sitePath + * + * @return bool + */ private function isLegacySculpinProject($sitePath) { - return is_dir($sitePath . '/.sculpin'); + return is_dir("{$sitePath}/.sculpin"); } + /** + * Check if the composer.json file requires Sculpin. + * + * @param string $sitePath + * + * @return bool + */ private function composerRequiresSculpin($sitePath) { - if (!file_exists($sitePath . '/composer.json')) { + if (!file_exists("{$sitePath}/composer.json")) { return false; } - $composer_json_source = file_get_contents($sitePath . '/composer.json'); + $composer_json_source = file_get_contents("{$sitePath}/composer.json"); $composer_json = json_decode($composer_json_source, true); if (json_last_error() !== JSON_ERROR_NONE) { @@ -43,10 +65,11 @@ private function composerRequiresSculpin($sitePath) { /** * Mutate the incoming URI. * - * @param string $uri + * @param string $uri + * * @return string */ public function mutateUri($uri) { - return rtrim('/output_dev' . $uri, '/'); + return rtrim("/output_dev{$uri}", '/'); } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/StatamicV1ValetDriver.php b/cli/Valet/Drivers/Specific/StatamicV1ValetDriver.php index cedf3674c..184415841 100644 --- a/cli/Valet/Drivers/Specific/StatamicV1ValetDriver.php +++ b/cli/Valet/Drivers/Specific/StatamicV1ValetDriver.php @@ -8,21 +8,23 @@ class StatamicV1ValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/_app/core/statamic.php'); + return file_exists("{$sitePath}/_app/core/statamic.php"); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { @@ -30,7 +32,7 @@ public function isStaticFile($sitePath, $siteName, $uri) { return false; } - if ($this->isActualFile($staticFilePath = $sitePath . $uri)) { + if ($this->isActualFile($staticFilePath = "{$sitePath}{$uri}")) { return $staticFilePath; } @@ -40,26 +42,27 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { if (strpos($uri, '/admin.php') === 0) { $_SERVER['SCRIPT_NAME'] = '/admin.php'; - return $sitePath . '/admin.php'; + return "{$sitePath}/admin.php"; } if ($uri === '/admin') { $_SERVER['SCRIPT_NAME'] = '/admin/index.php'; - return $sitePath . '/admin/index.php'; + return "{$sitePath}/admin/index.php"; } $_SERVER['SCRIPT_NAME'] = '/index.php'; - return $sitePath . '/index.php'; + return "{$sitePath}/index.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/StatamicValetDriver.php b/cli/Valet/Drivers/Specific/StatamicValetDriver.php index cdbb47c6b..a28271453 100644 --- a/cli/Valet/Drivers/Specific/StatamicValetDriver.php +++ b/cli/Valet/Drivers/Specific/StatamicValetDriver.php @@ -8,21 +8,23 @@ class StatamicValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return is_dir($sitePath . '/statamic'); + return is_dir("{$sitePath}/statamic"); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { @@ -32,10 +34,10 @@ public function isStaticFile($sitePath, $siteName, $uri) { elseif (strpos($uri, '/local') === 0 || strpos($uri, '/statamic') === 0) { return false; } - elseif ($this->isActualFile($staticFilePath = $sitePath . $uri)) { + elseif ($this->isActualFile($staticFilePath = "{$sitePath}{$uri}")) { return $staticFilePath; } - elseif ($this->isActualFile($staticFilePath = $sitePath . '/public' . $uri)) { + elseif ($this->isActualFile($staticFilePath = "{$sitePath}/public{$uri}")) { return $staticFilePath; } @@ -45,9 +47,10 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { @@ -56,36 +59,36 @@ public function frontControllerPath($sitePath, $siteName, $uri) { } if ($uri === '/installer.php') { - return $sitePath . '/installer.php'; + return "{$sitePath}/installer.php"; } $scriptName = '/index.php'; - if ($this->isActualFile($sitePath . '/index.php')) { - $indexPath = $sitePath . '/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'; + if ($isAboveWebroot = $this->isActualFile("{$sitePath}/public/index.php")) { + $indexPath = "{$sitePath}/public/index.php"; } - $sitePathPrefix = ($isAboveWebroot) ? $sitePath . '/public' : $sitePath; + $sitePathPrefix = $isAboveWebroot ? "{$sitePath}/public" : $sitePath; if ($locale = $this->getUriLocale($uri)) { - if ($this->isActualFile($localeIndexPath = $sitePathPrefix . '/' . $locale . '/index.php')) { + if ($this->isActualFile($localeIndexPath = "{$sitePathPrefix}/{$locale}/index.php")) { // Force trailing slashes on locale roots. - if ($uri === '/' . $locale) { - header('Location: ' . $uri . '/'); + if ($uri === "/{$locale}") { + header("Location: {$uri}/"); exit; } $indexPath = $localeIndexPath; - $scriptName = '/' . $locale . '/index.php'; + $scriptName = "/{$locale}/index.php"; } } $_SERVER['SCRIPT_NAME'] = $scriptName; - $_SERVER['SCRIPT_FILENAME'] = $sitePathPrefix . $scriptName; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePathPrefix}{$scriptName}"; return $indexPath; } @@ -93,7 +96,8 @@ public function frontControllerPath($sitePath, $siteName, $uri) { /** * Get the locale from this URI. * - * @param string $uri + * @param string $uri + * * @return string|null */ public function getUriLocale($uri) { @@ -113,271 +117,37 @@ public function getUriLocale($uri) { * @return array */ public function getLocales() { + // phpcs:disable Squiz.Arrays.ArrayDeclaration.ValueNoNewline 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' + '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' ]; + // phpcs:enable } /** * Get the path to a statically cached page. * - * @param string $sitePath + * @param string $sitePath + * * @return string */ protected function getStaticPath($sitePath) { $parts = parse_url($_SERVER['REQUEST_URI']); $query = isset($parts['query']) ? $parts['query'] : ''; - return $sitePath . '/static' . $parts['path'] . '_' . $query . '.html'; + return "{$sitePath}/static{$parts['path']}_{$query}.html"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/SymfonyValetDriver.php b/cli/Valet/Drivers/Specific/SymfonyValetDriver.php index 640a9b275..07d28b16e 100644 --- a/cli/Valet/Drivers/Specific/SymfonyValetDriver.php +++ b/cli/Valet/Drivers/Specific/SymfonyValetDriver.php @@ -8,28 +8,30 @@ class SymfonyValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return (file_exists($sitePath . '/web/app_dev.php') || file_exists($sitePath . '/web/app.php')) && (file_exists($sitePath . '/app/AppKernel.php')) || (file_exists($sitePath . '/public/index.php')) && (file_exists($sitePath . '/src/Kernel.php')); + return (file_exists("{$sitePath}/web/app_dev.php") || file_exists("{$sitePath}/web/app.php")) && file_exists("{$sitePath}/app/AppKernel.php") || (file_exists("{$sitePath}/public/index.php") && file_exists("{$sitePath}/src/Kernel.php")); } /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { - if ($this->isActualFile($staticFilePath = $sitePath . '/web/' . $uri)) { + if ($this->isActualFile($staticFilePath = "{$sitePath}/web/{$uri}")) { return $staticFilePath; } - elseif ($this->isActualFile($staticFilePath = $sitePath . '/public/' . $uri)) { + elseif ($this->isActualFile($staticFilePath = "{$sitePath}/public/{$uri}")) { return $staticFilePath; } @@ -39,19 +41,20 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - if (file_exists($frontControllerPath = $sitePath . '/web/app_dev.php')) { + if (file_exists($frontControllerPath = "{$sitePath}/web/app_dev.php")) { return $frontControllerPath; } - elseif (file_exists($frontControllerPath = $sitePath . '/web/app.php')) { + elseif (file_exists($frontControllerPath = "{$sitePath}/web/app.php")) { return $frontControllerPath; } - elseif (file_exists($frontControllerPath = $sitePath . '/public/index.php')) { + elseif (file_exists($frontControllerPath = "{$sitePath}/public/index.php")) { return $frontControllerPath; } } diff --git a/cli/Valet/Drivers/Specific/Typo3ValetDriver.php b/cli/Valet/Drivers/Specific/Typo3ValetDriver.php index e8bdee871..861660a84 100644 --- a/cli/Valet/Drivers/Specific/Typo3ValetDriver.php +++ b/cli/Valet/Drivers/Specific/Typo3ValetDriver.php @@ -5,9 +5,9 @@ use Valet\Drivers\ValetDriver; /** - * This driver serves TYPO3 instances (version 7.0 and up). It activates, if it + * This driver serves TYPO3 instances (version 7.0 and up). It activates if it * finds the characteristic typo3/ folder in the document root, serves both - * frontend and backend scripts and prevents access to private resources. + * frontend and backend scripts, and prevents access to private resources. */ class Typo3ValetDriver extends ValetDriver { /* @@ -28,7 +28,7 @@ class Typo3ValetDriver extends ValetDriver { |-------------------------------------------------------------------------- | | All of these patterns won't be accessible from your web server. Instead, - | the server will throw a 403 forbidden response, if you try to access + | the server will throw a 403 forbidden response if you try to access | these files via the HTTP layer. Use regex syntax here and escape @. | */ @@ -44,13 +44,14 @@ class Typo3ValetDriver extends ValetDriver { * Determine if the driver serves the request. For TYPO3, this is the * case, if a folder called "typo3" is present in the document root. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - $typo3Dir = $sitePath . $this->documentRoot . '/typo3'; + $typo3Dir = "{$sitePath}{$this->documentRoot}/typo3"; return file_exists($typo3Dir) && is_dir($typo3Dir); } @@ -60,23 +61,24 @@ public function serves($sitePath, $siteName, $uri) { * no PHP script file and the URI points to a valid file (no folder) on * the disk. Access to those static files will be authorized. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { // May the file contains a cache busting version string like filename.12345678.css // If that is the case, the file cannot be found on disk, so remove the version // identifier before retrying below. - if (!$this->isActualFile($filePath = $sitePath . $this->documentRoot . $uri)) { + if (!$this->isActualFile($filePath = "{$sitePath}{$this->documentRoot}{$uri}")) { $uri = preg_replace("@^(.+)\.(\d+)\.(js|css|png|jpg|gif|gzip)$@", '$1.$3', $uri); } // Now that any possible version string is cleared from the filename, the resulting // URI should be a valid file on disc. So assemble the absolute file name with the // same schema as above and if it exists, authorize access and return its path. - if ($this->isActualFile($filePath = $sitePath . $this->documentRoot . $uri)) { + if ($this->isActualFile($filePath = "{$sitePath}{$this->documentRoot}{$uri}")) { return $this->isAccessAuthorized($uri) ? $filePath : false; } @@ -87,7 +89,8 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Determines if the given URI is blacklisted so that access is prevented. * - * @param string $uri + * @param string $uri + * * @return bool */ private function isAccessAuthorized($uri) { @@ -105,9 +108,10 @@ private function isAccessAuthorized($uri) { * This can be the currently requested PHP script, a folder that * contains an index.php or the global index.php otherwise. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { @@ -118,16 +122,16 @@ public function frontControllerPath($sitePath, $siteName, $uri) { $uri = rtrim($uri, '/'); // try to find the responsible script file for the requested folder / script URI - if (file_exists($absoluteFilePath = $sitePath . $this->documentRoot . $uri)) { + if (file_exists($absoluteFilePath = "{$sitePath}{$this->documentRoot}{$uri}")) { if (is_dir($absoluteFilePath)) { - if (file_exists($absoluteFilePath . '/index.php')) { + if (file_exists("{$absoluteFilePath}/index.php")) { // this folder can be served by index.php - return $this->serveScript($sitePath, $siteName, $uri . '/index.php'); + return $this->serveScript($sitePath, $siteName, "{$uri}/index.php"); } - if (file_exists($absoluteFilePath . '/index.html')) { + if (file_exists("{$absoluteFilePath}/index.html")) { // this folder can be served by index.html - return $absoluteFilePath . '/index.html'; + return "{$absoluteFilePath}/index.html"; } } elseif (pathinfo($absoluteFilePath, PATHINFO_EXTENSION) === 'php') { @@ -145,7 +149,9 @@ public function frontControllerPath($sitePath, $siteName, $uri) { * sysext install script. domain.dev/typo3 will be redirected to /typo3/, because * the generated JavaScript URIs on the login screen would be broken on /typo3. * - * @param string $uri + * @param string $uri + * + * @return void */ private function handleRedirectBackendShorthandUris($uri) { if (rtrim($uri, '/') === '/typo3/install') { @@ -163,17 +169,17 @@ private function handleRedirectBackendShorthandUris($uri) { * Configures the $_SERVER globals for serving the script at * the specified URI and returns it absolute file path. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @param string $script + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ private function serveScript($sitePath, $siteName, $uri) { - $docroot = $sitePath . $this->documentRoot; - $abspath = $docroot . $uri; + $docroot = "{$sitePath}{$this->documentRoot}"; + $abspath = "{$docroot}{$uri}"; - $_SERVER['SERVER_NAME'] = $siteName . '.dev'; + $_SERVER['SERVER_NAME'] = "{$siteName}.dev"; $_SERVER['DOCUMENT_ROOT'] = $docroot; $_SERVER['DOCUMENT_URI'] = $uri; $_SERVER['SCRIPT_FILENAME'] = $abspath; diff --git a/cli/Valet/Drivers/Specific/WordPressValetDriver.php b/cli/Valet/Drivers/Specific/WordPressValetDriver.php index 95c6faa35..79e0e6e1a 100644 --- a/cli/Valet/Drivers/Specific/WordPressValetDriver.php +++ b/cli/Valet/Drivers/Specific/WordPressValetDriver.php @@ -8,21 +8,23 @@ class WordPressValetDriver extends BasicValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ public function serves($sitePath, $siteName, $uri) { - return file_exists($sitePath . '/wp-config.php') || file_exists($sitePath . '/wp-config-sample.php'); + return file_exists("{$sitePath}/wp-config.php") || file_exists("{$sitePath}/wp-config-sample.php"); } /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { @@ -38,14 +40,15 @@ public function frontControllerPath($sitePath, $siteName, $uri) { } /** - * Redirect to uri with trailing slash. + * Redirect to URI with a trailing slash. + * + * @param string $uri * - * @param string $uri * @return string */ private function forceTrailingSlash($uri) { if (substr($uri, -1 * strlen('/wp-admin')) == '/wp-admin') { - header('Location: ' . $uri . '/'); + header("Location: {$uri}/"); exit; } diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index 30513123f..cb9dcb3ec 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -13,19 +13,21 @@ abstract class ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return bool */ abstract public function serves($sitePath, $siteName, $uri); /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string|false */ abstract public function isStaticFile($sitePath, $siteName, $uri); @@ -33,9 +35,10 @@ abstract public function isStaticFile($sitePath, $siteName, $uri); /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return string */ abstract public function frontControllerPath($sitePath, $siteName, $uri); @@ -43,9 +46,10 @@ abstract public function frontControllerPath($sitePath, $siteName, $uri); /** * Find a driver that can serve the incoming request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return ValetDriver|null */ public static function assign($sitePath, $siteName, $uri) { @@ -90,17 +94,18 @@ public static function assign($sitePath, $siteName, $uri) { } /** - * Get the custom driver class from the site path, if one exists. + * Get the custom driver class from the local site path, if one exists. + * + * @param string $sitePath * - * @param string $sitePath * @return void|string */ public static function customSiteDriver($sitePath) { - if (!file_exists($sitePath . '/LocalValetDriver.php')) { + if (!file_exists("$sitePath/LocalValetDriver.php")) { return; } - require_once $sitePath . '/LocalValetDriver.php'; + require_once "$sitePath/LocalValetDriver.php"; return 'LocalValetDriver'; } @@ -108,7 +113,8 @@ public static function customSiteDriver($sitePath) { /** * Get all of the driver classes in a given path. * - * @param string $path + * @param string $path + * * @return array */ public static function driversIn($path) { @@ -134,7 +140,8 @@ public static function driversIn($path) { /** * Mutate the incoming URI. * - * @param string $uri + * @param string $uri + * * @return string */ public function mutateUri($uri) { @@ -144,10 +151,11 @@ public function mutateUri($uri) { /** * Serve the static file at the given path. * - * @param string $staticFilePath - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $staticFilePath + * @param string $sitePath + * @param string $siteName + * @param string $uri + * * @return void */ public function serveStaticFile($staticFilePath, $sitePath, $siteName, $uri) { @@ -175,7 +183,8 @@ public function serveStaticFile($staticFilePath, $sitePath, $siteName, $uri) { /** * Determine if the path is a file and not a directory. * - * @param string $path + * @param string $path + * * @return bool */ protected function isActualFile($path) { @@ -186,12 +195,13 @@ protected function isActualFile($path) { * Load server environment variables if available. * Processes any '*' entries first, and then adds site-specific entries. * - * @param string $sitePath - * @param string $siteName + * @param string $sitePath + * @param string $siteName + * * @return void */ public function loadServerEnvironmentVariables($sitePath, $siteName) { - $varFilePath = $sitePath . '/.valet-env.php'; + $varFilePath = "$sitePath/.valet-env.php"; if (!file_exists($varFilePath)) { return; } @@ -210,7 +220,7 @@ public function loadServerEnvironmentVariables($sitePath, $siteName) { } $_SERVER[$key] = $value; $_ENV[$key] = $value; - putenv($key . '=' . $value); + putenv("$key=$value"); } } } \ No newline at end of file From 2705a793618ccee1bb9dad73ce4005fc2c53cbad Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 3 Apr 2025 01:17:40 +0100 Subject: [PATCH 05/13] feat: add 3 new drivers for `Nette`, `Radicle`, and `Statamic V2` --- .../Drivers/Specific/NetteValetDriver.php | 58 +++++++ .../Drivers/Specific/RadicleValetDriver.php | 76 +++++++++ .../Specific/StatamicV2ValetDriver.php | 153 ++++++++++++++++++ 3 files changed, 287 insertions(+) create mode 100644 cli/Valet/Drivers/Specific/NetteValetDriver.php create mode 100644 cli/Valet/Drivers/Specific/RadicleValetDriver.php create mode 100644 cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php diff --git a/cli/Valet/Drivers/Specific/NetteValetDriver.php b/cli/Valet/Drivers/Specific/NetteValetDriver.php new file mode 100644 index 000000000..9d3f11a0f --- /dev/null +++ b/cli/Valet/Drivers/Specific/NetteValetDriver.php @@ -0,0 +1,58 @@ +isActualFile($staticFilePath = "{$sitePath}/www/{$uri}")) { + return $staticFilePath; + } + + return false; + } + + /** + * Get the fully resolved path to the application's front controller. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return string + */ + public function frontControllerPath($sitePath, $siteName, $uri) { + $_SERVER['DOCUMENT_ROOT'] = "{$sitePath}/www"; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/www/index.php"; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + $_SERVER['PHP_SELF'] = '/index.php'; + + return "{$sitePath}/www/index.php"; + } +} \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/RadicleValetDriver.php b/cli/Valet/Drivers/Specific/RadicleValetDriver.php new file mode 100644 index 000000000..3bdf77aa5 --- /dev/null +++ b/cli/Valet/Drivers/Specific/RadicleValetDriver.php @@ -0,0 +1,76 @@ +isActualFile($staticFilePath)) { + return $staticFilePath; + } + + return false; + } + + /** + * Get the fully resolved path to the application's front controller. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return string + */ + public function frontControllerPath($sitePath, $siteName, $uri) { + $_SERVER['PHP_SELF'] = $uri; + if (strpos($uri, '/wp/') === 0) { + return is_dir("{$sitePath}/public{$uri}") + ? "{$sitePath}/public" . $this->forceTrailingSlash($uri) . '/index.php' + : "{$sitePath}/public{$uri}"; + } + + return "{$sitePath}/public/index.php"; + } + + /** + * Redirect to URI with trailing slash. + * + * @param string $uri + * + * @return string + */ + private function forceTrailingSlash($uri) { + if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') { + header("Location: {$uri}/"); + exit; + } + + return $uri; + } +} \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php b/cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php new file mode 100644 index 000000000..913ba3797 --- /dev/null +++ b/cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php @@ -0,0 +1,153 @@ +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. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return string + */ + public function frontControllerPath($sitePath, $siteName, $uri) { + 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. + * + * @param string $uri + * + * @return string|null + */ + public function getUriLocale($uri) { + $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. + * + * @return string[] + */ + public function getLocales() { + // phpcs:disable Squiz.Arrays.ArrayDeclaration.ValueNoNewline + 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' + ]; + // phpcs:enable + } + + /** + * Get the path to a statically cached page. + * + * @param string $sitePath + * + * @return string + */ + protected function getStaticPath($sitePath) { + $parts = parse_url($_SERVER['REQUEST_URI']); + $query = isset($parts['query']) ? $parts['query'] : ''; + + return "{$sitePath}/static{$parts['path']}_{$query}.html"; + } +} \ No newline at end of file From 5b28f8fa7265be8ca8995dab1f19e3ef8dbe6034 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 3 Apr 2025 01:28:25 +0100 Subject: [PATCH 06/13] refactor: extract functionality for public directory from basic driver into it's own class, and simplify both - Extract functionality for basic driver with a public directory into it's own class `BasicWithPublicValetDriver`, and simplify both classes. - Removed now redundant methods. --- cli/Valet/Drivers/BasicValetDriver.php | 102 ++---------------- .../Drivers/BasicWithPublicValetDriver.php | 77 +++++++++++++ cli/Valet/Drivers/ValetDriver.php | 1 + 3 files changed, 89 insertions(+), 91 deletions(-) create mode 100644 cli/Valet/Drivers/BasicWithPublicValetDriver.php diff --git a/cli/Valet/Drivers/BasicValetDriver.php b/cli/Valet/Drivers/BasicValetDriver.php index ee210d3db..81914f164 100644 --- a/cli/Valet/Drivers/BasicValetDriver.php +++ b/cli/Valet/Drivers/BasicValetDriver.php @@ -26,13 +26,7 @@ public function serves($sitePath, $siteName, $uri) { * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { - if (file_exists($staticFilePath = $sitePath . '/public' . rtrim($uri, '/') . '/index.html')) { - return $staticFilePath; - } - elseif (file_exists($staticFilePath = $sitePath . '/public' . rtrim($uri, '/') . '/index.php')) { - return $staticFilePath; - } - elseif (file_exists($staticFilePath = $sitePath . '/public' . $uri)) { + if (file_exists($staticFilePath = $sitePath . rtrim($uri, '/') . '/index.html')) { return $staticFilePath; } elseif ($this->isActualFile($staticFilePath = $sitePath . $uri)) { @@ -55,14 +49,17 @@ public function frontControllerPath($sitePath, $siteName, $uri) { $_SERVER['PHP_SELF'] = $uri; $_SERVER['SERVER_ADDR'] = '127.0.0.1'; $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; - - $dynamicCandidates = [ - $this->asActualFile($sitePath, $uri), - $this->asPhpIndexFileInDirectory($sitePath, $uri), - $this->asHtmlIndexFileInDirectory($sitePath, $uri) + + $uri = rtrim($uri, '/'); + + $candidates = [ + $sitePath . $uri, + $sitePath . "$uri/index.php", + "$sitePath/index.php", + "$sitePath/index.html" ]; - foreach ($dynamicCandidates as $candidate) { + foreach ($candidates as $candidate) { if ($this->isActualFile($candidate)) { $_SERVER['SCRIPT_FILENAME'] = $candidate; $_SERVER['SCRIPT_NAME'] = str_replace($sitePath, '', $candidate); @@ -72,83 +69,6 @@ public function frontControllerPath($sitePath, $siteName, $uri) { } } - $fixedCandidatesAndDocroots = [ - $this->asRootPhpIndexFile($sitePath) => $sitePath, - $this->asPublicPhpIndexFile($sitePath) => $sitePath . '/public', - $this->asPublicHtmlIndexFile($sitePath) => $sitePath . '/public' - ]; - - foreach ($fixedCandidatesAndDocroots as $candidate => $docroot) { - if ($this->isActualFile($candidate)) { - $_SERVER['SCRIPT_FILENAME'] = $candidate; - $_SERVER['SCRIPT_NAME'] = '/index.php'; - $_SERVER['DOCUMENT_ROOT'] = $docroot; - - return $candidate; - } - } - } - - /** - * Concatenate the site path and URI as a single file name. - * - * @param string $sitePath - * @param string $uri - * @return string - */ - protected function asActualFile($sitePath, $uri) { - return $sitePath . $uri; - } - - /** - * Format the site path and URI with a trailing "index.php". - * - * @param string $sitePath - * @param string $uri - * @return string - */ - protected function asPhpIndexFileInDirectory($sitePath, $uri) { - return $sitePath . rtrim($uri, '/') . '/index.php'; - } - - /** - * Format the site path and URI with a trailing "index.html". - * - * @param string $sitePath - * @param string $uri - * @return string - */ - protected function asHtmlIndexFileInDirectory($sitePath, $uri) { - return $sitePath . rtrim($uri, '/') . '/index.html'; - } - - /** - * Format the incoming site path as root "index.php" file path. - * - * @param string $sitePath - * @return string - */ - protected function asRootPhpIndexFile($sitePath) { - return $sitePath . '/index.php'; - } - - /** - * Format the incoming site path as a "public/index.php" file path. - * - * @param string $sitePath - * @return string - */ - protected function asPublicPhpIndexFile($sitePath) { - return $sitePath . '/public/index.php'; - } - - /** - * Format the incoming site path as a "public/index.php" file path. - * - * @param string $sitePath - * @return string - */ - protected function asPublicHtmlIndexFile($sitePath) { - return $sitePath . '/public/index.html'; + return null; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/BasicWithPublicValetDriver.php b/cli/Valet/Drivers/BasicWithPublicValetDriver.php new file mode 100644 index 000000000..f3ec119cc --- /dev/null +++ b/cli/Valet/Drivers/BasicWithPublicValetDriver.php @@ -0,0 +1,77 @@ +isActualFile($publicPath)) { + return $publicPath; + } + elseif (file_exists("$publicPath/index.html")) { + return "$publicPath/index.html"; + } + + return false; + } + + /** + * Get the fully resolved path to the application's front controller. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return string|null + */ + public function frontControllerPath($sitePath, $siteName, $uri) { + $_SERVER['PHP_SELF'] = $uri; + $_SERVER['SERVER_ADDR'] = '127.0.0.1'; + $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; + + $docRoot = "$sitePath/public"; + $uri = rtrim($uri, '/'); + + $candidates = [ + $docRoot . $uri, + $docRoot . "$uri/index.php", + "$docRoot/index.php", + "$docRoot/index.html" + ]; + + foreach ($candidates as $candidate) { + if ($this->isActualFile($candidate)) { + $_SERVER['SCRIPT_FILENAME'] = $candidate; + $_SERVER['SCRIPT_NAME'] = str_replace("$sitePath/public", '', $candidate); + $_SERVER['DOCUMENT_ROOT'] = "$sitePath/public"; + + return $candidate; + } + } + + return null; + } +} \ No newline at end of file diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index cb9dcb3ec..586fa9c10 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -82,6 +82,7 @@ public static function assign($sitePath, $siteName, $uri) { $drivers[] = 'NeosValetDriver'; $drivers[] = 'Magento2ValetDriver'; + $drivers[] = 'BasicWithPublicValetDriver'; $drivers[] = 'BasicValetDriver'; foreach ($drivers as $driver) { From 1e9e5ede4abef9770967490d892fc0a0f9ced289 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 3 Apr 2025 02:11:15 +0100 Subject: [PATCH 07/13] refactor: add `beforeLoading` hook to simplify the `frontControllerPath` method for some drivers - Add `beforeLoading` method. - Move most `$_SERVER` variables for many drivers into the new method. - Remove the now unused `$sitename` param from the `serverScript` method in `Typo3ValetDriver`. --- cli/Valet/Drivers/BasicValetDriver.php | 20 ++++++++--- cli/Valet/Drivers/LaravelValetDriver.php | 21 +++++++++--- .../Drivers/Specific/BedrockValetDriver.php | 19 ++++++++--- .../Drivers/Specific/CakeValetDriver.php | 21 +++++++++--- .../Drivers/Specific/JoomlaValetDriver.php | 14 ++++++-- .../Drivers/Specific/NeosValetDriver.php | 20 ++++++++--- .../Drivers/Specific/NetteValetDriver.php | 20 ++++++++--- .../Drivers/Specific/RadicleValetDriver.php | 13 ++++++- .../Drivers/Specific/Typo3ValetDriver.php | 34 ++++++++++++------- .../Drivers/Specific/WordPressValetDriver.php | 18 +++++++--- cli/Valet/Drivers/ValetDriver.php | 13 +++++++ server.php | 5 +++ 12 files changed, 172 insertions(+), 46 deletions(-) diff --git a/cli/Valet/Drivers/BasicValetDriver.php b/cli/Valet/Drivers/BasicValetDriver.php index 81914f164..bd7e887ff 100644 --- a/cli/Valet/Drivers/BasicValetDriver.php +++ b/cli/Valet/Drivers/BasicValetDriver.php @@ -16,6 +16,22 @@ public function serves($sitePath, $siteName, $uri) { return true; } + + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + $_SERVER['PHP_SELF'] = $uri; + $_SERVER['SERVER_ADDR'] = '127.0.0.1'; + $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; + } + /** * Determine if the incoming request is for a static file. * @@ -46,10 +62,6 @@ public function isStaticFile($sitePath, $siteName, $uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - $_SERVER['PHP_SELF'] = $uri; - $_SERVER['SERVER_ADDR'] = '127.0.0.1'; - $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; - $uri = rtrim($uri, '/'); $candidates = [ diff --git a/cli/Valet/Drivers/LaravelValetDriver.php b/cli/Valet/Drivers/LaravelValetDriver.php index 7dfd40b0e..2fc2a2066 100644 --- a/cli/Valet/Drivers/LaravelValetDriver.php +++ b/cli/Valet/Drivers/LaravelValetDriver.php @@ -16,6 +16,23 @@ public function serves($sitePath, $siteName, $uri) { return file_exists("$sitePath/public/index.php") && file_exists("$sitePath/artisan"); } + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + // Shortcut for getting the "local" hostname as the HTTP_HOST, especially when + // proxied or using 'share' + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { + $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; + } + } + /** * Determine if the incoming request is for a static file. * @@ -53,10 +70,6 @@ public function isStaticFile($sitePath, $siteName, $uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - // Shortcut for getting the "local" hostname as the HTTP_HOST - if (isset($_SERVER['HTTP_X_ORIGINAL_HOST'], $_SERVER['HTTP_X_FORWARDED_HOST'])) { - $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; - } return "$sitePath/public/index.php"; } diff --git a/cli/Valet/Drivers/Specific/BedrockValetDriver.php b/cli/Valet/Drivers/Specific/BedrockValetDriver.php index 40451f2b1..d19e45a25 100644 --- a/cli/Valet/Drivers/Specific/BedrockValetDriver.php +++ b/cli/Valet/Drivers/Specific/BedrockValetDriver.php @@ -18,6 +18,20 @@ public function serves($sitePath, $siteName, $uri) { return file_exists("$sitePath/web/app/mu-plugins/bedrock-autoloader.php") || (is_dir("$sitePath/web/app/") && file_exists("$sitePath/web/wp-config.php") && file_exists("$sitePath/config/application.php")); } + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + $_SERVER['PHP_SELF'] = $uri; + $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; + } + /** * Determine if the incoming request is for a static file. * @@ -47,9 +61,6 @@ public function isStaticFile($sitePath, $siteName, $uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - $_SERVER['PHP_SELF'] = $uri; - $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; - if (strpos($uri, '/wp/') === 0) { return is_dir("$sitePath/web$uri") ? "$sitePath/web" . $this->forceTrailingSlash($uri) . '/index.php' @@ -74,4 +85,4 @@ private function forceTrailingSlash($uri) { return $uri; } -} +} \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/CakeValetDriver.php b/cli/Valet/Drivers/Specific/CakeValetDriver.php index df2dfdeac..d2370bd38 100644 --- a/cli/Valet/Drivers/Specific/CakeValetDriver.php +++ b/cli/Valet/Drivers/Specific/CakeValetDriver.php @@ -18,6 +18,22 @@ public function serves($sitePath, $siteName, $uri) { return file_exists("{$sitePath}/bin/cake"); } + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + $_SERVER['DOCUMENT_ROOT'] = "{$sitePath}/webroot"; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/webroot/index.php"; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + $_SERVER['PHP_SELF'] = '/index.php'; + } + /** * Determine if the incoming request is for a static file. * @@ -45,11 +61,6 @@ public function isStaticFile($sitePath, $siteName, $uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - $_SERVER['DOCUMENT_ROOT'] = "{$sitePath}/webroot"; - $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/webroot/index.php"; - $_SERVER['SCRIPT_NAME'] = '/index.php'; - $_SERVER['PHP_SELF'] = '/index.php'; - return "{$sitePath}/webroot/index.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/JoomlaValetDriver.php b/cli/Valet/Drivers/Specific/JoomlaValetDriver.php index d064b9385..504ca26cf 100644 --- a/cli/Valet/Drivers/Specific/JoomlaValetDriver.php +++ b/cli/Valet/Drivers/Specific/JoomlaValetDriver.php @@ -18,6 +18,18 @@ public function serves($sitePath, $siteName, $uri) { return is_dir("{$sitePath}/libraries/joomla"); } + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + $_SERVER['PHP_SELF'] = $uri; + } + /** * Get the fully resolved path to the application's front controller. * @@ -28,8 +40,6 @@ public function serves($sitePath, $siteName, $uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - $_SERVER['PHP_SELF'] = $uri; - return parent::frontControllerPath($sitePath, $siteName, $uri); } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/NeosValetDriver.php b/cli/Valet/Drivers/Specific/NeosValetDriver.php index 6ab2f8a8e..ff8176e33 100644 --- a/cli/Valet/Drivers/Specific/NeosValetDriver.php +++ b/cli/Valet/Drivers/Specific/NeosValetDriver.php @@ -18,6 +18,21 @@ public function serves($sitePath, $siteName, $uri) { return file_exists("{$sitePath}/flow") && is_dir("{$sitePath}/Web"); } + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + putenv('FLOW_CONTEXT=Development'); + putenv('FLOW_REWRITEURLS=1'); + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/Web/index.php"; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + } + /** * Determine if the incoming request is for a static file. * @@ -45,11 +60,6 @@ public function isStaticFile($sitePath, $siteName, $uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - putenv('FLOW_CONTEXT=Development'); - putenv('FLOW_REWRITEURLS=1'); - $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/Web/index.php"; - $_SERVER['SCRIPT_NAME'] = '/index.php'; - return "{$sitePath}/Web/index.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/NetteValetDriver.php b/cli/Valet/Drivers/Specific/NetteValetDriver.php index 9d3f11a0f..68c770247 100644 --- a/cli/Valet/Drivers/Specific/NetteValetDriver.php +++ b/cli/Valet/Drivers/Specific/NetteValetDriver.php @@ -21,6 +21,21 @@ public function serves($sitePath, $siteName, $uri): bool { file_exists("{$sitePath}/config/services.neon"); } + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + $_SERVER['DOCUMENT_ROOT'] = "{$sitePath}/www"; + $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/www/index.php"; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + $_SERVER['PHP_SELF'] = '/index.php'; + } + /** * Determine if the incoming request is for a static file. * @@ -48,11 +63,6 @@ public function isStaticFile($sitePath, $siteName, $uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - $_SERVER['DOCUMENT_ROOT'] = "{$sitePath}/www"; - $_SERVER['SCRIPT_FILENAME'] = "{$sitePath}/www/index.php"; - $_SERVER['SCRIPT_NAME'] = '/index.php'; - $_SERVER['PHP_SELF'] = '/index.php'; - return "{$sitePath}/www/index.php"; } } \ No newline at end of file diff --git a/cli/Valet/Drivers/Specific/RadicleValetDriver.php b/cli/Valet/Drivers/Specific/RadicleValetDriver.php index 3bdf77aa5..554a32ad6 100644 --- a/cli/Valet/Drivers/Specific/RadicleValetDriver.php +++ b/cli/Valet/Drivers/Specific/RadicleValetDriver.php @@ -20,6 +20,18 @@ public function serves($sitePath, $siteName, $uri) { file_exists("{$sitePath}/bedrock/application.php"); } + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + $_SERVER['PHP_SELF'] = $uri; + } + /** * Determine if the incoming request is for a static file. * @@ -48,7 +60,6 @@ public function isStaticFile($sitePath, $siteName, $uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - $_SERVER['PHP_SELF'] = $uri; if (strpos($uri, '/wp/') === 0) { return is_dir("{$sitePath}/public{$uri}") ? "{$sitePath}/public" . $this->forceTrailingSlash($uri) . '/index.php' diff --git a/cli/Valet/Drivers/Specific/Typo3ValetDriver.php b/cli/Valet/Drivers/Specific/Typo3ValetDriver.php index 861660a84..de5b4c72e 100644 --- a/cli/Valet/Drivers/Specific/Typo3ValetDriver.php +++ b/cli/Valet/Drivers/Specific/Typo3ValetDriver.php @@ -56,6 +56,24 @@ public function serves($sitePath, $siteName, $uri) { return file_exists($typo3Dir) && is_dir($typo3Dir); } + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + // without modifying the URI, redirect if necessary + $this->handleRedirectBackendShorthandUris($uri); + + $_SERVER['SERVER_NAME'] = "{$siteName}.dev"; + $_SERVER['DOCUMENT_URI'] = $uri; + $_SERVER['SCRIPT_NAME'] = $uri; + $_SERVER['PHP_SELF'] = $uri; + } + /** * Determine if the incoming request is for a static file. That is, it is * no PHP script file and the URI points to a valid file (no folder) on @@ -115,9 +133,6 @@ private function isAccessAuthorized($uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - // without modifying the URI, redirect if necessary - $this->handleRedirectBackendShorthandUris($uri); - // from now on, remove trailing / for convenience for all the following join operations $uri = rtrim($uri, '/'); @@ -126,7 +141,7 @@ public function frontControllerPath($sitePath, $siteName, $uri) { if (is_dir($absoluteFilePath)) { if (file_exists("{$absoluteFilePath}/index.php")) { // this folder can be served by index.php - return $this->serveScript($sitePath, $siteName, "{$uri}/index.php"); + return $this->serveScript($sitePath, "{$uri}/index.php"); } if (file_exists("{$absoluteFilePath}/index.html")) { @@ -136,12 +151,12 @@ public function frontControllerPath($sitePath, $siteName, $uri) { } elseif (pathinfo($absoluteFilePath, PATHINFO_EXTENSION) === 'php') { // this file can be served directly - return $this->serveScript($sitePath, $siteName, $uri); + return $this->serveScript($sitePath, $uri); } } // the global index.php will handle all other cases - return $this->serveScript($sitePath, $siteName, '/index.php'); + return $this->serveScript($sitePath, '/index.php'); } /** @@ -170,21 +185,16 @@ private function handleRedirectBackendShorthandUris($uri) { * the specified URI and returns it absolute file path. * * @param string $sitePath - * @param string $siteName * @param string $uri * * @return string */ - private function serveScript($sitePath, $siteName, $uri) { + private function serveScript($sitePath, $uri) { $docroot = "{$sitePath}{$this->documentRoot}"; $abspath = "{$docroot}{$uri}"; - $_SERVER['SERVER_NAME'] = "{$siteName}.dev"; $_SERVER['DOCUMENT_ROOT'] = $docroot; - $_SERVER['DOCUMENT_URI'] = $uri; $_SERVER['SCRIPT_FILENAME'] = $abspath; - $_SERVER['SCRIPT_NAME'] = $uri; - $_SERVER['PHP_SELF'] = $uri; return $abspath; } diff --git a/cli/Valet/Drivers/Specific/WordPressValetDriver.php b/cli/Valet/Drivers/Specific/WordPressValetDriver.php index 79e0e6e1a..bd908e8ec 100644 --- a/cli/Valet/Drivers/Specific/WordPressValetDriver.php +++ b/cli/Valet/Drivers/Specific/WordPressValetDriver.php @@ -19,19 +19,29 @@ public function serves($sitePath, $siteName, $uri) { } /** - * Get the fully resolved path to the application's front controller. + * Take any steps necessary before loading the front controller for this driver. * * @param string $sitePath * @param string $siteName * @param string $uri - * - * @return string + * @return void */ - public function frontControllerPath($sitePath, $siteName, $uri) { + public function beforeLoading($sitePath, $siteName, $uri) { $_SERVER['PHP_SELF'] = $uri; $_SERVER['SERVER_ADDR'] = '127.0.0.1'; $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; + } + /** + * Get the fully resolved path to the application's front controller. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return string + */ + public function frontControllerPath($sitePath, $siteName, $uri) { return parent::frontControllerPath( $sitePath, $siteName, diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index 586fa9c10..70d275fff 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -138,6 +138,19 @@ public static function driversIn($path) { return $drivers; } + /** + * Take any steps necessary before loading the front controller for this driver. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * + * @return void + */ + public function beforeLoading($sitePath, $siteName, $uri) { + // Do nothing + } + /** * Mutate the incoming URI. * diff --git a/server.php b/server.php index 89ae2783e..850a7c897 100644 --- a/server.php +++ b/server.php @@ -73,6 +73,11 @@ return $valetDriver->serveStaticFile($staticFilePath, $valetSitePath, $siteName, $uri); } +/** + * Allow for drivers to take pre-loading actions (e.g. setting server variables). + */ +$valetDriver->beforeLoading($valetSitePath, $siteName, $uri); + /** * Attempt to dispatch to a front controller. */ From 1d1f760e2664f75b4242c63ea27edd6c3b2bbdd1 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 3 Apr 2025 02:18:14 +0100 Subject: [PATCH 08/13] feat: Add the ability for drivers to check Composer dependencies - Add new public `composerRequires` method to the base `ValetDriver` class. - Remove the private `composerRequiresSculpin` method from `SculpinValetDriver`, and update it's reference to use the new global `composerRequires` method. --- .../Drivers/Specific/SculpinValetDriver.php | 24 +------------------ cli/Valet/Drivers/ValetDriver.php | 23 ++++++++++++++++++ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/cli/Valet/Drivers/Specific/SculpinValetDriver.php b/cli/Valet/Drivers/Specific/SculpinValetDriver.php index 3973f546b..a294207de 100644 --- a/cli/Valet/Drivers/Specific/SculpinValetDriver.php +++ b/cli/Valet/Drivers/Specific/SculpinValetDriver.php @@ -26,7 +26,7 @@ public function serves($sitePath, $siteName, $uri) { * @return bool */ private function isModernSculpinProject($sitePath) { - return is_dir("{$sitePath}/source") && is_dir("{$sitePath}/output_dev") && $this->composerRequiresSculpin($sitePath); + return is_dir("{$sitePath}/source") && is_dir("{$sitePath}/output_dev") && $this->composerRequires($sitePath, 'sculpin/sculpin'); } /** @@ -40,28 +40,6 @@ private function isLegacySculpinProject($sitePath) { return is_dir("{$sitePath}/.sculpin"); } - /** - * Check if the composer.json file requires Sculpin. - * - * @param string $sitePath - * - * @return bool - */ - private function composerRequiresSculpin($sitePath) { - if (!file_exists("{$sitePath}/composer.json")) { - return false; - } - - $composer_json_source = file_get_contents("{$sitePath}/composer.json"); - $composer_json = json_decode($composer_json_source, true); - - if (json_last_error() !== JSON_ERROR_NONE) { - return false; - } - - return isset($composer_json['require']['sculpin/sculpin']); - } - /** * Mutate the incoming URI. * diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index 70d275fff..d448a5f5a 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -237,4 +237,27 @@ public function loadServerEnvironmentVariables($sitePath, $siteName) { putenv("$key=$value"); } } + + /** + * Check the site's Composer dependencies + * + * @param string $sitePath + * @param string $namespacedPackage + * + * @return bool + */ + public function composerRequires($sitePath, $namespacedPackage) { + if (! file_exists("$sitePath/composer.json")) { + return false; + } + + $composer_json_source = file_get_contents("$sitePath/composer.json"); + $composer_json = json_decode($composer_json_source, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + return false; + } + + return isset($composer_json['require'][$namespacedPackage]); + } } \ No newline at end of file From 9e15b3c0589367d2a57b881d8c34c33d44853d62 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 3 Apr 2025 02:41:10 +0100 Subject: [PATCH 09/13] refactor: the `assign`ing of drivers and allow the retrieval of drivers using the new namespaces. - Remove listing the specific drivers individually, which would be a maintenance nightmare for new drivers. - Add new `specificDrivers` method to bulk map the specific drivers into the array using the namespace. --- cli/Valet/Drivers/ValetDriver.php | 48 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index d448a5f5a..314dca130 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -55,38 +55,32 @@ abstract public function frontControllerPath($sitePath, $siteName, $uri); public static function assign($sitePath, $siteName, $uri) { $drivers = []; + // Get all specific drivers. + // Must scan these so they're extensible by customSiteDrivers loaded next. + $specificDrivers = static::specificDrivers(); + + // Queue custom driver based on path if ($customSiteDriver = static::customSiteDriver($sitePath)) { $drivers[] = $customSiteDriver; } $drivers = array_merge($drivers, static::driversIn(VALET_HOME_PATH . '/Drivers')); + // Queue Valet-shipped drivers + $drivers[] = 'Specific\StatamicValetDriver'; $drivers[] = 'LaravelValetDriver'; - - $drivers[] = 'WordPressValetDriver'; - $drivers[] = 'BedrockValetDriver'; - $drivers[] = 'ContaoValetDriver'; - $drivers[] = 'SymfonyValetDriver'; - $drivers[] = 'CraftValetDriver'; - $drivers[] = 'StatamicValetDriver'; - $drivers[] = 'StatamicV1ValetDriver'; - $drivers[] = 'CakeValetDriver'; - $drivers[] = 'SculpinValetDriver'; - $drivers[] = 'JigsawValetDriver'; - $drivers[] = 'KirbyValetDriver'; - $drivers[] = 'KatanaValetDriver'; - $drivers[] = 'JoomlaValetDriver'; - $drivers[] = 'DrupalValetDriver'; - $drivers[] = 'Concrete5ValetDriver'; - $drivers[] = 'Typo3ValetDriver'; - $drivers[] = 'NeosValetDriver'; - $drivers[] = 'Magento2ValetDriver'; - + $drivers = array_unique(array_merge($drivers, $specificDrivers)); $drivers[] = 'BasicWithPublicValetDriver'; $drivers[] = 'BasicValetDriver'; foreach ($drivers as $driver) { - $driver = new $driver(); + if ($driver === 'LocalValetDriver') { + $driver = new $driver(); + } + else { + $className = "Valet\Drivers\\{$driver}"; + $driver = new $className(); + } if ($driver->serves($sitePath, $siteName, $driver->mutateUri($uri))) { return $driver; @@ -138,6 +132,18 @@ public static function driversIn($path) { return $drivers; } + /** + * Get all of the specific drivers shipped with Valet. + * + * @return array + */ + public static function specificDrivers() { + return array_map(function ($item) { + return "Specific\\$item"; + }, static::driversIn(__DIR__ . '/Specific')); + } + + /** * Take any steps necessary before loading the front controller for this driver. * From eb9ee704ba8cec558545c61921a7b4d765ccb534 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 3 Apr 2025 02:42:49 +0100 Subject: [PATCH 10/13] feat: allow for global environment variables to be configured. This leverages the existing `.valet-env.php` file capability, but just adds the Valet Home directory as a first-lookup location. So, now Valet will check for `.valet-env.php` in: - `~/.config/valet/` - then the current project folder --- cli/Valet/Drivers/ValetDriver.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index 314dca130..c2ae9a09d 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -222,6 +222,10 @@ protected function isActualFile($path) { */ public function loadServerEnvironmentVariables($sitePath, $siteName) { $varFilePath = "$sitePath/.valet-env.php"; + + if (!file_exists($varFilePath)) { + $varFilePath = VALET_HOME_PATH . '/.valet-env.php'; + } if (!file_exists($varFilePath)) { return; } From 73822d08a29182159c46ade20e03861acd980add Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 3 Apr 2025 02:51:09 +0100 Subject: [PATCH 11/13] feat: add new namespace to the `SampleValetDriver` class as `Valet\Drivers\Custom` - Add namespace to the sample custom driver, and a `use` declaration to make sure the `ValetDriver` is available in this custom class. - Add new `customDrivers` method to bulk map the custom drivers from the `~.config/valet/Drivers` directory into the drivers array using the new namespace of `Valet\Drivers\Custom`. --- cli/Valet/Drivers/ValetDriver.php | 13 ++++++++++++- cli/stubs/SampleValetDriver.php | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index c2ae9a09d..f8fd399a2 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -64,7 +64,8 @@ public static function assign($sitePath, $siteName, $uri) { $drivers[] = $customSiteDriver; } - $drivers = array_merge($drivers, static::driversIn(VALET_HOME_PATH . '/Drivers')); + // Queue custom drivers for this environment + $drivers = array_merge($drivers, static::customDrivers()); // Queue Valet-shipped drivers $drivers[] = 'Specific\StatamicValetDriver'; @@ -143,6 +144,16 @@ public static function specificDrivers() { }, static::driversIn(__DIR__ . '/Specific')); } + /** + * Get all of the custom drivers defined by the user in `~/.config/valet/Drivers`. + * + * @return array + */ + public static function customDrivers() { + return array_map(function ($item) { + return "Custom\\$item"; + }, static::driversIn(VALET_HOME_PATH . '/Drivers')); + } /** * Take any steps necessary before loading the front controller for this driver. diff --git a/cli/stubs/SampleValetDriver.php b/cli/stubs/SampleValetDriver.php index 0a8102fc0..08ae0d1d1 100644 --- a/cli/stubs/SampleValetDriver.php +++ b/cli/stubs/SampleValetDriver.php @@ -1,5 +1,9 @@ Date: Thu, 3 Apr 2025 02:52:42 +0100 Subject: [PATCH 12/13] style: remove extra space in sample driver's docblock params, and... convert string concatenation to interpolation --- cli/stubs/SampleValetDriver.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cli/stubs/SampleValetDriver.php b/cli/stubs/SampleValetDriver.php index 08ae0d1d1..7051ee7da 100644 --- a/cli/stubs/SampleValetDriver.php +++ b/cli/stubs/SampleValetDriver.php @@ -8,13 +8,13 @@ class SampleValetDriver extends ValetDriver { /** * Determine if the driver serves the request. * - * @param string $sitePath - * @param string $siteName - * @param string $uri - * @return boolean + * @param string $sitePath + * @param string $siteName + * @param string $uri + * @return bool */ public function serves($sitePath, $siteName, $uri) { - // if (file_exists($sitePath.'/file-that-identifies-my-framework')) { + // if (file_exists("$sitePath/file-that-identifies-my-framework")) { // return true; // } @@ -24,13 +24,13 @@ public function serves($sitePath, $siteName, $uri) { /** * Determine if the incoming request is for a static file. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri * @return string|false */ public function isStaticFile($sitePath, $siteName, $uri) { - if (file_exists($staticFilePath = $sitePath.'/public/'.$uri)) { + if (file_exists($staticFilePath = "$sitePath/public/$uri")) { return $staticFilePath; } @@ -40,12 +40,12 @@ public function isStaticFile($sitePath, $siteName, $uri) { /** * Get the fully resolved path to the application's front controller. * - * @param string $sitePath - * @param string $siteName - * @param string $uri + * @param string $sitePath + * @param string $siteName + * @param string $uri * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { - return $sitePath.'/public/index.php'; + return "$sitePath/public/index.php"; } -} +} \ No newline at end of file From f978e9f8f48b18a9e6e7f3f950807911d62e6d28 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Thu, 3 Apr 2025 02:56:04 +0100 Subject: [PATCH 13/13] feat: 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. --- cli/Valet/Drivers/LaravelValetDriver.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/Valet/Drivers/LaravelValetDriver.php b/cli/Valet/Drivers/LaravelValetDriver.php index 2fc2a2066..4cbfdafe3 100644 --- a/cli/Valet/Drivers/LaravelValetDriver.php +++ b/cli/Valet/Drivers/LaravelValetDriver.php @@ -70,6 +70,9 @@ public function isStaticFile($sitePath, $siteName, $uri) { * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { + if (file_exists($staticFilePath = "$sitePath/public$uri") && $this->isActualFile($staticFilePath)) { + return $staticFilePath; + } return "$sitePath/public/index.php"; }