Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ function runserver_env($key) {
return getenv($key);
}
}

// Note that we are simply prepended to the PHP request, we fall through to the
// default PHP handling.
44 changes: 44 additions & 0 deletions commands/runserver/rs-router_7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

// We hijack filter_init (which core filter module does not implement) as
// a convenient place to affect early changes.
if (!function_exists('filter_init')) {
// Check function_exists as a safety net in case it is added in future.
function filter_init() {
global $conf, $user;
// Inject values into the $conf array - will apply to all sites.
// This can be a useful place to apply generic development settings.
$conf_inject = unserialize(urldecode(runserver_env('RUNSERVER_CONF')));
// Merge in the injected conf, overriding existing items.
$conf = array_merge($conf, $conf_inject);
}
}

// We hijack system_watchdog (which core system module does not implement) as
// a convenient place to capture logs.
if (!function_exists('system_watchdog')) {
// Check function_exists as a safety net in case it is added in future.
function system_watchdog($log_entry = array()) {
// Drupal <= 7.x defines VERSION. Drupal 8 defines Drupal::VERSION instead.
if (defined('VERSION')) {
$uid = $log_entry['user']->uid;
}
else {
$uid = $log_entry['user']->id();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like D8 code in a D7 file.

}
$message = strtr('Watchdog: !message | severity: !severity | type: !type | uid: !uid | !ip | !request_uri | !referer | !link', array(
'!message' => strip_tags(!isset($log_entry['variables']) ? $log_entry['message'] : strtr($log_entry['message'], $log_entry['variables'])),
'!severity' => $log_entry['severity'],
'!type' => $log_entry['type'],
'!ip' => $log_entry['ip'],
'!request_uri' => $log_entry['request_uri'],
'!referer' => $log_entry['referer'],
'!uid' => $uid,
'!link' => strip_tags($log_entry['link']),
));
error_log($message);
}
}

// Pass through to the default runserver router.
include __DIR__ . '/rs-router.php';
10 changes: 7 additions & 3 deletions commands/runserver/runserver.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ function drush_core_runserver($uri = NULL) {
drush_start_browser($browse, 2);
}
// Start the server using 'php -S'.
if (drush_drupal_major_version() >=8) {
$extra = ' "' . __DIR__ . '/d8-rs-router.php"';
if (drush_drupal_major_version() >= 8) {
$extra = ' "' . __DIR__ . '/rs-router.php"';
}
elseif (drush_drupal_major_version() == 7) {
$extra = ' "' . __DIR__ . '/rs-router_7.php"';
}
else {
$extra = ' --define auto_prepend_file="' . __DIR__ . '/runserver-prepend.php"';
// For Drupal 6 we prepend an include to what PHP was going invoke.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The master branch of Drush no longer supports Drupal 6. I dont mind removing this bit at merge time if that makes things simple.

$extra = ' --define auto_prepend_file="' . __DIR__ . '/rs-router_6.php"';
}
$root = \Drush::bootstrapManager()->getRoot();
drush_shell_exec_interactive('cd %s && %s -S ' . $addr . ':' . $uri['port']. $extra, $root, drush_get_option('php', 'php'));
Expand Down