mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 08:40:09 +01:00
66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Valet\Drivers;
|
|
|
|
class BasicValetDriver extends ValetDriver
|
|
{
|
|
/**
|
|
* Determine if the driver serves the request.
|
|
*/
|
|
public function serves(string $sitePath, string $siteName, string $uri): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Take any steps necessary before loading the front controller for this driver.
|
|
*/
|
|
public function beforeLoading(string $sitePath, string $siteName, string $uri): void
|
|
{
|
|
$_SERVER['PHP_SELF'] = $uri;
|
|
$_SERVER['SERVER_ADDR'] = $_SERVER['SERVER_ADDR'] ?? '127.0.0.1';
|
|
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
|
|
}
|
|
|
|
/**
|
|
* Determine if the incoming request is for a static file.
|
|
*/
|
|
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
|
|
{
|
|
if (file_exists($staticFilePath = $sitePath.rtrim($uri, '/').'/index.html')) {
|
|
return $staticFilePath;
|
|
} elseif ($this->isActualFile($staticFilePath = $sitePath.$uri)) {
|
|
return $staticFilePath;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get the fully resolved path to the application's front controller.
|
|
*/
|
|
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
|
|
{
|
|
$uri = rtrim($uri, '/');
|
|
|
|
$candidates = [
|
|
$sitePath.$uri,
|
|
$sitePath.$uri.'/index.php',
|
|
$sitePath.'/index.php',
|
|
$sitePath.'/index.html',
|
|
];
|
|
|
|
foreach ($candidates as $candidate) {
|
|
if ($this->isActualFile($candidate)) {
|
|
$_SERVER['SCRIPT_FILENAME'] = $candidate;
|
|
$_SERVER['SCRIPT_NAME'] = str_replace($sitePath, '', $candidate);
|
|
$_SERVER['DOCUMENT_ROOT'] = $sitePath;
|
|
|
|
return $candidate;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|