1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-08 01:10:08 +01:00

Allow for serving Drupal from within a sub-directory

This commit is contained in:
Oliver Davies
2018-10-14 16:44:30 +01:00
parent 10c5239ddc
commit b0f0f063c4

View File

@@ -12,6 +12,8 @@ class DrupalValetDriver extends ValetDriver
*/ */
public function serves($sitePath, $siteName, $uri) public function serves($sitePath, $siteName, $uri)
{ {
$sitePath = $this->addSubdirectory($sitePath);
/** /**
* /misc/drupal.js = Drupal 7 * /misc/drupal.js = Drupal 7
* /core/lib/Drupal.php = Drupal 8 * /core/lib/Drupal.php = Drupal 8
@@ -32,6 +34,8 @@ public function serves($sitePath, $siteName, $uri)
*/ */
public function isStaticFile($sitePath, $siteName, $uri) public function isStaticFile($sitePath, $siteName, $uri)
{ {
$sitePath = $this->addSubdirectory($sitePath);
if (file_exists($sitePath.$uri) && if (file_exists($sitePath.$uri) &&
! is_dir($sitePath.$uri) && ! is_dir($sitePath.$uri) &&
pathinfo($sitePath.$uri)['extension'] != 'php') { pathinfo($sitePath.$uri)['extension'] != 'php') {
@@ -51,6 +55,8 @@ public function isStaticFile($sitePath, $siteName, $uri)
*/ */
public function frontControllerPath($sitePath, $siteName, $uri) public function frontControllerPath($sitePath, $siteName, $uri)
{ {
$sitePath = $this->addSubdirectory($sitePath);
if (!isset($_GET['q']) && !empty($uri) && $uri !== '/') { if (!isset($_GET['q']) && !empty($uri) && $uri !== '/') {
$_GET['q'] = $uri; $_GET['q'] = $uri;
} }
@@ -70,4 +76,36 @@ public function frontControllerPath($sitePath, $siteName, $uri)
$_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['SCRIPT_NAME'] = '/index.php';
return $sitePath.'/index.php'; return $sitePath.'/index.php';
} }
/**
* Add any matching subdirectory to the site path.
*/
public function addSubdirectory($sitePath)
{
$paths = array_map(function ($subDir) use ($sitePath) {
return "$sitePath/$subDir";
}, $this->possibleSubdirectories());
$foundPaths = array_filter($paths, function ($path) {
return file_exists($path);
});
// If paths are found, return the first one.
if (!empty($foundPaths)) {
return array_shift($foundPaths);
}
// If there are no matches, return the original path.
return $sitePath;
}
/**
* Return an array of possible subdirectories.
*
* @return array
*/
private function possibleSubdirectories()
{
return ['docroot', 'public', 'web'];
}
} }