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
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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.
 *
+0 −10
Original line number Diff line number Diff line
@@ -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);

+12 −1
Original line number Diff line number Diff line
@@ -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;
  }

}
+8 −0
Original line number Diff line number Diff line
@@ -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)];
  }

}
+7 −0
Original line number Diff line number Diff line
@@ -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'
Loading