diff --git a/core/lib/Drupal/Core/Bootstrap/Bootstrap.php b/core/lib/Drupal/Core/Bootstrap/Bootstrap.php index 1d7138b..0994084 100644 --- a/core/lib/Drupal/Core/Bootstrap/Bootstrap.php +++ b/core/lib/Drupal/Core/Bootstrap/Bootstrap.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Bootstrap; use Drupal\Component\Utility\Bytes; +use Symfony\Component\HttpFoundation\Request; /** * Provides helper methods for bootstrapping Drupal. @@ -67,12 +68,16 @@ public static function checkMemoryLimit($required, $memory_limit = NULL) { * the command line script should pass in the desired value via the * 'REMOTE_ADDR' key. * - * @param array $variables - * (optional) An associative array of variables within $_SERVER that should - * be replaced. If the special element 'url' is provided in this array, it - * will be used to populate some of the server defaults; it should be set to - * the URL of the current page request, excluding any $_GET request but - * including the script name (e.g., http://www.example.com/mysite/index.php). + * @param \Symfony\Component\HttpFoundation\Request $request + * A request object. + * + * @param $variables + * (optional) An associative array of variables within + * \Drupal::request()->server that should be replaced. If the special element + * 'url' is provided in this array, it will be used to populate some of the + * server defaults; it should be set to the URL of the current page request, + * excluding any GET request but including the script name + * (e.g., http://www.example.com/mysite/index.php). * * @see conf_path() * @see request_uri() @@ -80,8 +85,7 @@ public static function checkMemoryLimit($required, $memory_limit = NULL) { * * @todo Replace use of `$_REQUEST` with a Symfony request object. */ - public static function overrideServerVariables($variables = array()) { - $request = \Drupal::request(); + public static function overrideServerVariables(Request $request, $variables = array()) { $server_vars = $request->server->all(); // Allow the provided URL to override any existing values in $_SERVER. if (isset($variables['url'])) { diff --git a/core/tests/Drupal/Tests/Core/Bootstrap/BootstrapTest.php b/core/tests/Drupal/Tests/Core/Bootstrap/BootstrapTest.php index 439308c..af9bac8 100644 --- a/core/tests/Drupal/Tests/Core/Bootstrap/BootstrapTest.php +++ b/core/tests/Drupal/Tests/Core/Bootstrap/BootstrapTest.php @@ -9,7 +9,6 @@ use Drupal\Core\Bootstrap\Bootstrap; use Drupal\Core\Controller\ControllerResolver; -use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; @@ -43,18 +42,15 @@ public static function getInfo() { * @dataProvider providerTestOverrideServerVariables */ public function testOverrideServerVariables($overrides, $expected_server_values) { - // Create request and container. + // Create request. $request = new Request(); - $container = new ContainerBuilder(); - $container->set('request', $request); - \Drupal::setContainer($container); // Remember the original value of $_SERVER, since the function call below // will modify it. $original_server = $_SERVER; // Call drupal_override_server_variables() and ensure that all expected // $_SERVER variables were modified correctly. - Bootstrap::overrideServerVariables($overrides); + Bootstrap::overrideServerVariables($request, $overrides); foreach ($expected_server_values as $key => $value) { $this->assertSame($_SERVER[$key], $value); }