diff --git a/cli/drivers/DrupalValetDriver.php b/cli/drivers/DrupalValetDriver.php index c25952e..978639f 100644 --- a/cli/drivers/DrupalValetDriver.php +++ b/cli/drivers/DrupalValetDriver.php @@ -12,6 +12,8 @@ class DrupalValetDriver extends ValetDriver */ public function serves($sitePath, $siteName, $uri) { + $sitePath = $this->addSubdirectory($sitePath); + /** * /misc/drupal.js = Drupal 7 * /core/lib/Drupal.php = Drupal 8 @@ -32,6 +34,8 @@ public function serves($sitePath, $siteName, $uri) */ public function isStaticFile($sitePath, $siteName, $uri) { + $sitePath = $this->addSubdirectory($sitePath); + if (file_exists($sitePath.$uri) && ! is_dir($sitePath.$uri) && pathinfo($sitePath.$uri)['extension'] != 'php') { @@ -51,6 +55,8 @@ public function isStaticFile($sitePath, $siteName, $uri) */ public function frontControllerPath($sitePath, $siteName, $uri) { + $sitePath = $this->addSubdirectory($sitePath); + if (!isset($_GET['q']) && !empty($uri) && $uri !== '/') { $_GET['q'] = $uri; } @@ -70,4 +76,36 @@ public function frontControllerPath($sitePath, $siteName, $uri) $_SERVER['SCRIPT_NAME'] = '/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']; + } }