mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 00:40:06 +01:00
146 lines
3.7 KiB
PHP
146 lines
3.7 KiB
PHP
<?php
|
|
|
|
class BasicValetDriver extends ValetDriver
|
|
{
|
|
/**
|
|
* Determine if the driver serves the request.
|
|
*
|
|
* @param string $sitePath
|
|
* @param string $siteName
|
|
* @param string $uri
|
|
* @return void
|
|
*/
|
|
public function serves($sitePath, $siteName, $uri)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine if the incoming request is for a static file.
|
|
*
|
|
* @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)) {
|
|
return $staticFilePath;
|
|
} elseif (file_exists($staticFilePath = $sitePath.$uri) && ! is_dir($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)
|
|
{
|
|
$candidates = [
|
|
$this->asActualFile($sitePath, $uri),
|
|
$this->asPhpIndexFileInDirectory($sitePath, $uri),
|
|
$this->asHtmlIndexFileInDirectory($sitePath, $uri),
|
|
];
|
|
|
|
foreach ($candidates as $candidate) {
|
|
if ($this->isActualFile($candidate)) {
|
|
$_SERVER['SCRIPT_FILENAME'] = $candidate;
|
|
$_SERVER['SCRIPT_NAME'] = str_replace($sitePath, '', $candidate);
|
|
return $candidate;
|
|
}
|
|
}
|
|
|
|
$candidates = [
|
|
$this->asPublicPhpIndexFile($sitePath, $uri),
|
|
$this->asPublicHtmlIndexFile($sitePath, $uri),
|
|
];
|
|
|
|
foreach ($candidates as $candidate) {
|
|
if ($this->isActualFile($candidate)) {
|
|
$_SERVER['SCRIPT_FILENAME'] = $candidate;
|
|
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
|
return $candidate;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Determine if the path is a file and not a directory.
|
|
*
|
|
* @param string $path
|
|
* @return bool
|
|
*/
|
|
protected function isActualFile($path)
|
|
{
|
|
return file_exists($path) && ! is_dir($path);
|
|
}
|
|
|
|
/**
|
|
* 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 a "public/index.php" file path.
|
|
*
|
|
* @param string $sitePath
|
|
* @param string $uri
|
|
* @return string
|
|
*/
|
|
protected function asPublicPhpIndexFile($sitePath, $uri)
|
|
{
|
|
return $sitePath.'/public/index.php';
|
|
}
|
|
|
|
/**
|
|
* Format the incoming site path as a "public/index.php" file path.
|
|
*
|
|
* @param string $sitePath
|
|
* @param string $uri
|
|
* @return string
|
|
*/
|
|
protected function asPublicHtmlIndexFile($sitePath, $uri)
|
|
{
|
|
return $sitePath.'/public/index.html';
|
|
}
|
|
}
|