mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 16:50:09 +01:00
Merge branch 'version-4' of github.com:laravel/valet into version-4
This commit is contained in:
@@ -27,11 +27,7 @@ public function serves($sitePath, $siteName, $uri)
|
||||
*/
|
||||
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)) {
|
||||
return $staticFilePath;
|
||||
@@ -54,13 +50,16 @@ public function frontControllerPath($sitePath, $siteName, $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);
|
||||
@@ -69,90 +68,5 @@ public function frontControllerPath($sitePath, $siteName, $uri)
|
||||
return $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
$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';
|
||||
}
|
||||
}
|
||||
|
||||
75
cli/Valet/Drivers/BasicWithPublicValetDriver.php
Normal file
75
cli/Valet/Drivers/BasicWithPublicValetDriver.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class BasicWithPublicValetDriver extends ValetDriver
|
||||
{
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return bool
|
||||
*/
|
||||
public function serves($sitePath, $siteName, $uri)
|
||||
{
|
||||
return is_dir($sitePath.'/public/');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$publicPath = $sitePath.'/public/'.trim($uri, '/');
|
||||
|
||||
if ($this->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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,7 @@ public static function assign(string $sitePath, string $siteName, string $uri):
|
||||
$drivers[] = 'NeosValetDriver';
|
||||
$drivers[] = 'Magento2ValetDriver';
|
||||
|
||||
$drivers[] = 'BasicWithPublicValetDriver';
|
||||
$drivers[] = 'BasicValetDriver';
|
||||
|
||||
foreach ($drivers as $driver) {
|
||||
|
||||
Reference in New Issue
Block a user