1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-07 09:10:03 +01:00

Update drivers location and loading

- Extract much of server.php into a `Server` class
- Move all but the Laravel and Basic drivers into a subfolder
- Load all but the Laravel and Basic drivers via glob
- Add `beforeLoading` hook to simplify the `frontControllerPath` method for some drivers
This commit is contained in:
Matt Stauffer
2022-12-18 15:08:17 -06:00
parent 29b94a48a6
commit efa7937038
68 changed files with 534 additions and 496 deletions

View File

@@ -0,0 +1,67 @@
<?php
namespace Valet\Drivers\Specific;
use Valet\Drivers\BasicValetDriver;
class WordPressValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return file_exists($sitePath.'/wp-config.php') || file_exists($sitePath.'/wp-config-sample.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(string $sitePath, string $siteName, string $uri): void
{
$_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(string $sitePath, string $siteName, string $uri): string
{
return parent::frontControllerPath(
$sitePath, $siteName, $this->forceTrailingSlash($uri)
);
}
/**
* Redirect to uri with trailing slash.
*
* @param string $uri
* @return string
*/
private function forceTrailingSlash($uri)
{
if (substr($uri, -1 * strlen('/wp-admin')) == '/wp-admin') {
header('Location: '.$uri.'/');
exit;
}
return $uri;
}
}