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

Merge pull request #653 from opdavies/drupal-subdirs

Failing functional tests with Drupal in a sub-directory
This commit is contained in:
Matt Stauffer
2018-10-25 15:54:26 -04:00
committed by GitHub

View File

@@ -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'];
}
}