mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 08:30:07 +01:00
conslidate drivers into basic driver if possible
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class GenericPhpValetDriver extends ValetDriver
|
||||
class BasicValetDriver extends ValetDriver
|
||||
{
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
@@ -12,8 +12,7 @@ class GenericPhpValetDriver extends ValetDriver
|
||||
*/
|
||||
public function serves($sitePath, $siteName, $uri)
|
||||
{
|
||||
return file_exists($sitePath.'/public/index.php') ||
|
||||
file_exists($sitePath.'/index.php');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +46,8 @@ public function frontControllerPath($sitePath, $siteName, $uri)
|
||||
{
|
||||
$candidates = [
|
||||
$this->asActualFile($sitePath, $uri),
|
||||
$this->asIndexFileInDirectory($sitePath, $uri),
|
||||
$this->asPhpIndexFileInDirectory($sitePath, $uri),
|
||||
$this->asHtmlIndexFileInDirectory($sitePath, $uri),
|
||||
];
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
@@ -59,8 +59,8 @@ public function frontControllerPath($sitePath, $siteName, $uri)
|
||||
}
|
||||
|
||||
$candidates = [
|
||||
$this->asPublicIndexFile($sitePath, $uri),
|
||||
// ...and other possible public prefixes
|
||||
$this->asPublicPhpIndexFile($sitePath, $uri),
|
||||
$this->asPublicHtmlIndexFile($sitePath, $uri),
|
||||
];
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
@@ -72,23 +72,74 @@ public function frontControllerPath($sitePath, $siteName, $uri)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
protected function asIndexFileInDirectory($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';
|
||||
}
|
||||
|
||||
protected function asPublicIndexFile($sitePath, $uri)
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class JigsawValetDriver extends StaticValetDriver
|
||||
class JigsawValetDriver extends BasicValetDriver
|
||||
{
|
||||
/**
|
||||
* Mutate the incoming URI.
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
class StaticValetDriver 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 $this->isStaticFile($sitePath, $siteName, $uri) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$uri = rtrim($uri, '/');
|
||||
|
||||
if (file_exists($staticFilePath = $sitePath.$uri) && ! is_dir($staticFilePath)) {
|
||||
return $staticFilePath;
|
||||
} elseif (file_exists($staticFilePath = $sitePath.$uri.'/index.html')) {
|
||||
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)
|
||||
{
|
||||
return $sitePath.'/index.html';
|
||||
}
|
||||
}
|
||||
@@ -45,13 +45,13 @@ public static function assign($sitePath, $siteName, $uri)
|
||||
$drivers = static::driversIn(VALET_HOME_PATH.'/Drivers');
|
||||
|
||||
$drivers[] = 'LaravelValetDriver';
|
||||
$drivers[] = 'SymfonyValetDriver';
|
||||
$drivers[] = 'WordPressValetDriver';
|
||||
|
||||
$drivers[] = 'CraftValetDriver';
|
||||
$drivers[] = 'StatamicValetDriver';
|
||||
$drivers[] = 'JigsawValetDriver';
|
||||
$drivers[] = 'GenericPhpValetDriver';
|
||||
$drivers[] = 'StaticValetDriver';
|
||||
$drivers[] = 'StatamicValetDriver';
|
||||
$drivers[] = 'SymfonyValetDriver';
|
||||
|
||||
$drivers[] = 'BasicValetDriver';
|
||||
|
||||
foreach ($drivers as $driver) {
|
||||
$driver = new $driver;
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
class WordPressValetDriver 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 is_dir($sitePath.'/wp-admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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($sitePath.$uri) &&
|
||||
! is_dir($sitePath.$uri)) {
|
||||
return $sitePath.$uri;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$uri = rtrim($uri, '/');
|
||||
|
||||
if ($uri == '/') {
|
||||
return $sitePath.'/index.php';
|
||||
}
|
||||
|
||||
if (file_exists($sitePath.$uri) && ! is_dir($sitePath.$uri)) {
|
||||
return $sitePath.$uri;
|
||||
} elseif (file_exists($frontControllerPath = $sitePath.$uri.'/index.php')) {
|
||||
return $frontControllerPath;
|
||||
} else {
|
||||
return $sitePath.'/index.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Basic drivers...
|
||||
*/
|
||||
require_once __DIR__.'/ValetDriver.php';
|
||||
require_once __DIR__.'/StatamicValetDriver.php';
|
||||
require_once __DIR__.'/LaravelValetDriver.php';
|
||||
require_once __DIR__.'/StaticValetDriver.php';
|
||||
require_once __DIR__.'/JigsawValetDriver.php';
|
||||
require_once __DIR__.'/WordPressValetDriver.php';
|
||||
require_once __DIR__.'/BasicValetDriver.php';
|
||||
|
||||
/**
|
||||
* Specific drivers...
|
||||
*/
|
||||
require_once __DIR__.'/CraftValetDriver.php';
|
||||
require_once __DIR__.'/JigsawValetDriver.php';
|
||||
require_once __DIR__.'/LaravelValetDriver.php';
|
||||
require_once __DIR__.'/StatamicValetDriver.php';
|
||||
require_once __DIR__.'/SymfonyValetDriver.php';
|
||||
require_once __DIR__.'/GenericPhpValetDriver.php';
|
||||
|
||||
Reference in New Issue
Block a user