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

Drupal 7 & 8 Driver (#48)

* Add support for Drupal

* Implement more logic to handle Drupal 6, Drupal 7 and Drupal 8

* Additional fixes for Drupal 8 install. Removed note about Drupal 6 since it doesn't work properly beyond PHP 5.3.

* Rewrite front controller check for Drupal 8
This commit is contained in:
Tristan Payne
2016-07-26 14:09:15 -05:00
committed by Taylor Otwell
parent 60dc951513
commit 58e3c07fe3
3 changed files with 75 additions and 0 deletions

View File

@@ -59,6 +59,7 @@ public static function assign($sitePath, $siteName, $uri)
$drivers[] = 'ContaoValetDriver'; $drivers[] = 'ContaoValetDriver';
$drivers[] = 'KatanaValetDriver'; $drivers[] = 'KatanaValetDriver';
$drivers[] = 'JoomlaValetDriver'; $drivers[] = 'JoomlaValetDriver';
$drivers[] = 'DrupalValetDriver';
$drivers[] = 'BasicValetDriver'; $drivers[] = 'BasicValetDriver';

View File

@@ -23,3 +23,4 @@
require_once __DIR__.'/KatanaValetDriver.php'; require_once __DIR__.'/KatanaValetDriver.php';
require_once __DIR__.'/CakeValetDriver.php'; require_once __DIR__.'/CakeValetDriver.php';
require_once __DIR__.'/JoomlaValetDriver.php'; require_once __DIR__.'/JoomlaValetDriver.php';
require_once __DIR__.'/DrupalValetDriver.php';

View File

@@ -0,0 +1,73 @@
<?php
class DrupalValetDriver 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)
{
/**
* /misc/drupal.js = Drupal 7
* /core/lib/Drupal.php = Drupal 8
*/
if (file_exists($sitePath.'/misc/drupal.js') ||
file_exists($sitePath.'/core/lib/Drupal.php')) {
return true;
}
}
/**
* 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) &&
pathinfo($sitePath.$uri)['extension'] != 'php') {
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)
{
if (!empty($uri) && $uri !== '/') {
$_GET['q'] = $uri;
}
$matches = [];
if (preg_match('/^\/(.*?)\.php/', $uri, $matches)) {
$filename = $matches[0];
if (file_exists($sitePath.$filename) && ! is_dir($sitePath.$filename)) {
$_SERVER['SCRIPT_FILENAME'] = $sitePath.$filename;
$_SERVER['SCRIPT_NAME'] = $filename;
return $sitePath.$filename;
}
}
// Fallback
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/index.php';
$_SERVER['SCRIPT_NAME'] = '/index.php';
return $sitePath.'/index.php';
}
}