mirror of
https://github.com/laravel/valet.git
synced 2026-02-04 16:10:08 +01:00
When PHP files other than index.php exist in /public/ this allows them to be served by the Laravel driver. I discussed this previously at: https://github.com/laravel/valet/discussions/1430#discussioncomment-6536474 ... but I think it's safe to include in the core LaravelValetDriver by default.
63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Valet\Drivers;
|
|
|
|
class LaravelValetDriver extends ValetDriver
|
|
{
|
|
/**
|
|
* Determine if the driver serves the request.
|
|
*/
|
|
public function serves(string $sitePath, string $siteName, string $uri): bool
|
|
{
|
|
return file_exists($sitePath.'/public/index.php') &&
|
|
file_exists($sitePath.'/artisan');
|
|
}
|
|
|
|
/**
|
|
* Take any steps necessary before loading the front controller for this driver.
|
|
*/
|
|
public function beforeLoading(string $sitePath, string $siteName, string $uri): void
|
|
{
|
|
// 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.
|
|
*/
|
|
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
|
|
{
|
|
if (file_exists($staticFilePath = $sitePath.'/public'.$uri)
|
|
&& is_file($staticFilePath)) {
|
|
return $staticFilePath;
|
|
}
|
|
|
|
$storageUri = $uri;
|
|
|
|
if (strpos($uri, '/storage/') === 0) {
|
|
$storageUri = substr($uri, 8);
|
|
}
|
|
|
|
if ($this->isActualFile($storagePath = $sitePath.'/storage/app/public'.$storageUri)) {
|
|
return $storagePath;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get the fully resolved path to the application's front controller.
|
|
*/
|
|
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
|
|
{
|
|
if (file_exists($staticFilePath = $sitePath.'/public'.$uri)
|
|
&& $this->isActualFile($staticFilePath)) {
|
|
return $staticFilePath;
|
|
}
|
|
|
|
return $sitePath.'/public/index.php';
|
|
}
|
|
}
|