Skip to content
Snippets Groups Projects
Unverified Commit fc37ffa5 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3198594 by catch, longwave, nikitagupta, alexpott, andypost: Forward...

Issue #3198594 by catch, longwave, nikitagupta, alexpott, andypost: Forward compatibility layer for InputBag
parent 2fccc04d
No related branches found
No related tags found
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!16Draft: Resolve #2081585 "History storage"
...@@ -528,7 +528,7 @@ ...@@ -528,7 +528,7 @@
"dist": { "dist": {
"type": "path", "type": "path",
"url": "core", "url": "core",
"reference": "02fb64caa7f852779c5ba9b94d7b48755612d45d" "reference": "365584bd91d9f305a9bf0db5a9acecf55c22ba57"
}, },
"require": { "require": {
"asm89/stack-cors": "^1.1", "asm89/stack-cors": "^1.1",
...@@ -751,6 +751,7 @@ ...@@ -751,6 +751,7 @@
"lib/Drupal/Core/DependencyInjection/Container.php", "lib/Drupal/Core/DependencyInjection/Container.php",
"lib/Drupal/Core/DrupalKernel.php", "lib/Drupal/Core/DrupalKernel.php",
"lib/Drupal/Core/DrupalKernelInterface.php", "lib/Drupal/Core/DrupalKernelInterface.php",
"lib/Drupal/Core/Http/InputBag.php",
"lib/Drupal/Core/Installer/InstallerRedirectTrait.php", "lib/Drupal/Core/Installer/InstallerRedirectTrait.php",
"lib/Drupal/Core/Site/Settings.php" "lib/Drupal/Core/Site/Settings.php"
], ],
...@@ -7811,12 +7812,12 @@ ...@@ -7811,12 +7812,12 @@
"version": "1.9.1", "version": "1.9.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/webmozart/assert.git", "url": "https://github.com/webmozarts/assert.git",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389",
"shasum": "" "shasum": ""
}, },
...@@ -7854,8 +7855,8 @@ ...@@ -7854,8 +7855,8 @@
"validate" "validate"
], ],
"support": { "support": {
"issues": "https://github.com/webmozart/assert/issues", "issues": "https://github.com/webmozarts/assert/issues",
"source": "https://github.com/webmozart/assert/tree/master" "source": "https://github.com/webmozarts/assert/tree/1.9.1"
}, },
"time": "2020-07-08T17:02:28+00:00" "time": "2020-07-08T17:02:28+00:00"
} }
......
...@@ -196,6 +196,7 @@ ...@@ -196,6 +196,7 @@
"lib/Drupal/Core/DependencyInjection/Container.php", "lib/Drupal/Core/DependencyInjection/Container.php",
"lib/Drupal/Core/DrupalKernel.php", "lib/Drupal/Core/DrupalKernel.php",
"lib/Drupal/Core/DrupalKernelInterface.php", "lib/Drupal/Core/DrupalKernelInterface.php",
"lib/Drupal/Core/Http/InputBag.php",
"lib/Drupal/Core/Installer/InstallerRedirectTrait.php", "lib/Drupal/Core/Installer/InstallerRedirectTrait.php",
"lib/Drupal/Core/Site/Settings.php" "lib/Drupal/Core/Site/Settings.php"
], ],
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
use Drupal\Core\DependencyInjection\YamlFileLoader; use Drupal\Core\DependencyInjection\YamlFileLoader;
use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\File\MimeType\MimeTypeGuesser; use Drupal\Core\File\MimeType\MimeTypeGuesser;
use Drupal\Core\Http\InputBag;
use Drupal\Core\Http\TrustedHostsRequestFactory; use Drupal\Core\Http\TrustedHostsRequestFactory;
use Drupal\Core\Installer\InstallerKernel; use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Installer\InstallerRedirectTrait; use Drupal\Core\Installer\InstallerRedirectTrait;
...@@ -33,6 +34,7 @@ ...@@ -33,6 +34,7 @@
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\TerminableInterface; use Symfony\Component\HttpKernel\TerminableInterface;
use Symfony\Component\HttpFoundation\InputBag as SymfonyInputBag;
use TYPO3\PharStreamWrapper\Manager as PharStreamWrapperManager; use TYPO3\PharStreamWrapper\Manager as PharStreamWrapperManager;
use TYPO3\PharStreamWrapper\Behavior as PharStreamWrapperBehavior; use TYPO3\PharStreamWrapper\Behavior as PharStreamWrapperBehavior;
use TYPO3\PharStreamWrapper\PharStreamWrapper; use TYPO3\PharStreamWrapper\PharStreamWrapper;
...@@ -692,6 +694,14 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = ...@@ -692,6 +694,14 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
// Ensure sane PHP environment variables. // Ensure sane PHP environment variables.
static::bootEnvironment(); 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 { try {
$this->initializeSettings($request); $this->initializeSettings($request);
......
<?php
namespace Drupal\Core\Http;
use Symfony\Component\HttpFoundation\ParameterBag;
/**
* Forward compatibility class for Symfony 5.
*
* @internal only used as a bridge from Symfony 4 to Symfony 5, will be removed
* in drupal:10.0.0.
*/
final class InputBag extends ParameterBag {
/**
* Returns the parameters.
*
* @param string|null $key
* The name of the parameter to return or null to get them all.
*
* @return array
* An array of parameters.
*/
public function all(string $key = NULL): array {
if ($key === NULL) {
return $this->parameters;
}
$value = $this->parameters[$key] ?? [];
if (!is_array($value)) {
throw new \UnexpectedValueException(sprintf('Unexpected value for parameter "%s": expecting "array", got "%s".', $key, get_debug_type($value)));
}
return $value;
}
}
<?php
namespace Drupal\Tests\Core\Http;
use Drupal\Core\Http\InputBag;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Core\Http\InputBag
*
* @group Http
*/
class InputBagTest extends UnitTestCase {
/**
* @covers ::all
*/
public function testAll() {
$input = [
'bad' => 'bad',
'good' => ['good'],
];
$input_bag = new InputBag();
$input_bag->replace($input);
$this->assertSame($input_bag->all(), $input);
$this->assertSame($input_bag->all('good'), ['good']);
$this->expectException(\UnexpectedValueException::class);
$input_bag->all('bad');
}
}
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