diff --git a/composer.lock b/composer.lock index dc13a581370aa75d4a49d529454bf130737be031..1d46b257095997657a45eb4a8875b138e564037b 100644 --- a/composer.lock +++ b/composer.lock @@ -528,7 +528,7 @@ "dist": { "type": "path", "url": "core", - "reference": "02fb64caa7f852779c5ba9b94d7b48755612d45d" + "reference": "365584bd91d9f305a9bf0db5a9acecf55c22ba57" }, "require": { "asm89/stack-cors": "^1.1", @@ -751,6 +751,7 @@ "lib/Drupal/Core/DependencyInjection/Container.php", "lib/Drupal/Core/DrupalKernel.php", "lib/Drupal/Core/DrupalKernelInterface.php", + "lib/Drupal/Core/Http/InputBag.php", "lib/Drupal/Core/Installer/InstallerRedirectTrait.php", "lib/Drupal/Core/Site/Settings.php" ], @@ -7811,12 +7812,12 @@ "version": "1.9.1", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", + "url": "https://github.com/webmozarts/assert.git", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "shasum": "" }, @@ -7854,8 +7855,8 @@ "validate" ], "support": { - "issues": "https://github.com/webmozart/assert/issues", - "source": "https://github.com/webmozart/assert/tree/master" + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.9.1" }, "time": "2020-07-08T17:02:28+00:00" } diff --git a/core/composer.json b/core/composer.json index 79019a8cf65dbc7e097dbbc8822a8b26a9559099..1b185cbe0f287ec8463356ceee15e0cf03219f0b 100644 --- a/core/composer.json +++ b/core/composer.json @@ -196,6 +196,7 @@ "lib/Drupal/Core/DependencyInjection/Container.php", "lib/Drupal/Core/DrupalKernel.php", "lib/Drupal/Core/DrupalKernelInterface.php", + "lib/Drupal/Core/Http/InputBag.php", "lib/Drupal/Core/Installer/InstallerRedirectTrait.php", "lib/Drupal/Core/Site/Settings.php" ], diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index ee3b56e7bc391e4a787831a207fb60bab65bd522..599e13833ad94296ae9e9ea3f5dbdb96c2a1aeac 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -17,6 +17,7 @@ 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; @@ -33,6 +34,7 @@ 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; @@ -692,6 +694,14 @@ 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); diff --git a/core/lib/Drupal/Core/Http/InputBag.php b/core/lib/Drupal/Core/Http/InputBag.php new file mode 100644 index 0000000000000000000000000000000000000000..b4409cced4f016551dd9438d06765cf146f90af9 --- /dev/null +++ b/core/lib/Drupal/Core/Http/InputBag.php @@ -0,0 +1,37 @@ +<?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; + } + +} diff --git a/core/tests/Drupal/Tests/Core/Http/InputBagTest.php b/core/tests/Drupal/Tests/Core/Http/InputBagTest.php new file mode 100644 index 0000000000000000000000000000000000000000..43b24db1298cf139b5283394ad2901a6f67fd453 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Http/InputBagTest.php @@ -0,0 +1,31 @@ +<?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'); + } + +}