summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-09-05 00:33:07 (GMT)
committer Alex Pott2013-09-05 00:33:07 (GMT)
commitc1c38a9b086c3ce61e228546c57dde2b05c58f6d (patch)
tree6db016d4373733d5fab27d6d3a43ce905bc76687
parent49c215957e45334aea8a95ebf60f350815043b6d (diff)
Issue #1998696 by kim.pepper, kmcculloch, valdo: Use Symfony Request for core includes.
-rw-r--r--core/includes/common.inc4
-rw-r--r--core/includes/errors.inc2
-rw-r--r--core/includes/pager.inc7
-rw-r--r--core/includes/tablesort.inc10
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php42
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Database/SelectPagerDefaultTest.php9
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php29
7 files changed, 68 insertions, 35 deletions
diff --git a/core/includes/common.inc b/core/includes/common.inc
index d6886f2..86745a2 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -4093,7 +4093,7 @@ function show(&$element) {
* @see drupal_render_cache_set()
*/
function drupal_render_cache_get($elements) {
- if (!in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD')) || !$cid = drupal_render_cid_create($elements)) {
+ if (!Drupal::request()->isMethodSafe() || !$cid = drupal_render_cid_create($elements)) {
return FALSE;
}
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
@@ -4125,7 +4125,7 @@ function drupal_render_cache_get($elements) {
*/
function drupal_render_cache_set(&$markup, $elements) {
// Create the cache ID for the element.
- if (!in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD')) || !$cid = drupal_render_cid_create($elements)) {
+ if (!Drupal::request()->isMethodSafe() || !$cid = drupal_render_cid_create($elements)) {
return FALSE;
}
diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index 3fe23b7..86ef93f 100644
--- a/core/includes/errors.inc
+++ b/core/includes/errors.inc
@@ -222,7 +222,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
}
}
- if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
+ if (Drupal::request()->isXmlHttpRequest()) {
if ($fatal) {
if (error_displayable($error)) {
// When called from JavaScript, simply output the error message.
diff --git a/core/includes/pager.inc b/core/includes/pager.inc
index cef12ac..4654012 100644
--- a/core/includes/pager.inc
+++ b/core/includes/pager.inc
@@ -6,6 +6,7 @@
*/
use Drupal\Core\Template\Attribute;
+use Drupal\Component\Utility\Url;
/**
* Returns the current page being requested for display within a pager.
@@ -26,7 +27,7 @@ use Drupal\Core\Template\Attribute;
* @see pager_default_initialize()
*/
function pager_find_page($element = 0) {
- $page = isset($_GET['page']) ? $_GET['page'] : '';
+ $page = Drupal::request()->query->get('page', '');
$page_array = explode(',', $page);
if (!isset($page_array[$element])) {
$page_array[$element] = 0;
@@ -136,7 +137,7 @@ function pager_default_initialize($total, $limit, $element = 0) {
function pager_get_query_parameters() {
$query = &drupal_static(__FUNCTION__);
if (!isset($query)) {
- $query = drupal_get_query_parameters($_GET, array('page'));
+ $query = Url::filterQueryParameters(Drupal::request()->query->all(), array('page'));
}
return $query;
}
@@ -425,7 +426,7 @@ function pager_query_add_page(array $query, $element, $index) {
// Determine the first result to display on the linked page.
$page_new = pager_load_array($index, $element, $pager_page_array);
- $page = isset($_GET['page']) ? $_GET['page'] : '';
+ $page = Drupal::request()->query->get('page', '');
if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
$query['page'] = $new_page;
}
diff --git a/core/includes/tablesort.inc b/core/includes/tablesort.inc
index c42b1f4..14da51c 100644
--- a/core/includes/tablesort.inc
+++ b/core/includes/tablesort.inc
@@ -3,6 +3,7 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\SelectExtender;
use Drupal\Core\Database\Query\SelectInterface;
+use Drupal\Component\Utility\Url;
/**
* @file
@@ -100,7 +101,7 @@ function tablesort_cell($cell, $header, $ts, $i) {
* page request except for those pertaining to table sorting.
*/
function tablesort_get_query_parameters() {
- return drupal_get_query_parameters($_GET, array('sort', 'order'));
+ return Url::filterQueryParameters(Drupal::request()->query->all(), array('sort', 'order'));
}
/**
@@ -115,7 +116,7 @@ function tablesort_get_query_parameters() {
* - "sql": The name of the database field to sort on.
*/
function tablesort_get_order($headers) {
- $order = isset($_GET['order']) ? $_GET['order'] : '';
+ $order = Drupal::request()->query->get('order', '');
foreach ($headers as $header) {
if (is_array($header)) {
if (isset($header['data']) && $order == $header['data']) {
@@ -150,8 +151,9 @@ function tablesort_get_order($headers) {
* The current sort direction ("asc" or "desc").
*/
function tablesort_get_sort($headers) {
- if (isset($_GET['sort'])) {
- return (strtolower($_GET['sort']) == 'desc') ? 'desc' : 'asc';
+ $query = Drupal::request()->query;
+ if ($query->has('sort')) {
+ return (strtolower($query->get('sort')) == 'desc') ? 'desc' : 'asc';
}
// The user has not specified a sort. Use the default for the currently sorted
// header if specified; otherwise use "asc".
diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php
index c7cc2a9..241949f 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php
@@ -8,6 +8,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\simpletest\UnitTestBase;
+use Symfony\Component\HttpFoundation\Request;
/**
* Tests unicode handling features implemented in unicode.inc.
@@ -53,38 +54,42 @@ class TableSortExtenderUnitTest extends UnitTestBase {
$headers = array('foo', 'bar', 'baz');
// Reset $_GET to prevent parameters from Simpletest and Batch API ending
// up in $ts['query'].
- $_GET = array();
$expected_ts = array(
'name' => 'foo',
'sql' => '',
'sort' => 'asc',
'query' => array(),
);
+ $request = Request::createFromGlobals();
+ $request->query->replace(array());
+ \Drupal::getContainer()->set('request', $request);
$ts = tablesort_init($headers);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, 'Simple table headers sorted correctly.');
// Test with simple table headers plus $_GET parameters that should _not_
// override the default.
-
- $_GET = array(
+ $request = Request::createFromGlobals();
+ $request->query->replace(array(
// This should not override the table order because only complex
// headers are overridable.
'order' => 'bar',
- );
+ ));
+ \Drupal::getContainer()->set('request', $request);
$ts = tablesort_init($headers);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, 'Simple table headers plus non-overriding $_GET parameters sorted correctly.');
// Test with simple table headers plus $_GET parameters that _should_
// override the default.
-
- $_GET = array(
+ $request = Request::createFromGlobals();
+ $request->query->replace(array(
'sort' => 'DESC',
// Add an unrelated parameter to ensure that tablesort will include
// it in the links that it creates.
'alpha' => 'beta',
- );
+ ));
+ \Drupal::getContainer()->set('request', $request);
$expected_ts['sort'] = 'desc';
$expected_ts['query'] = array('alpha' => 'beta');
$ts = tablesort_init($headers);
@@ -108,9 +113,11 @@ class TableSortExtenderUnitTest extends UnitTestBase {
),
);
// Reset $_GET from previous assertion.
- $_GET = array(
+ $request = Request::createFromGlobals();
+ $request->query->replace(array(
'order' => '2',
- );
+ ));
+ \Drupal::getContainer()->set('request', $request);
$ts = tablesort_init($headers);
$expected_ts = array(
'name' => '2',
@@ -123,12 +130,13 @@ class TableSortExtenderUnitTest extends UnitTestBase {
// Test complex table headers plus $_GET parameters that should _not_
// override the default.
-
- $_GET = array(
+ $request = Request::createFromGlobals();
+ $request->query->replace(array(
// This should not override the table order because this header does not
// exist.
'order' => 'bar',
- );
+ ));
+ \Drupal::getContainer()->set('request', $request);
$ts = tablesort_init($headers);
$expected_ts = array(
'name' => '1',
@@ -138,18 +146,18 @@ class TableSortExtenderUnitTest extends UnitTestBase {
);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, 'Complex table headers plus non-overriding $_GET parameters sorted correctly.');
- unset($_GET['sort'], $_GET['order'], $_GET['alpha']);
// Test complex table headers plus $_GET parameters that _should_
// override the default.
-
- $_GET = array(
+ $request = Request::createFromGlobals();
+ $request->query->replace(array(
'order' => '1',
'sort' => 'ASC',
// Add an unrelated parameter to ensure that tablesort will include
// it in the links that it creates.
'alpha' => 'beta',
- );
+ ));
+ \Drupal::getContainer()->set('request', $request);
$expected_ts = array(
'name' => '1',
'sql' => 'one',
@@ -159,7 +167,5 @@ class TableSortExtenderUnitTest extends UnitTestBase {
$ts = tablesort_init($headers);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, 'Complex table headers plus $_GET parameters sorted correctly.');
- unset($_GET['sort'], $_GET['order'], $_GET['alpha']);
-
}
}
diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/SelectPagerDefaultTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/SelectPagerDefaultTest.php
index 83f0640..79c93d2 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Database/SelectPagerDefaultTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Database/SelectPagerDefaultTest.php
@@ -6,6 +6,7 @@
*/
namespace Drupal\system\Tests\Database;
+use Symfony\Component\HttpFoundation\Request;
/**
* Tests the pager query select extender.
@@ -135,7 +136,12 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
* Confirms that every pager gets a valid, non-overlaping element ID.
*/
function testElementNumbers() {
- $_GET['page'] = '3, 2, 1, 0';
+
+ $request = Request::createFromGlobals();
+ $request->query->replace(array(
+ 'page' => '3, 2, 1, 0',
+ ));
+ \Drupal::getContainer()->set('request', $request);
$name = db_select('test', 't')
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
@@ -168,6 +174,5 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
->fetchField();
$this->assertEqual($name, 'John', 'Pager query #3 with a generated element ID returned the correct results.');
- unset($_GET['page']);
}
}
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
index e1b0ea7..091a824 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
@@ -8,6 +8,7 @@
namespace Drupal\system\Tests\Entity;
use Drupal\Core\Language\Language;
+use Symfony\Component\HttpFoundation\Request;
/**
* Tests the basic Entity API.
@@ -349,7 +350,11 @@ class EntityQueryTest extends EntityUnitTestBase {
// Test the pager by setting element #1 to page 2 with a page size of 4.
// Results will be #8-12 from above.
- $_GET['page'] = '0,2';
+ $request = Request::createFromGlobals();
+ $request->query->replace(array(
+ 'page' => '0,2',
+ ));
+ \Drupal::getContainer()->set('request', $request);
$this->queryResults = $this->factory->get('entity_test_mulrev')
->sort("$figures.color")
->sort("$greetings.format")
@@ -376,8 +381,13 @@ class EntityQueryTest extends EntityUnitTestBase {
// While ordering on bundles do not give us a definite order, we can still
// assert that all entities from one bundle are after the other as the
// order dictates.
- $_GET['sort'] = 'asc';
- $_GET['order'] = 'Type';
+ $request = Request::createFromGlobals();
+ $request->query->replace(array(
+ 'sort' => 'asc',
+ 'order' => 'Type',
+ ));
+ \Drupal::getContainer()->set('request', $request);
+
$header = array(
'id' => array('data' => 'Id', 'specifier' => 'id'),
'type' => array('data' => 'Type', 'specifier' => 'type'),
@@ -387,7 +397,12 @@ class EntityQueryTest extends EntityUnitTestBase {
->tableSort($header)
->execute());
$this->assertBundleOrder('asc');
- $_GET['sort'] = 'desc';
+
+ $request->query->add(array(
+ 'sort' => 'desc',
+ ));
+ \Drupal::getContainer()->set('request', $request);
+
$header = array(
'id' => array('data' => 'Id', 'specifier' => 'id'),
'type' => array('data' => 'Type', 'specifier' => 'type'),
@@ -396,8 +411,12 @@ class EntityQueryTest extends EntityUnitTestBase {
->tableSort($header)
->execute());
$this->assertBundleOrder('desc');
+
// Ordering on ID is definite, however.
- $_GET['order'] = 'Id';
+ $request->query->add(array(
+ 'order' => 'Id',
+ ));
+ \Drupal::getContainer()->set('request', $request);
$this->queryResults = $this->factory->get('entity_test_mulrev')
->tableSort($header)
->execute();