Skip to content
Snippets Groups Projects
Commit 022284b1 authored by catch's avatar catch
Browse files

Issue #3162016 by longwave, andypost, Hardik_Patel_12, catch, alexpott,...

Issue #3162016 by longwave, andypost, Hardik_Patel_12, catch, alexpott, daffie, Chi, Kristen Pol: [Symfony 6] Retrieving a non-string value from "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated
parent 66ba9753
No related branches found
No related tags found
17 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!1101Issue #2412669 by claudiu.cristea, Julfabre, sidharrell, catch, daffie,...,!1039Issue #2556069 by claudiu.cristea, bnjmnm, lauriii, pfrenssen, Tim Bozeman,...,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!1012Issue #3226887: Hreflang on non-canonical content pages,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!594Put each entity type table into a details element on admin/config/regional/content-language,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -6,11 +6,14 @@
*/
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Http\InputBag;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Test\TestDatabase;
use Drupal\Core\Utility\Error;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\InputBag as SymfonyInputBag;
/**
* Minimum allowed version of PHP for Drupal to be bootstrapped.
......@@ -130,6 +133,23 @@
// alias once Drupal is running Symfony 5.3 or higher.
class_alias('Drupal\Core\Http\KernelEvent', 'Symfony\Component\HttpKernel\Event\KernelEvent', TRUE);
/**
* Set up the Symfony Request factory for forward compatibility with Symfony 5.
*
* @todo Remove this when Symfony 4 is no longer supported.
*/
Request::setFactory(
function ($query, $request, $attributes, $cookies, $files, $server, $content) {
$request = new Request($query, $request, $attributes, $cookies, $files, $server, $content);
foreach (['request', 'query', 'cookies'] as $bag) {
if (!($bag instanceof SymfonyInputBag)) {
$request->$bag = new InputBag($request->$bag->all());
}
}
return $request;
}
);
/**
* Returns and optionally sets the filename for a system resource.
*
......
......@@ -17,7 +17,6 @@
use Drupal\Core\DependencyInjection\YamlFileLoader;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\File\MimeType\MimeTypeGuesser;
use Drupal\Core\Http\InputBag;
use Drupal\Core\Http\TrustedHostsRequestFactory;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Installer\InstallerRedirectTrait;
......@@ -34,7 +33,6 @@
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\TerminableInterface;
use Symfony\Component\HttpFoundation\InputBag as SymfonyInputBag;
use TYPO3\PharStreamWrapper\Manager as PharStreamWrapperManager;
use TYPO3\PharStreamWrapper\Behavior as PharStreamWrapperBehavior;
use TYPO3\PharStreamWrapper\PharStreamWrapper;
......@@ -695,14 +693,6 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
// Ensure sane PHP environment variables.
static::bootEnvironment();
// Replace ParameterBag with InputBag for compatibility with Symfony 5.
// @todo Remove this when Symfony 4 is no longer supported.
foreach (['request', 'query', 'cookies'] as $bag) {
if (!($bag instanceof SymfonyInputBag)) {
$request->$bag = new InputBag($request->$bag->all());
}
}
try {
$this->initializeSettings($request);
......
......@@ -2,6 +2,7 @@
namespace Drupal\Core\Http;
use Symfony\Component\HttpFoundation\InputBag as SymfonyInputBag;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -61,7 +62,17 @@ public function createRequest(array $query = [], array $request = [], array $att
if (empty($server['HTTP_HOST']) || ($server['HTTP_HOST'] === 'localhost' && $this->host !== 'localhost')) {
$server['HTTP_HOST'] = $this->host;
}
return new Request($query, $request, $attributes, $cookies, $files, $server, $content);
$request = new Request($query, $request, $attributes, $cookies, $files, $server, $content);
// Replace ParameterBag with InputBag for compatibility with Symfony 5.
// @todo Remove this when Symfony 4 is no longer supported.
foreach (['request', 'query', 'cookies'] as $bag) {
if (!($bag instanceof SymfonyInputBag)) {
$request->$bag = new InputBag($request->$bag->all());
}
}
return $request;
}
}
......@@ -17,4 +17,12 @@ public function fakeRequestHost() {
return ['#markup' => 'Host: ' . $request->getHost()];
}
/**
* Creates a fake request and prints out the class name of the specified bag.
*/
public function bagType($bag) {
$request = Request::create('/');
return ['#markup' => 'Type: ' . get_class($request->$bag)];
}
}
......@@ -4,3 +4,10 @@ trusted_hosts_test.fake_request:
_controller: '\Drupal\trusted_hosts_test\Controller\TrustedHostsTestController::fakeRequestHost'
requirements:
_access: 'TRUE'
trusted_hosts_test.bag_type:
path: '/trusted-hosts-test/bag-type/{bag}'
defaults:
_controller: '\Drupal\trusted_hosts_test\Controller\TrustedHostsTestController::bagType'
requirements:
_access: 'TRUE'
......@@ -111,4 +111,28 @@ public function testShortcut() {
$this->assertSession()->linkExists($shortcut->label());
}
/**
* Tests that the request bags have the correct classes.
*
* @todo Remove this when Symfony 4 is no longer supported.
*
* @see \Drupal\Core\Http\TrustedHostsRequestFactory
*/
public function testRequestBags() {
$this->container->get('module_installer')->install(['trusted_hosts_test']);
$host = $this->container->get('request_stack')->getCurrentRequest()->getHost();
$settings['settings']['trusted_host_patterns'] = (object) [
'value' => ['^' . preg_quote($host) . '$'],
'required' => TRUE,
];
$this->writeSettings($settings);
foreach (['request', 'query', 'cookies'] as $bag) {
$this->drupalGet('trusted-hosts-test/bag-type/' . $bag);
$this->assertSession()->pageTextContains('InputBag');
}
}
}
......@@ -4,6 +4,7 @@
use Drupal\Core\Http\InputBag;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
/**
* @coversDefaultClass \Drupal\Core\Http\InputBag
......@@ -28,4 +29,13 @@ public function testAll() {
$input_bag->all('bad');
}
/**
* @coversNothing
* @todo Remove this when Symfony 4 is no longer supported.
*/
public function testRequestFactory() {
$request = Request::create('');
$this->assertInstanceOf(InputBag::class, $request->query);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment