From 02a32e3ff52064252c39affb1a3f2323cf1b53b4 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Mon, 14 Jul 2014 15:58:53 +0100 Subject: [PATCH] Issue #2284103 by alexpott, fabpot, damiankloip, Xano, Xen, Berdir: Fixed Remove the request from the container. --- core/core.services.yml | 17 +- core/includes/common.inc | 2 +- core/includes/install.core.inc | 4 +- core/includes/path.inc | 4 +- core/lib/Drupal.php | 4 +- core/lib/Drupal/Core/Access/AccessManager.php | 27 +- .../AuthenticationProviderInterface.php | 2 +- core/lib/Drupal/Core/CoreServiceProvider.php | 5 - .../DependencyInjection/ContainerBuilder.php | 11 +- core/lib/Drupal/Core/DrupalKernel.php | 51 +--- core/lib/Drupal/Core/Form/FormBase.php | 24 +- core/lib/Drupal/Core/Form/FormBuilder.php | 4 +- core/lib/Drupal/Core/HttpKernel.php | 263 ------------------ .../Drupal/Core/Installer/InstallerKernel.php | 8 - core/lib/Drupal/Core/Logger/LoggerChannel.php | 28 +- .../Core/Logger/LoggerChannelFactory.php | 15 +- .../Core/Logger/LoggerChannelInterface.php | 8 +- core/lib/Drupal/Core/Routing/UrlGenerator.php | 22 +- .../Core/Routing/UrlGeneratorInterface.php | 9 - core/lib/Drupal/Core/Session/AccountProxy.php | 14 +- .../block/src/Tests/BlockViewBuilderTest.php | 21 +- .../src/Plugin/Block/BookNavigationBlock.php | 20 +- .../tests/src/Entity/CommentLockTest.php | 6 +- .../Tests/ContentTranslationSyncImageTest.php | 2 +- .../src/Tests/FilterHtmlImageSecureTest.php | 2 +- core/modules/language/language.services.yml | 2 +- .../src/ConfigurableLanguageManager.php | 17 +- .../ConfigurableLanguageManagerInterface.php | 8 - .../LanguageRequestSubscriber.php | 3 +- .../src/HttpKernel/PathProcessorLanguage.php | 2 +- .../language/src/LanguageNegotiator.php | 23 +- .../src/LanguageNegotiatorInterface.php | 9 - .../language/src/LanguageServiceProvider.php | 3 +- .../LanguageUILanguageNegotiationTest.php | 9 +- .../rest/tests/src/CollectRoutesTest.php | 1 - .../simpletest/src/InstallerTestBase.php | 5 +- .../modules/simpletest/src/KernelTestBase.php | 3 +- core/modules/simpletest/src/TestBase.php | 1 + core/modules/simpletest/src/WebTestBase.php | 4 +- .../src/Plugin/Block/SystemHelpBlock.php | 2 +- .../Common/TableSortExtenderUnitTest.php | 12 +- .../Tests/Database/SelectPagerDefaultTest.php | 2 +- .../DrupalKernel/ServiceDestructionTest.php | 4 +- .../src/Tests/Entity/EntityQueryTest.php | 8 +- .../Tests/Entity/EntityViewBuilderTest.php | 14 +- .../src/Tests/File/UrlRewritingTest.php | 2 +- .../src/Tests/Session/SessionHttpsTest.php | 2 +- .../system/src/Tests/Theme/RegistryTest.php | 1 - core/modules/system/system.module | 2 +- core/modules/user/src/Form/UserLoginForm.php | 4 +- .../src/Form/UserMultipleCancelConfirm.php | 2 +- core/modules/views/src/Form/ViewsForm.php | 20 +- .../src/Tests/Plugin/DisplayPageTest.php | 2 +- core/modules/views/src/Tests/ViewTestBase.php | 1 - core/modules/views/views.theme.inc | 2 +- core/modules/views_ui/src/Tests/TagTest.php | 2 +- core/modules/views_ui/src/ViewEditForm.php | 20 +- .../Tests/Core/Access/AccessManagerTest.php | 28 +- .../ContainerBuilderTest.php | 3 + core/tests/Drupal/Tests/Core/DrupalTest.php | 8 - .../Drupal/Tests/Core/Form/FormTestBase.php | 4 +- .../Drupal/Tests/Core/HttpKernelTest.php | 60 ---- .../Tests/Core/Logger/LoggerChannelTest.php | 12 +- .../Tests/Core/Routing/UrlGeneratorTest.php | 10 +- .../Core/Session/AnonymousUserSessionTest.php | 12 +- 65 files changed, 245 insertions(+), 657 deletions(-) delete mode 100644 core/lib/Drupal/Core/HttpKernel.php delete mode 100644 core/tests/Drupal/Tests/Core/HttpKernelTest.php diff --git a/core/core.services.yml b/core/core.services.yml index 0bb13d0f5788..ac4f816c9f8e 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -279,10 +279,6 @@ services: parent: default_plugin_manager plugin.cache_clearer: class: Drupal\Core\Plugin\CachedDiscoveryClearer - request: - class: Symfony\Component\HttpFoundation\Request - synthetic: true - synchronized: true request_stack: class: Symfony\Component\HttpFoundation\RequestStack tags: @@ -304,9 +300,8 @@ services: class: Drupal\Core\Controller\TitleResolver arguments: ['@controller_resolver', '@string_translation'] http_kernel: - class: Drupal\Core\HttpKernel + class: Symfony\Component\HttpKernel\HttpKernel arguments: ['@event_dispatcher', '@controller_resolver', '@request_stack'] - parent: container.trait language_manager: class: Drupal\Core\Language\LanguageManager arguments: ['@language.default'] @@ -371,9 +366,8 @@ services: - { name: service_collector, tag: route_filter, call: addRouteFilter } url_generator: class: Drupal\Core\Routing\UrlGenerator - arguments: ['@router.route_provider', '@path_processor_manager', '@route_processor_manager', '@config.factory', '@settings', '@logger.channel.default'] + arguments: ['@router.route_provider', '@path_processor_manager', '@route_processor_manager', '@config.factory', '@settings', '@logger.channel.default', '@request_stack'] calls: - - [setRequest, ['@?request']] - [setContext, ['@?router.request_context']] link_generator: class: Drupal\Core\Utility\LinkGenerator @@ -566,10 +560,9 @@ services: class: Drupal\Core\Access\AccessArgumentsResolver access_manager: class: Drupal\Core\Access\AccessManager - arguments: ['@router.route_provider', '@url_generator', '@paramconverter_manager', '@access_arguments_resolver'] + arguments: ['@router.route_provider', '@url_generator', '@paramconverter_manager', '@access_arguments_resolver', '@request_stack'] calls: - [setContainer, ['@service_container']] - - [setRequest, ['@?request']] access_subscriber: class: Drupal\Core\EventSubscriber\AccessSubscriber arguments: ['@access_manager', '@current_user'] @@ -627,13 +620,11 @@ services: tags: - { name: event_subscriber } arguments: ['@language_manager', '@config.factory'] - scope: request redirect_response_subscriber: class: Drupal\Core\EventSubscriber\RedirectResponseSubscriber arguments: ['@url_generator'] tags: - { name: event_subscriber } - scope: request request_close_subscriber: class: Drupal\Core\EventSubscriber\RequestCloseSubscriber tags: @@ -804,7 +795,7 @@ services: arguments: ['@authentication'] current_user: class: Drupal\Core\Session\AccountProxy - arguments: ['@authentication', '@request'] + arguments: ['@authentication', '@request_stack'] session_manager: class: Drupal\Core\Session\SessionManager arguments: ['@request_stack', '@database', '@session_manager.metadata_bag', '@settings'] diff --git a/core/includes/common.inc b/core/includes/common.inc index 379685840db5..1c301f428c88 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1731,7 +1731,7 @@ function _drupal_add_js($data = NULL, $options = NULL) { // @todo Make this less hacky: http://drupal.org/node/1547376. $scriptPath = $GLOBALS['script_path']; $pathPrefix = ''; - $current_query = \Drupal::service('request')->query->all(); + $current_query = \Drupal::service('request_stack')->getCurrentRequest()->query->all(); url('', array('script' => &$scriptPath, 'prefix' => &$pathPrefix)); $current_path = current_path(); $current_path_is_admin = FALSE; diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 10b92f54c26f..4774a54fe2e7 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -355,10 +355,12 @@ function install_begin_request(&$install_state) { $environment = 'prod'; } - $kernel = InstallerKernel::createFromRequest($request, drupal_classloader(), $environment); + // Only allow dumping the container once the hash salt has been created. + $kernel = InstallerKernel::createFromRequest($request, drupal_classloader(), $environment, (bool) Settings::get('hash_salt', FALSE)); $kernel->setSitePath($site_path); $kernel->boot(); $container = $kernel->getContainer(); + $container->get('request_stack')->push($request); // Register the file translation service. if (isset($GLOBALS['config']['locale.settings']['translation.path'])) { diff --git a/core/includes/path.inc b/core/includes/path.inc index a050217be407..b2298d0dbe2f 100644 --- a/core/includes/path.inc +++ b/core/includes/path.inc @@ -60,8 +60,8 @@ function current_path() { // @todo Remove the check for whether the request service exists and the // fallback code below, once the path alias logic has been figured out in // http://drupal.org/node/1269742. - if (\Drupal::getContainer()->isScopeActive('request')) { - $path = \Drupal::request()->attributes->get('_system_path'); + if ($request = \Drupal::request()) { + $path = $request->attributes->get('_system_path'); if ($path !== NULL) { return $path; } diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 6409fd38c0b9..21443e5b570e 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -158,7 +158,7 @@ public static function hasService($id) { * TRUE if there is a currently active request object, FALSE otherwise. */ public static function hasRequest() { - return static::$container && static::$container->has('request') && static::$container->initialized('request') && static::$container->isScopeActive('request'); + return static::$container && static::$container->has('request_stack') && static::$container->get('request_stack')->getCurrentRequest() !== NULL; } /** @@ -184,7 +184,7 @@ public static function hasRequest() { * The currently active request object. */ public static function request() { - return static::$container->get('request'); + return static::$container->get('request_stack')->getCurrentRequest(); } /** diff --git a/core/lib/Drupal/Core/Access/AccessManager.php b/core/lib/Drupal/Core/Access/AccessManager.php index b40905f0beaa..21185c1b8ada 100644 --- a/core/lib/Drupal/Core/Access/AccessManager.php +++ b/core/lib/Drupal/Core/Access/AccessManager.php @@ -18,6 +18,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Cmf\Component\Routing\RouteObjectInterface; @@ -94,11 +95,11 @@ class AccessManager implements ContainerAwareInterface { protected $argumentsResolver; /** - * A request object. + * A request stack object. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * Constructs a AccessManager instance. @@ -111,25 +112,15 @@ class AccessManager implements ContainerAwareInterface { * The param converter manager. * @param \Drupal\Core\Access\AccessArgumentsResolverInterface $arguments_resolver * The access arguments resolver. + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + * The request stack object. */ - public function __construct(RouteProviderInterface $route_provider, UrlGeneratorInterface $url_generator, ParamConverterManagerInterface $paramconverter_manager, AccessArgumentsResolverInterface $arguments_resolver) { + public function __construct(RouteProviderInterface $route_provider, UrlGeneratorInterface $url_generator, ParamConverterManagerInterface $paramconverter_manager, AccessArgumentsResolverInterface $arguments_resolver, RequestStack $requestStack) { $this->routeProvider = $route_provider; $this->urlGenerator = $url_generator; $this->paramConverterManager = $paramconverter_manager; $this->argumentsResolver = $arguments_resolver; - } - - /** - * Sets the request object to use. - * - * This is used by the RouterListener to make additional request attributes - * available. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - */ - public function setRequest(Request $request) { - $this->request = $request; + $this->requestStack = $requestStack; } /** @@ -222,7 +213,7 @@ public function checkNamedRoute($route_name, array $parameters = array(), Accoun if (empty($route_request)) { // Create a request and copy the account from the current request. $defaults = $parameters + $route->getDefaults(); - $route_request = RequestHelper::duplicate($this->request, $this->urlGenerator->generate($route_name, $defaults)); + $route_request = RequestHelper::duplicate($this->requestStack->getCurrentRequest(), $this->urlGenerator->generate($route_name, $defaults)); $defaults[RouteObjectInterface::ROUTE_OBJECT] = $route; $route_request->attributes->add($this->paramConverterManager->convert($defaults, $route_request)); } diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationProviderInterface.php b/core/lib/Drupal/Core/Authentication/AuthenticationProviderInterface.php index 374de78b9de5..bc8e10c11ad0 100644 --- a/core/lib/Drupal/Core/Authentication/AuthenticationProviderInterface.php +++ b/core/lib/Drupal/Core/Authentication/AuthenticationProviderInterface.php @@ -29,7 +29,7 @@ public function applies(Request $request); /** * Authenticates the user. * - * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Symfony\Component\HttpFoundation\Request|null $request * The request object. * * @return \Drupal\Core\Session\AccountInterface|null diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php index c72cafc1af66..02a5625d63d1 100644 --- a/core/lib/Drupal/Core/CoreServiceProvider.php +++ b/core/lib/Drupal/Core/CoreServiceProvider.php @@ -22,7 +22,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Scope; use Symfony\Component\DependencyInjection\Compiler\PassConfig; /** @@ -41,10 +40,6 @@ class CoreServiceProvider implements ServiceProviderInterface { * {@inheritdoc} */ public function register(ContainerBuilder $container) { - // The 'request' scope and service enable services to depend on the Request - // object and get reconstructed when the request object changes (e.g., - // during a subrequest). - $container->addScope(new Scope('request')); $this->registerTwig($container); $this->registerUuid($container); $this->registerTest($container); diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php index 56f1627ed59c..58cbe3cc859a 100644 --- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php +++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php @@ -10,6 +10,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder; use Symfony\Component\DependencyInjection\Container as SymfonyContainer; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; /** * Drupal's dependency injection container builder. @@ -19,13 +20,11 @@ class ContainerBuilder extends SymfonyContainerBuilder { /** - * Overrides Symfony\Component\DependencyInjection\ContainerBuilder::addObjectResource(). - * - * Drupal does not use Symfony's Config component, so we override - * addObjectResource() with an empty implementation to prevent errors during - * container compilation. + * {@inheritdoc} */ - public function addObjectResource($object) { + public function __construct(ParameterBagInterface $parameterBag = NULL) { + $this->setResourceTracking(FALSE); + parent::__construct($parameterBag); } /** diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 0f2d1c58532e..e54cf895163c 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -425,23 +425,12 @@ protected function preHandle(Request $request) { // Initialize cookie globals. $this->initializeCookieGlobals($request); - // Ensure container has a request scope so we can load file stream wrappers. - if (!$this->container->isScopeActive('request')) { - // Enter the request scope so that current_user service is available for - // locale/translation sake. - $this->container->enterScope('request'); - $this->container->set('request', $request, 'request'); - $this->container->get('request_stack')->push($request); - } + // Put the request on the stack. + $this->container->get('request_stack')->push($request); // Make sure all stream wrappers are registered. file_get_stream_wrappers(); - // Back out scope required to initialize the file stream wrappers. - if ($this->container->isScopeActive('request')) { - $this->container->leaveScope('request'); - } - // Set the allowed protocols once we have the config available. $allowed_protocols = $this->container->get('config.factory')->get('system.filter')->get('protocols'); if (!isset($allowed_protocols)) { @@ -582,8 +571,6 @@ public function prepareLegacyRequest(Request $request) { $this->preHandle($request); // Enter the request scope so that current_user service is available for // locale/translation sake. - $this->container->enterScope('request'); - $this->container->set('request', $request); $this->container->get('request_stack')->push($request); $this->container->get('router.request_context')->fromRequest($request); return $this; @@ -680,21 +667,8 @@ protected function getKernelParameters() { */ protected function initializeContainer($rebuild = FALSE) { $this->containerNeedsDumping = FALSE; - // The request service requires custom persisting logic, since it is also - // potentially scoped. - $request_scope = FALSE; - $request_stack = $request = NULL; $session_manager_state = 0; if (isset($this->container)) { - if ($this->container->isScopeActive('request')) { - $request_scope = TRUE; - } - if ($this->container->initialized('request')) { - $request = $this->container->get('request'); - } - if ($this->container->initialized('request_stack')) { - $request_stack = $this->container->get('request_stack'); - } // If there is a session manager, close and save the session. if ($this->container->initialized('session_manager')) { $session_manager = $this->container->get('session_manager'); @@ -730,7 +704,7 @@ protected function initializeContainer($rebuild = FALSE) { $container = $this->compileContainer(); } - $this->attachSynthetic($container, $request, $request_stack, $request_scope); + $this->attachSynthetic($container); $this->container = $container; if ($session_manager_state & 0x1) { @@ -996,15 +970,10 @@ public function rebuildContainer() { * * @param ContainerInterface $container * Container object - * @param Request $request - * Request object. - * @param RequestStack $request_stack - * Request stack. - * @param null $request_scope + * * @return ContainerInterface */ - protected function attachSynthetic(ContainerInterface $container, Request $request = NULL, RequestStack $request_stack = NULL, $request_scope = NULL) { - + protected function attachSynthetic(ContainerInterface $container) { $persist = array(); if (isset($this->container)) { $persist = $this->getServicesToPersist($this->container); @@ -1019,16 +988,6 @@ protected function attachSynthetic(ContainerInterface $container, Request $reque // Set the class loader which was registered as a synthetic service. $container->set('class_loader', $this->classLoader); - // If we have a request set it back to the new container. - if ($request_scope) { - $container->enterScope('request'); - } - if (isset($request)) { - $container->set('request', $request); - } - if (isset($request_stack)) { - $container->set('request_stack', $request_stack); - } return $container; } diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php index 751ad9f6a3d8..8848d3f9cd0e 100644 --- a/core/lib/Drupal/Core/Form/FormBase.php +++ b/core/lib/Drupal/Core/Form/FormBase.php @@ -14,7 +14,7 @@ use Drupal\Core\Routing\UrlGeneratorTrait; use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Provides a base class for forms. @@ -26,11 +26,11 @@ abstract class FormBase implements FormInterface, ContainerInjectionInterface { use UrlGeneratorTrait; /** - * The current request. + * The request stack. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * The config factory. @@ -127,22 +127,22 @@ public function resetConfigFactory() { * The request object. */ protected function getRequest() { - if (!$this->request) { - $this->request = $this->container()->get('request'); + if (!$this->requestStack) { + $this->requestStack = \Drupal::service('request_stack'); } - return $this->request; + return $this->requestStack->getCurrentRequest(); } /** - * Sets the request object to use. + * Sets the request stack object to use. * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack object. * * @return $this */ - public function setRequest(Request $request) { - $this->request = $request; + public function setRequestStack(RequestStack $request_stack) { + $this->requestStack = $request_stack; return $this; } diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index d3bedc13f8fc..32a21af229e0 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -13,7 +13,6 @@ use Drupal\Core\Access\CsrfTokenGenerator; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\HttpKernel; use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; use Drupal\Core\Render\Element; use Drupal\Core\Site\Settings; @@ -21,6 +20,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -67,7 +67,7 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS /** * The HTTP kernel to handle forms returning response objects. * - * @var \Drupal\Core\HttpKernel + * @var \Symfony\Component\HttpKernel\HttpKernel */ protected $httpKernel; diff --git a/core/lib/Drupal/Core/HttpKernel.php b/core/lib/Drupal/Core/HttpKernel.php deleted file mode 100644 index dba6032a2e42..000000000000 --- a/core/lib/Drupal/Core/HttpKernel.php +++ /dev/null @@ -1,263 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\Core\HttpKernel. - * - * @todo This file is copied verbatim, with the exception of the namespace - * change and this commment block, from Symfony full stack's FrameworkBundle. - * Once the FrameworkBundle is available as a Composer package we should switch - * to pulling it via Composer. - */ - -namespace Drupal\Core; - -use Symfony\Cmf\Component\Routing\RouteObjectInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\StreamedResponse; -use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\HttpKernel\HttpKernel as BaseHttpKernel; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; - -/** - * This HttpKernel is used to manage scope changes of the DI container. - * - * @author Fabien Potencier <fabien@symfony.com> - * @author Johannes M. Schmitt <schmittjoh@gmail.com> - */ -class HttpKernel extends BaseHttpKernel implements ContainerAwareInterface { - - use ContainerAwareTrait; - - private $esiSupport; - - public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) - { - $request->headers->set('X-Php-Ob-Level', ob_get_level()); - - $this->container->enterScope('request'); - $this->container->set('request', $request, 'request'); - - try { - $response = parent::handle($request, $type, $catch); - } catch (\Exception $e) { - $this->container->leaveScope('request'); - - throw $e; - } - - $this->container->leaveScope('request'); - - return $response; - } - - /** - * Forwards the request to another controller. - * - * @param string|null $controller - * The controller name (a string like BlogBundle:Post:index). - * @param array $attributes - * An array of request attributes. - * @param array $query - * An array of request query parameters. - * - * @return Response - * A Response instance - */ - public function forward($controller, array $attributes = array(), array $query = array()) - { - $subrequest = $this->setupSubrequest($controller, $attributes, $query); - - return $this->handle($subrequest, HttpKernelInterface::SUB_REQUEST); - } - - /** - * Renders a Controller and returns the Response content. - * - * Note that this method generates an esi:include tag only when both the standalone - * option is set to true and the request has ESI capability (@see Symfony\Component\HttpKernel\HttpCache\ESI). - * - * Available options: - * - * * attributes: An array of request attributes (only when the first argument is a controller) - * * query: An array of request query parameters (only when the first argument is a controller) - * * ignore_errors: true to return an empty string in case of an error - * * alt: an alternative controller to execute in case of an error (can be a controller, a URI, or an array with the controller, the attributes, and the query arguments) - * * standalone: whether to generate an esi:include tag or not when ESI is supported - * * comment: a comment to add when returning an esi:include tag - * - * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI - * @param array $options An array of options - * - * @return string The Response content - */ - public function render($controller, array $options = array()) - { - $options = array_merge(array( - 'attributes' => array(), - 'query' => array(), - 'ignore_errors' => !$this->container->getParameter('kernel.debug'), - 'alt' => array(), - 'standalone' => false, - 'comment' => '', - ), $options); - - if (!is_array($options['alt'])) { - $options['alt'] = array($options['alt']); - } - - if (null === $this->esiSupport) { - $this->esiSupport = $this->container->has('esi') && $this->container->get('esi')->hasSurrogateEsiCapability($this->container->get('request')); - } - - if ($this->esiSupport && (true === $options['standalone'] || 'esi' === $options['standalone'])) { - $uri = $this->generateInternalUri($controller, $options['attributes'], $options['query']); - - $alt = ''; - if ($options['alt']) { - $alt = $this->generateInternalUri($options['alt'][0], isset($options['alt'][1]) ? $options['alt'][1] : array(), isset($options['alt'][2]) ? $options['alt'][2] : array()); - } - - return $this->container->get('esi')->renderIncludeTag($uri, $alt, $options['ignore_errors'], $options['comment']); - } - - if ('js' === $options['standalone']) { - $uri = $this->generateInternalUri($controller, $options['attributes'], $options['query'], false); - $defaultContent = null; - - if ($template = $this->container->getParameter('templating.hinclude.default_template')) { - $defaultContent = $this->container->get('templating')->render($template); - } - - return $this->renderHIncludeTag($uri, $defaultContent); - } - - $request = $this->container->get('request'); - - // controller or URI? - if (0 === strpos($controller, '/')) { - $subRequest = Request::create($request->getUriForPath($controller), 'get', array(), $request->cookies->all(), array(), $request->server->all()); - if ($session = $request->getSession()) { - $subRequest->setSession($session); - } - } else { - $options['attributes']['_controller'] = $controller; - - if (!isset($options['attributes']['_format'])) { - $options['attributes']['_format'] = $request->getRequestFormat(); - } - - $options['attributes'][RouteObjectInterface::ROUTE_OBJECT] = '_internal'; - $subRequest = $request->duplicate($options['query'], null, $options['attributes']); - $subRequest->setMethod('GET'); - } - - $level = ob_get_level(); - try { - $response = $this->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false); - - if (!$response->isSuccessful()) { - throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $request->getUri(), $response->getStatusCode())); - } - - if (!$response instanceof StreamedResponse) { - return $response->getContent(); - } - - $response->sendContent(); - } catch (\Exception $e) { - if ($options['alt']) { - $alt = $options['alt']; - unset($options['alt']); - $options['attributes'] = isset($alt[1]) ? $alt[1] : array(); - $options['query'] = isset($alt[2]) ? $alt[2] : array(); - - return $this->render($alt[0], $options); - } - - if (!$options['ignore_errors']) { - throw $e; - } - - // let's clean up the output buffers that were created by the sub-request - while (ob_get_level() > $level) { - ob_get_clean(); - } - } - } - - /** - * Generates an internal URI for a given controller. - * - * This method uses the "_internal" route, which should be available. - * - * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI - * @param array $attributes An array of request attributes - * @param array $query An array of request query parameters - * @param boolean $secure - * - * @return string An internal URI - */ - public function generateInternalUri($controller, array $attributes = array(), array $query = array(), $secure = true) - { - if (0 === strpos($controller, '/')) { - return $controller; - } - - $path = http_build_query($attributes, '', '&'); - $uri = $this->container->get('router')->generate($secure ? '_internal' : '_internal_public', array( - 'controller' => $controller, - 'path' => $path ?: 'none', - '_format' => $this->container->get('request')->getRequestFormat(), - )); - - if ($queryString = http_build_query($query, '', '&')) { - $uri .= '?'.$queryString; - } - - return $uri; - } - - /** - * Renders an HInclude tag. - * - * @param string $uri A URI - * @param string $defaultContent Default content - */ - public function renderHIncludeTag($uri, $defaultContent = null) - { - return sprintf('<hx:include src="%s">%s</hx:include>', $uri, $defaultContent); - } - - public function hasEsiSupport() - { - return $this->esiSupport; - } - - /** - * Creates a request object for a subrequest. - * - * @param string $controller - * The controller name (a string like BlogBundle:Post:index) - * @param array $attributes - * An array of request attributes. - * @param array $query - * An array of request query parameters. - * - * @return \Symfony\Component\HttpFoundation\Request - * Returns the new request. - */ - public function setupSubrequest($controller, array $attributes, array $query) { - // Don't override the controller if it's NULL. - if (isset($controller)) { - $attributes['_controller'] = $controller; - } - else { - unset($attributes['_controller']); - } - return $this->container->get('request')->duplicate($query, NULL, $attributes); - } - -} diff --git a/core/lib/Drupal/Core/Installer/InstallerKernel.php b/core/lib/Drupal/Core/Installer/InstallerKernel.php index dcac1b556e3b..9b0b6458b2b8 100644 --- a/core/lib/Drupal/Core/Installer/InstallerKernel.php +++ b/core/lib/Drupal/Core/Installer/InstallerKernel.php @@ -25,12 +25,4 @@ protected function initializeContainer($rebuild = TRUE) { return $container; } - /** - * {@inheritdoc} - */ - protected function dumpDrupalContainer(ContainerBuilder $container, $baseClass) { - if (Settings::get('hash_salt')) { - return parent::dumpDrupalContainer($container, $baseClass); - } - } } diff --git a/core/lib/Drupal/Core/Logger/LoggerChannel.php b/core/lib/Drupal/Core/Logger/LoggerChannel.php index 074cd23dd150..aa812edd00e3 100644 --- a/core/lib/Drupal/Core/Logger/LoggerChannel.php +++ b/core/lib/Drupal/Core/Logger/LoggerChannel.php @@ -11,7 +11,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\LoggerTrait; use Psr\Log\LogLevel; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Defines a logger channel that most implementations will use. @@ -52,11 +52,11 @@ class LoggerChannel implements LoggerChannelInterface { protected $loggers = array(); /** - * The request object. + * The request stack object. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * The current user object. @@ -90,15 +90,15 @@ public function log($level, $message, array $context = array()) { 'ip' => '', 'timestamp' => time(), ); - if ($this->currentUser) { - $context['user'] = $this->currentUser; - $context['uid'] = $this->currentUser->id(); - } // Some context values are only available when in a request context. - if ($this->request) { - $context['request_uri'] = $this->request->getUri(); - $context['referer'] = $this->request->headers->get('Referer', ''); - $context['ip'] = $this->request->getClientIP(); + if ($this->requestStack && $request = $this->requestStack->getCurrentRequest()) { + $context['request_uri'] = $request->getUri(); + $context['referer'] = $request->headers->get('Referer', ''); + $context['ip'] = $request->getClientIP(); + if ($this->currentUser) { + $context['user'] = $this->currentUser; + $context['uid'] = $this->currentUser->id(); + } } if (is_string($level)) { @@ -114,8 +114,8 @@ public function log($level, $message, array $context = array()) { /** * {@inheritdoc} */ - public function setRequest(Request $request = NULL) { - $this->request = $request; + public function setRequestStack(RequestStack $requestStack = NULL) { + $this->requestStack = $requestStack; } /** diff --git a/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php b/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php index 1ec171002d5c..7d66887d863e 100644 --- a/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php +++ b/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php @@ -10,7 +10,6 @@ use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; -use Symfony\Component\DependencyInjection\Exception\RuntimeException; /** * Defines a factory for logging channels. @@ -39,16 +38,12 @@ public function get($channel) { if (!isset($this->channels[$channel])) { $instance = new LoggerChannel($channel); - // If the service container is set and request is available, set it with - // the current user to the channel. + // If we have a container set the request_stack and current_user services + // on the channel. It is up to the channel to determine if there is a + // current request. if ($this->container) { - try { - $instance->setRequest($this->container->get('request')); - $instance->setCurrentUser($this->container->get('current_user')); - } - catch (RuntimeException $e) { - // We are not in a request context. - } + $instance->setRequestStack($this->container->get('request_stack')); + $instance->setCurrentUser($this->container->get('current_user')); } // Pass the loggers to the channel. diff --git a/core/lib/Drupal/Core/Logger/LoggerChannelInterface.php b/core/lib/Drupal/Core/Logger/LoggerChannelInterface.php index 15d974141356..20afd7eb7e14 100644 --- a/core/lib/Drupal/Core/Logger/LoggerChannelInterface.php +++ b/core/lib/Drupal/Core/Logger/LoggerChannelInterface.php @@ -9,7 +9,7 @@ use Drupal\Core\Session\AccountInterface; use Psr\Log\LoggerInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Logger channel interface. @@ -17,12 +17,12 @@ interface LoggerChannelInterface extends LoggerInterface { /** - * Sets the request. + * Sets the request stack. * - * @param \Symfony\Component\HttpFoundation\Request|null $request + * @param \Symfony\Component\HttpFoundation\RequestStack|null $requestStack * The current request object. */ - public function setRequest(Request $request = NULL); + public function setRequestStack(RequestStack $requestStack = NULL); /** * Sets the current user. diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php index 7028101f622f..a5684ff0bf51 100644 --- a/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -9,6 +9,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Route as SymfonyRoute; use Symfony\Component\Routing\Exception\RouteNotFoundException; @@ -27,11 +28,11 @@ class UrlGenerator extends ProviderBasedGenerator implements UrlGeneratorInterface { /** - * A request object. + * A request stack object. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * The path processor to convert the system path to one suitable for urls. @@ -91,7 +92,7 @@ class UrlGenerator extends ProviderBasedGenerator implements UrlGeneratorInterfa * @param \Psr\Log\LoggerInterface $logger * An optional logger for recording errors. */ - public function __construct(RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, ConfigFactoryInterface $config, Settings $settings, LoggerInterface $logger = NULL) { + public function __construct(RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, ConfigFactoryInterface $config, Settings $settings, LoggerInterface $logger = NULL, RequestStack $requestStack) { parent::__construct($provider, $logger); $this->pathProcessor = $path_processor; @@ -99,13 +100,18 @@ public function __construct(RouteProviderInterface $provider, OutboundPathProces $this->mixedModeSessions = $settings->get('mixed_mode_sessions', FALSE); $allowed_protocols = $config->get('system.filter')->get('protocols') ?: array('http', 'https'); UrlHelper::setAllowedProtocols($allowed_protocols); + $this->requestStack = $requestStack; + $this->updateFromRequest(); } /** - * {@inheritdoc} + * Updates instance properties using the current request from the stack. + * + * @todo This should probably be inline in the constructor as this is only + * useful to get some current tests pass. */ - public function setRequest(Request $request) { - $this->request = $request; + public function updateFromRequest() { + $request = $this->requestStack->getCurrentRequest(); // Set some properties, based on the request, that are used during path-based // url generation. $this->basePath = $request->getBasePath() . '/'; @@ -351,7 +357,7 @@ protected function processPath($path, &$options = array()) { $actual_path = $path; $query_string = ''; } - $path = '/' . $this->pathProcessor->processOutbound(trim($actual_path, '/'), $options, $this->request); + $path = '/' . $this->pathProcessor->processOutbound(trim($actual_path, '/'), $options, $this->requestStack->getCurrentRequest()); $path .= $query_string; return $path; } diff --git a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php index 3a64ecd64f0f..a3535ad04879 100644 --- a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php +++ b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Routing; -use Symfony\Component\HttpFoundation\Request; use Symfony\Cmf\Component\Routing\VersatileGeneratorInterface; /** @@ -142,14 +141,6 @@ public function getPathFromRoute($name, $parameters = array()); */ public function generateFromRoute($name, $parameters = array(), $options = array()); - /** - * Sets the $request property. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The HttpRequest object representing the current request. - */ - public function setRequest(Request $request); - /** * Sets the baseUrl property. * diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php index 9f002180bcbc..56a42fa0b26b 100644 --- a/core/lib/Drupal/Core/Session/AccountProxy.php +++ b/core/lib/Drupal/Core/Session/AccountProxy.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Session; use Drupal\Core\Authentication\AuthenticationManagerInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * A proxied implementation of AccountInterface. @@ -26,9 +26,9 @@ class AccountProxy implements AccountProxyInterface { /** * The current request. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * The authentication manager. @@ -52,9 +52,9 @@ class AccountProxy implements AccountProxyInterface { * @param \Symfony\Component\HttpFoundation\Request $request * The request object used for authenticating. */ - public function __construct(AuthenticationManagerInterface $authentication_manager, Request $request) { + public function __construct(AuthenticationManagerInterface $authentication_manager, RequestStack $requestStack) { $this->authenticationManager = $authentication_manager; - $this->request = $request; + $this->requestStack = $requestStack; } /** @@ -74,7 +74,9 @@ public function setAccount(AccountInterface $account) { */ public function getAccount() { if (!isset($this->account)) { - $this->setAccount($this->authenticationManager->authenticate($this->request)); + // Use the master request to prevent subrequests authenticating to a + // different user. + $this->setAccount($this->authenticationManager->authenticate($this->requestStack->getMasterRequest())); } return $this->account; } diff --git a/core/modules/block/src/Tests/BlockViewBuilderTest.php b/core/modules/block/src/Tests/BlockViewBuilderTest.php index 7c1dd550e5ba..2109058bf51b 100644 --- a/core/modules/block/src/Tests/BlockViewBuilderTest.php +++ b/core/modules/block/src/Tests/BlockViewBuilderTest.php @@ -149,8 +149,9 @@ public function testBlockViewBuilderCache() { */ protected function verifyRenderCacheHandling() { // Force a request via GET so we can get drupal_render() cache working. - $request_method = \Drupal::request()->server->get('REQUEST_METHOD'); - $this->container->get('request')->setMethod('GET'); + $request = \Drupal::request(); + $request_method = $request->server->get('REQUEST_METHOD'); + $request->setMethod('GET'); // Test that entities with caching disabled do not generate a cache entry. $build = $this->getBlockRenderArray(); @@ -184,7 +185,7 @@ protected function verifyRenderCacheHandling() { $this->assertFalse($this->container->get('cache.render')->get($cid), 'The block render cache entry has been cleared when the block was deleted.'); // Restore the previous request method. - $this->container->get('request')->setMethod($request_method); + $request->setMethod($request_method); } /** @@ -213,8 +214,9 @@ public function testBlockViewBuilderAlter() { \Drupal::state()->set('block_test_view_alter_suffix', FALSE); // Force a request via GET so we can get drupal_render() cache working. - $request_method = \Drupal::request()->server->get('REQUEST_METHOD'); - $this->container->get('request')->setMethod('GET'); + $request = \Drupal::request(); + $request_method = $request->server->get('REQUEST_METHOD'); + $request->setMethod('GET'); $default_keys = array('entity_view', 'block', 'test_block', 'en', 'cache_context.theme'); $default_tags = array('block_view' => TRUE, 'block' => array('test_block'), 'theme' => 'stark', 'block_plugin' => array('test_cache')); @@ -259,7 +261,7 @@ public function testBlockViewBuilderAlter() { $this->assertTrue(isset($build['#prefix']) && $build['#prefix'] === 'Hiya!<br>', 'A cached block without content is altered.'); // Restore the previous request method. - $this->container->get('request')->setMethod($request_method); + $request->setMethod($request_method); } /** @@ -272,8 +274,9 @@ public function testBlockViewBuilderAlter() { */ public function testBlockViewBuilderCacheContexts() { // Force a request via GET so we can get drupal_render() cache working. - $request_method = \Drupal::request()->server->get('REQUEST_METHOD'); - $this->container->get('request')->setMethod('GET'); + $request = \Drupal::request(); + $request_method = $request->server->get('REQUEST_METHOD'); + $request->setMethod('GET'); // First: no cache context. $this->setBlockCacheConfig(array( @@ -311,7 +314,7 @@ public function testBlockViewBuilderCacheContexts() { $this->container->set('cache_context.url', $original_url_cache_context); // Restore the previous request method. - $this->container->get('request')->setMethod($request_method); + $request->setMethod($request_method); } /** diff --git a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php index 604dbe6c5fc7..5e85d9973c3b 100644 --- a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php +++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php @@ -11,7 +11,7 @@ use Drupal\book\BookManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Provides a 'Book navigation' block. @@ -27,9 +27,9 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt /** * The request object. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * The book manager. @@ -47,15 +47,15 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack object. * @param \Drupal\book\BookManagerInterface $book_manager * The book manager. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request, BookManagerInterface $book_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, BookManagerInterface $book_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->request = $request; + $this->requestStack = $request_stack; $this->bookManager = $book_manager; } @@ -67,7 +67,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('request'), + $container->get('request_stack'), $container->get('book.manager') ); } @@ -113,7 +113,7 @@ public function blockSubmit($form, &$form_state) { public function build() { $current_bid = 0; - if ($node = $this->request->get('node')) { + if ($node = $this->requestStack->getCurrentRequest()->get('node')) { $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid']; } if ($this->configuration['block_mode'] == 'all pages') { @@ -173,7 +173,7 @@ public function build() { public function getCacheKeys() { // Add a key for the active book trail. $current_bid = 0; - if ($node = $this->request->get('node')) { + if ($node = $this->requestStack->getCurrentRequest()->get('node')) { $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid']; } if ($current_bid === 0) { diff --git a/core/modules/comment/tests/src/Entity/CommentLockTest.php b/core/modules/comment/tests/src/Entity/CommentLockTest.php index 7f667ff07d0d..a9a04f4ec8c8 100644 --- a/core/modules/comment/tests/src/Entity/CommentLockTest.php +++ b/core/modules/comment/tests/src/Entity/CommentLockTest.php @@ -9,6 +9,8 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\EntityType; use Drupal\Tests\UnitTestCase; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Tests comment acquires and releases the right lock. @@ -25,8 +27,10 @@ public function testLocks() { $container->set('module_handler', $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface')); $container->set('current_user', $this->getMock('Drupal\Core\Session\AccountInterface')); $container->set('cache.test', $this->getMock('Drupal\Core\Cache\CacheBackendInterface')); + $request_stack = new RequestStack(); + $request_stack->push(Request::create('/')); + $container->set('request_stack', $request_stack); $container->setParameter('cache_bins', array('cache.test' => 'test')); - $container->register('request', 'Symfony\Component\HttpFoundation\Request'); $lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface'); $cid = 2; $lock_name = "comment:$cid:.00/"; diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php index 2e326a005c59..4ce8d844bd95 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php @@ -116,7 +116,7 @@ function testImageFieldSync() { $langcode = $this->langcodes[1]; // Populate the required contextual values. - $attributes = $this->container->get('request')->attributes; + $attributes = \Drupal::request()->attributes; $attributes->set('source_langcode', $default_langcode); // Populate the test entity with some random initial values. diff --git a/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php index ebabb199bee1..9876f510be8b 100644 --- a/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php +++ b/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php @@ -96,7 +96,7 @@ function testImageSource() { // Create a list of test image sources. // The keys become the value of the IMG 'src' attribute, the values are the // expected filter conversions. - $host = $this->container->get('request')->getHost(); + $host = \Drupal::request()->getHost(); $host_pattern = '|^http\://' . $host . '(\:[0-9]{0,5})|'; $images = array( $http_base_url . '/' . $druplicon => base_path() . $druplicon, diff --git a/core/modules/language/language.services.yml b/core/modules/language/language.services.yml index e183e6ddacfb..9b5b2f474c7b 100644 --- a/core/modules/language/language.services.yml +++ b/core/modules/language/language.services.yml @@ -4,7 +4,7 @@ services: arguments: ['@container.namespaces', '@cache.discovery', '@module_handler'] language_negotiator: class: Drupal\language\LanguageNegotiator - arguments: ['@language_manager', '@plugin.manager.language_negotiation_method', '@config.factory', '@settings'] + arguments: ['@language_manager', '@plugin.manager.language_negotiation_method', '@config.factory', '@settings', '@request_stack'] calls: - [initLanguageManager] language.config_subscriber: diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index 0d9c7c6a7706..cb96a8ebe3ca 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -16,6 +16,7 @@ use Drupal\Core\Language\LanguageManager; use Drupal\language\Config\LanguageConfigFactoryOverrideInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Overrides default LanguageManager to provide configured languages. @@ -46,9 +47,9 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl /** * The request object. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * The language negotiator. @@ -113,11 +114,12 @@ public static function rebuildServices() { * @param \Drupal\Core\Config\StorageInterface $config_storage * The configuration storage engine. */ - public function __construct(LanguageDefault $default_language, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, LanguageConfigFactoryOverrideInterface $config_override) { + public function __construct(LanguageDefault $default_language, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, LanguageConfigFactoryOverrideInterface $config_override, RequestStack $requestStack) { $this->defaultLanguage = $default_language; $this->configFactory = $config_factory; $this->moduleHandler = $module_handler; $this->configFactoryOverride = $config_override; + $this->requestStack = $requestStack; } /** @@ -244,13 +246,6 @@ public function reset($type = NULL) { return $this; } - /** - * {@inheritdoc} - */ - public function setRequest(Request $request) { - $this->request = $request; - } - /** * {@inheritdoc} */ @@ -371,7 +366,7 @@ public function getLanguageSwitchLinks($type, $path) { $reflector = new \ReflectionClass($method['class']); if ($reflector->implementsInterface('\Drupal\language\LanguageSwitcherInterface')) { - $result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->request, $type, $path); + $result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->requestStack->getCurrentRequest(), $type, $path); if (!empty($result)) { // Allow modules to provide translations for specific links. diff --git a/core/modules/language/src/ConfigurableLanguageManagerInterface.php b/core/modules/language/src/ConfigurableLanguageManagerInterface.php index 2edf0bb604d4..0d15e2fcea00 100644 --- a/core/modules/language/src/ConfigurableLanguageManagerInterface.php +++ b/core/modules/language/src/ConfigurableLanguageManagerInterface.php @@ -20,14 +20,6 @@ interface ConfigurableLanguageManagerInterface extends LanguageManagerInterface */ public static function rebuildServices(); - /** - * Injects the request object. - * - * @param \Symfony\Component\HttpFoundation\Request - * The request object. - */ - public function setRequest(Request $request); - /** * Returns the language negotiator. * diff --git a/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php b/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php index fcc1ddfc94c2..c543fc78a0ea 100644 --- a/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php +++ b/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php @@ -78,10 +78,9 @@ public function onKernelRequestLanguage(GetResponseEvent $event) { if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { $request = $event->getRequest(); $this->negotiator->setCurrentUser($this->currentUser); - $this->negotiator->setRequest($request); + $this->negotiator->reset(); if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) { $this->languageManager->setNegotiator($this->negotiator); - $this->languageManager->setRequest($request); $this->languageManager->setConfigOverrideLanguage($this->languageManager->getCurrentLanguage()); } // After the language manager has initialized, set the default langcode diff --git a/core/modules/language/src/HttpKernel/PathProcessorLanguage.php b/core/modules/language/src/HttpKernel/PathProcessorLanguage.php index b2eb841e2338..c3a6a9fc616b 100644 --- a/core/modules/language/src/HttpKernel/PathProcessorLanguage.php +++ b/core/modules/language/src/HttpKernel/PathProcessorLanguage.php @@ -110,7 +110,7 @@ public function processOutbound($path, &$options = array(), Request $request = N $this->multilingual = $this->languageManager->isMultilingual(); } if ($this->multilingual) { - $this->negotiator->setRequest($request); + $this->negotiator->reset(); $scope = 'outbound'; if (!isset($this->processors[$scope])) { $this->initProcessors($scope); diff --git a/core/modules/language/src/LanguageNegotiator.php b/core/modules/language/src/LanguageNegotiator.php index cdeb8cf6f13c..eb1df939bcac 100644 --- a/core/modules/language/src/LanguageNegotiator.php +++ b/core/modules/language/src/LanguageNegotiator.php @@ -12,7 +12,7 @@ use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Site\Settings; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Class responsible for performing language negotiation. @@ -48,11 +48,11 @@ class LanguageNegotiator implements LanguageNegotiatorInterface { protected $settings; /** - * The request object. + * The request stack object. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * The current active user. @@ -87,11 +87,12 @@ class LanguageNegotiator implements LanguageNegotiatorInterface { * @param \Drupal\Core\Site\Settings $settings * The settings instance. */ - public function __construct(ConfigurableLanguageManagerInterface $language_manager, PluginManagerInterface $negotiator_manager, ConfigFactoryInterface $config_factory, Settings $settings) { + public function __construct(ConfigurableLanguageManagerInterface $language_manager, PluginManagerInterface $negotiator_manager, ConfigFactoryInterface $config_factory, Settings $settings, RequestStack $requestStack) { $this->languageManager = $language_manager; $this->negotiatorManager = $negotiator_manager; $this->configFactory = $config_factory; $this->settings = $settings; + $this->requestStack = $requestStack; } /** @@ -121,21 +122,13 @@ public function setCurrentUser(AccountInterface $current_user) { $this->reset(); } - /** - * {@inheritdoc} - */ - public function setRequest(Request $request) { - $this->request = $request; - $this->reset(); - } - /** * {@inheritdoc} */ public function initializeType($type) { $language = NULL; - if ($this->currentUser && $this->request) { + if ($this->currentUser) { // Execute the language negotiation methods in the order they were set up // and return the first valid language found. foreach ($this->getEnabledNegotiators($type) as $method_id => $info) { @@ -207,7 +200,7 @@ protected function negotiateLanguage($type, $method_id) { // If the language negotiation method has no cache preference or this is // satisfied we can execute the callback. if ($cache = !isset($method['cache']) || $this->currentUser->isAuthenticated() || $method['cache'] == $cache_enabled) { - $langcode = $this->getNegotiationMethodInstance($method_id)->getLangcode($this->request); + $langcode = $this->getNegotiationMethodInstance($method_id)->getLangcode($this->requestStack->getCurrentRequest()); } } diff --git a/core/modules/language/src/LanguageNegotiatorInterface.php b/core/modules/language/src/LanguageNegotiatorInterface.php index 13d70681f9df..309d84a2c076 100644 --- a/core/modules/language/src/LanguageNegotiatorInterface.php +++ b/core/modules/language/src/LanguageNegotiatorInterface.php @@ -8,7 +8,6 @@ namespace Drupal\language; use Drupal\Core\Session\AccountInterface; -use Symfony\Component\HttpFoundation\Request; /** * Common interface for language negotiation services. @@ -123,14 +122,6 @@ public function reset(); */ public function setCurrentUser(AccountInterface $current_user); - /** - * Sets the active request and resets all language types. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The HttpRequest object representing the current request. - */ - public function setRequest(Request $request); - /** * Initializes the specified language type. * diff --git a/core/modules/language/src/LanguageServiceProvider.php b/core/modules/language/src/LanguageServiceProvider.php index a565c1c46c62..523e3832763d 100644 --- a/core/modules/language/src/LanguageServiceProvider.php +++ b/core/modules/language/src/LanguageServiceProvider.php @@ -52,7 +52,8 @@ public function alter(ContainerBuilder $container) { $definition->setClass('Drupal\language\ConfigurableLanguageManager') ->addArgument(new Reference('config.factory')) ->addArgument(new Reference('module_handler')) - ->addArgument(new Reference('language.config_factory_override')); + ->addArgument(new Reference('language.config_factory_override')) + ->addArgument(new Reference('request_stack')); if ($default_language_values = $this->getDefaultLanguageValues()) { $container->setParameter('language.default_values', $default_language_values); } diff --git a/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php b/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php index 86a62bf83ac6..d1110001c4d2 100644 --- a/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php @@ -62,9 +62,6 @@ class LanguageUILanguageNegotiationTest extends WebTestBase { function setUp() { parent::setUp(); - $this->request = Request::createFromGlobals(); - $this->container->set('request', $this->request); - $admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages', 'administer blocks')); $this->drupalLogin($admin_user); } @@ -432,7 +429,7 @@ function testLanguageDomain() { // Base path gives problems on the testbot, so $correct_link is hard-coded. // @see UrlAlterFunctionalTest::assertUrlOutboundAlter (path.test). $italian_url = url('admin', array('language' => $languages['it'], 'script' => '')); - $url_scheme = $this->request->isSecure() ? 'https://' : 'http://'; + $url_scheme = \Drupal::request()->isSecure() ? 'https://' : 'http://'; $correct_link = $url_scheme . $link; $this->assertEqual($italian_url, $correct_link, format_string('The url() function returns the right URL (@url) in accordance with the chosen language', array('@url' => $italian_url))); @@ -446,9 +443,9 @@ function testLanguageDomain() { $this->settingsSet('mixed_mode_sessions', FALSE); // Test HTTPS via current URL scheme. - $generator = $this->container->get('url_generator'); $request = Request::create('', 'GET', array(), array(), array(), array('HTTPS' => 'on')); - $generator->setRequest($request); + $this->container->get('request_stack')->push($request); + $generator = $this->container->get('url_generator'); $italian_url = url('admin', array('language' => $languages['it'], 'script' => '')); $correct_link = 'https://' . $link; $this->assertTrue($italian_url == $correct_link, format_string('The url() function returns the right URL (via current URL scheme) (@url) in accordance with the chosen language', array('@url' => $italian_url))); diff --git a/core/modules/rest/tests/src/CollectRoutesTest.php b/core/modules/rest/tests/src/CollectRoutesTest.php index 9baf9d16729b..5a0cac622409 100644 --- a/core/modules/rest/tests/src/CollectRoutesTest.php +++ b/core/modules/rest/tests/src/CollectRoutesTest.php @@ -49,7 +49,6 @@ protected function setUp() { ->getMock(); $container->set('content_negotiation', $content_negotiation); - $container->set('request', $request); $this->view = $this->getMock('\Drupal\views\Entity\View', array('initHandlers'), array( array('id' => 'test_view'), diff --git a/core/modules/simpletest/src/InstallerTestBase.php b/core/modules/simpletest/src/InstallerTestBase.php index ebd9873e7bce..df33c4194dc8 100644 --- a/core/modules/simpletest/src/InstallerTestBase.php +++ b/core/modules/simpletest/src/InstallerTestBase.php @@ -14,6 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Base class for testing the interactive installer. @@ -101,8 +102,10 @@ protected function setUp() { // @see install_begin_request() $request = Request::create($GLOBALS['base_url'] . '/core/install.php'); $this->container = new ContainerBuilder(); + $request_stack = new RequestStack(); + $request_stack->push($request); $this->container - ->set('request', $request); + ->set('request_stack', $request_stack); $this->container ->setParameter('language.default_values', Language::$defaultValues); $this->container diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index 4e6c0e2de39b..dc459ed6052d 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -166,7 +166,6 @@ protected function setUp() { // Set the request scope. $this->container = $this->kernel->getContainer(); - $this->container->set('request', $request); $this->container->get('request_stack')->push($request); $this->container->get('state')->set('system.module.files', $this->moduleFiles); @@ -301,7 +300,7 @@ public function containerBuild(ContainerBuilder $container) { } $request = Request::create('/'); - $this->container->set('request', $request); + $container->get('request_stack')->push($request); } /** diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index b058560434ae..e6fe0682b558 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -23,6 +23,7 @@ use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\Utility\Error; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\DependencyInjection\Reference; /** diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 3bd7269faf91..ac2f0a0664bf 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -1601,6 +1601,7 @@ protected function drupalPostForm($path, $edit, $submit, array $options = array( if (isset($path)) { $this->drupalGet($path, $options); } + if ($this->parse()) { $edit_save = $edit; // Let's iterate over all the forms. @@ -2693,7 +2694,8 @@ protected function prepareRequestForGenerator($clean_urls = TRUE, $override_serv $server = array_merge($server, $override_server_vars); $request = Request::create($request_path, 'GET', array(), array(), array(), $server); - $generator->setRequest($request); + $this->container->get('request_stack')->push($request); + $generator->updateFromRequest(); return $request; } } diff --git a/core/modules/system/src/Plugin/Block/SystemHelpBlock.php b/core/modules/system/src/Plugin/Block/SystemHelpBlock.php index c9de38173701..a07937226222 100644 --- a/core/modules/system/src/Plugin/Block/SystemHelpBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemHelpBlock.php @@ -85,7 +85,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('request'), + $container->get('request_stack')->getCurrentRequest(), $container->get('module_handler'), $container->get('current_route_match') ); diff --git a/core/modules/system/src/Tests/Common/TableSortExtenderUnitTest.php b/core/modules/system/src/Tests/Common/TableSortExtenderUnitTest.php index e7cac6e0ca14..aa39b75a0859 100644 --- a/core/modules/system/src/Tests/Common/TableSortExtenderUnitTest.php +++ b/core/modules/system/src/Tests/Common/TableSortExtenderUnitTest.php @@ -36,7 +36,7 @@ function testTableSortInit() { ); $request = Request::createFromGlobals(); $request->query->replace(array()); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $ts = tablesort_init($headers); $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => String::checkPlain(var_export($ts, TRUE))))); $this->assertEqual($ts, $expected_ts, 'Simple table headers sorted correctly.'); @@ -49,7 +49,7 @@ function testTableSortInit() { // headers are overridable. 'order' => 'bar', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $ts = tablesort_init($headers); $this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => String::checkPlain(var_export($ts, TRUE))))); $this->assertEqual($ts, $expected_ts, 'Simple table headers plus non-overriding $_GET parameters sorted correctly.'); @@ -63,7 +63,7 @@ function testTableSortInit() { // it in the links that it creates. 'alpha' => 'beta', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $expected_ts['sort'] = 'desc'; $expected_ts['query'] = array('alpha' => 'beta'); $ts = tablesort_init($headers); @@ -91,7 +91,7 @@ function testTableSortInit() { $request->query->replace(array( 'order' => '2', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $ts = tablesort_init($headers); $expected_ts = array( 'name' => '2', @@ -110,7 +110,7 @@ function testTableSortInit() { // exist. 'order' => 'bar', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $ts = tablesort_init($headers); $expected_ts = array( 'name' => '1', @@ -131,7 +131,7 @@ function testTableSortInit() { // it in the links that it creates. 'alpha' => 'beta', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $expected_ts = array( 'name' => '1', 'sql' => 'one', diff --git a/core/modules/system/src/Tests/Database/SelectPagerDefaultTest.php b/core/modules/system/src/Tests/Database/SelectPagerDefaultTest.php index 306f1d4e3d9c..6c358f076b28 100644 --- a/core/modules/system/src/Tests/Database/SelectPagerDefaultTest.php +++ b/core/modules/system/src/Tests/Database/SelectPagerDefaultTest.php @@ -135,7 +135,7 @@ function testElementNumbers() { $request->query->replace(array( 'page' => '3, 2, 1, 0', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $name = db_select('test', 't') ->extend('Drupal\Core\Database\Query\PagerSelectExtender') diff --git a/core/modules/system/src/Tests/DrupalKernel/ServiceDestructionTest.php b/core/modules/system/src/Tests/DrupalKernel/ServiceDestructionTest.php index 57484470e667..b97b1c92dbf0 100644 --- a/core/modules/system/src/Tests/DrupalKernel/ServiceDestructionTest.php +++ b/core/modules/system/src/Tests/DrupalKernel/ServiceDestructionTest.php @@ -31,7 +31,7 @@ public function testDestructionUsed() { // Call the class and then terminate the kernel $this->container->get('service_provider_test_class'); $response = new Response(); - $this->container->get('kernel')->terminate($this->container->get('request'), $response); + $this->container->get('kernel')->terminate($this->container->get('request_stack')->getCurrentRequest(), $response); $this->assertTrue(\Drupal::state()->get('service_provider_test.destructed')); } @@ -48,7 +48,7 @@ public function testDestructionUnused() { // Terminate the kernel. The test class has not been called, so it should not // be destructed. $response = new Response(); - $this->container->get('kernel')->terminate($this->container->get('request'), $response); + $this->container->get('kernel')->terminate($this->container->get('request_stack')->getCurrentRequest(), $response); $this->assertNull(\Drupal::state()->get('service_provider_test.destructed')); } } diff --git a/core/modules/system/src/Tests/Entity/EntityQueryTest.php b/core/modules/system/src/Tests/Entity/EntityQueryTest.php index fbf093a83d20..4f56bd61b3bd 100644 --- a/core/modules/system/src/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/src/Tests/Entity/EntityQueryTest.php @@ -350,7 +350,7 @@ function testSort() { $request->query->replace(array( 'page' => '0,2', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $this->queryResults = $this->factory->get('entity_test_mulrev') ->sort("$figures.color") ->sort("$greetings.format") @@ -382,7 +382,7 @@ protected function testTableSort() { 'sort' => 'asc', 'order' => 'Type', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $header = array( 'id' => array('data' => 'Id', 'specifier' => 'id'), @@ -397,7 +397,7 @@ protected function testTableSort() { $request->query->add(array( 'sort' => 'desc', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $header = array( 'id' => array('data' => 'Id', 'specifier' => 'id'), @@ -412,7 +412,7 @@ protected function testTableSort() { $request->query->add(array( 'order' => 'Id', )); - \Drupal::getContainer()->set('request', $request); + \Drupal::getContainer()->get('request_stack')->push($request); $this->queryResults = $this->factory->get('entity_test_mulrev') ->tableSort($header) ->execute(); diff --git a/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php b/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php index 355edc0db9d4..c99b87db6382 100644 --- a/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php +++ b/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php @@ -34,8 +34,9 @@ public function setUp() { */ public function testEntityViewBuilderCache() { // Force a request via GET so we can get drupal_render() cache working. - $request_method = \Drupal::request()->server->get('REQUEST_METHOD'); - $this->container->get('request')->setMethod('GET'); + $request = \Drupal::request(); + $request_method = $request->server->get('REQUEST_METHOD'); + $request->setMethod('GET'); $entity_test = $this->createTestEntity('entity_test'); @@ -71,7 +72,7 @@ public function testEntityViewBuilderCache() { $this->assertFalse($this->container->get('cache.' . $bin)->get($cid), 'The entity render cache has been cleared when the entity was deleted.'); // Restore the previous request method. - $this->container->get('request')->setMethod($request_method); + $request->setMethod($request_method); } /** @@ -79,8 +80,9 @@ public function testEntityViewBuilderCache() { */ public function testEntityViewBuilderCacheWithReferences() { // Force a request via GET so we can get drupal_render() cache working. - $request_method = \Drupal::request()->server->get('REQUEST_METHOD'); - $this->container->get('request')->setMethod('GET'); + $request = \Drupal::request(); + $request_method = $request->server->get('REQUEST_METHOD'); + $request->setMethod('GET'); // Create an entity reference field and an entity that will be referenced. entity_reference_create_instance('entity_test', 'entity_test', 'reference_field', 'Reference', 'entity_test'); @@ -125,7 +127,7 @@ public function testEntityViewBuilderCacheWithReferences() { $this->assertFalse($this->container->get('cache.' . $bin_reference)->get($cid_reference), 'The entity render cache for the referenced entity has been cleared when the entity was deleted.'); // Restore the previous request method. - $this->container->get('request')->setMethod($request_method); + $request->setMethod($request_method); } /** diff --git a/core/modules/system/src/Tests/File/UrlRewritingTest.php b/core/modules/system/src/Tests/File/UrlRewritingTest.php index 0d8c33f44647..2c428aef1e4c 100644 --- a/core/modules/system/src/Tests/File/UrlRewritingTest.php +++ b/core/modules/system/src/Tests/File/UrlRewritingTest.php @@ -93,7 +93,7 @@ function testRelativeFileURL() { // Create a mock Request for file_url_transform_relative(). $request = Request::create($GLOBALS['base_url']); - $this->container->set('request', $request); + $this->container->get('request_stack')->push($request); \Drupal::setContainer($this->container); // Shipped file. diff --git a/core/modules/system/src/Tests/Session/SessionHttpsTest.php b/core/modules/system/src/Tests/Session/SessionHttpsTest.php index 060205c6e01b..dadd7cd0a1a4 100644 --- a/core/modules/system/src/Tests/Session/SessionHttpsTest.php +++ b/core/modules/system/src/Tests/Session/SessionHttpsTest.php @@ -29,7 +29,7 @@ class SessionHttpsTest extends WebTestBase { public function setUp() { parent::setUp(); $this->request = Request::createFromGlobals(); - $this->container->set('request', $this->request); + $this->container->get('request_stack')->push($this->request); } protected function testHttpsSession() { diff --git a/core/modules/system/src/Tests/Theme/RegistryTest.php b/core/modules/system/src/Tests/Theme/RegistryTest.php index 57adf4fd83f6..cb4de8dbbf6e 100644 --- a/core/modules/system/src/Tests/Theme/RegistryTest.php +++ b/core/modules/system/src/Tests/Theme/RegistryTest.php @@ -31,7 +31,6 @@ class RegistryTest extends WebTestBase { function testRaceCondition() { // The theme registry is not marked as persistable in case we don't have a // proper request. - \Drupal::getContainer()->enterScope('request'); \Drupal::request()->setMethod('GET'); $cid = 'test_theme_registry'; diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 74fc69b008f1..117dc49a7fd4 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -981,7 +981,7 @@ function system_page_build(&$page) { 'path' => current_path(), 'front' => drupal_is_front_page(), 'language' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->id, - 'query' => \Drupal::service('request')->query->all(), + 'query' => \Drupal::request()->query->all(), ) ); } diff --git a/core/modules/user/src/Form/UserLoginForm.php b/core/modules/user/src/Form/UserLoginForm.php index 58e0ba25e552..6300bfc3e32f 100644 --- a/core/modules/user/src/Form/UserLoginForm.php +++ b/core/modules/user/src/Form/UserLoginForm.php @@ -118,14 +118,14 @@ public function submitForm(array &$form, array &$form_state) { $account = $this->userStorage->load($form_state['uid']); // A destination was set, probably on an exception controller, - if (!$this->request->request->has('destination')) { + if (!$this->getRequest()->request->has('destination')) { $form_state['redirect_route'] = array( 'route_name' => 'user.view', 'route_parameters' => array('user' => $account->id()), ); } else { - $this->request->query->set('destination', $this->request->request->get('destination')); + $this->getRequest()->query->set('destination', $this->getRequest()->request->get('destination')); } user_login_finalize($account); diff --git a/core/modules/user/src/Form/UserMultipleCancelConfirm.php b/core/modules/user/src/Form/UserMultipleCancelConfirm.php index 4ad6e2b77079..7ed11bca1eef 100644 --- a/core/modules/user/src/Form/UserMultipleCancelConfirm.php +++ b/core/modules/user/src/Form/UserMultipleCancelConfirm.php @@ -190,7 +190,7 @@ public function submitForm(array &$form, array &$form_state) { $admin_form = $this->entityManager->getFormObject('user', 'cancel'); $admin_form->setEntity($account); // Calling this directly required to init form object with $account. - $admin_form->buildForm($admin_form_mock, $admin_form_state, $this->request); + $admin_form->buildForm($admin_form_mock, $admin_form_state); $admin_form->submit($admin_form_mock, $admin_form_state); } else { diff --git a/core/modules/views/src/Form/ViewsForm.php b/core/modules/views/src/Form/ViewsForm.php index 72ae38451920..02bf7cb3fc8f 100644 --- a/core/modules/views/src/Form/ViewsForm.php +++ b/core/modules/views/src/Form/ViewsForm.php @@ -16,7 +16,7 @@ use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\views\ViewExecutable; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Provides a base class for single- or multistep view forms. @@ -37,11 +37,11 @@ class ViewsForm implements FormInterface, ContainerInjectionInterface { protected $classResolver; /** - * The current request. + * The request stack. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * The url generator to generate the form action. @@ -71,17 +71,17 @@ class ViewsForm implements FormInterface, ContainerInjectionInterface { * The class resolver to get the subform form objects. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * The url generator to generate the form action. - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request. + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + * The request stack. * @param string $view_id * The ID of the view. * @param string $view_display_id * The ID of the active view's display. */ - public function __construct(ClassResolverInterface $controller_resolver, UrlGeneratorInterface $url_generator, Request $request, $view_id, $view_display_id) { + public function __construct(ClassResolverInterface $controller_resolver, UrlGeneratorInterface $url_generator, RequestStack $requestStack, $view_id, $view_display_id) { $this->classResolver = $controller_resolver; $this->urlGenerator = $url_generator; - $this->request = $request; + $this->requestStack = $requestStack; $this->viewId = $view_id; $this->viewDisplayId = $view_display_id; } @@ -93,7 +93,7 @@ public static function create(ContainerInterface $container, $view_id = NULL, $v return new static( $container->get('controller_resolver'), $container->get('url_generator'), - $container->get('request'), + $container->get('request_stack'), $view_id, $view_display_id ); @@ -127,7 +127,7 @@ public function buildForm(array $form, array &$form_state, ViewExecutable $view $form = array(); - $query = $this->request->query->all(); + $query = $this->requestStack->getCurrentRequest()->query->all(); $query = UrlHelper::filterQueryParameters($query, array(), ''); $form['#action'] = $this->urlGenerator->generateFromPath($view->getUrl(), array('query' => $query)); diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php index 712d1ae71d5f..0067ce3aa966 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php @@ -69,7 +69,7 @@ public function testPageResponses() { $this->assertEqual($response->getStatusCode(), 200); $subrequest = Request::create('/test_page_display_200', 'GET'); - \Drupal::getContainer()->set('request', $subrequest); + \Drupal::getContainer()->get('request_stack')->push($subrequest); // Test accessing a disabled page for a view. $view = Views::getView('test_page_display'); diff --git a/core/modules/views/src/Tests/ViewTestBase.php b/core/modules/views/src/Tests/ViewTestBase.php index 8527c4400805..82e42e20227e 100644 --- a/core/modules/views/src/Tests/ViewTestBase.php +++ b/core/modules/views/src/Tests/ViewTestBase.php @@ -232,7 +232,6 @@ protected function helperButtonHasLabel($id, $expected_label, $message = 'Label protected function executeView(ViewExecutable $view, $args = array()) { // A view does not really work outside of a request scope, due to many // dependencies like the current user. - $this->container->enterScope('request'); $view->setDisplay(); $view->preExecute($args); $view->execute(); diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 7d1060c28086..1603d814b802 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -120,7 +120,7 @@ function template_preprocess_views_view(&$variables) { } $container = \Drupal::getContainer(); - $form_object = new ViewsForm($container->get('class_resolver'), $container->get('url_generator'), $container->get('request'), $view->storage->id(), $view->current_display); + $form_object = new ViewsForm($container->get('class_resolver'), $container->get('url_generator'), $container->get('request_stack'), $view->storage->id(), $view->current_display); $form = \Drupal::formBuilder()->getForm($form_object, $view, $output); // The form is requesting that all non-essential views elements be hidden, // usually because the rendered step is not a view result. diff --git a/core/modules/views_ui/src/Tests/TagTest.php b/core/modules/views_ui/src/Tests/TagTest.php index 2e99440aad2f..65ce66cd4f04 100644 --- a/core/modules/views_ui/src/Tests/TagTest.php +++ b/core/modules/views_ui/src/Tests/TagTest.php @@ -41,7 +41,7 @@ public function testViewsUiAutocompleteTag() { // Make sure just ten results are returns. $controller = ViewsUIController::create($this->container); - $request = $this->container->get('request'); + $request = $this->container->get('request_stack')->getCurrentRequest(); $request->query->set('q', 'autocomplete_tag_test'); $result = $controller->autocompleteTag($request); $matches = (array) json_decode($result->getContent()); diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 5a4b23ceb6ba..bd276b9733a0 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -16,7 +16,7 @@ use Drupal\Core\Render\Element; use Drupal\user\TempStoreFactory; use Drupal\views\Views; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -34,21 +34,21 @@ class ViewEditForm extends ViewFormBase { /** * The request object. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * Constructs a new ViewEditForm object. * * @param \Drupal\user\TempStoreFactory $temp_store_factory * The factory for the temp store object. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + * The request stack object. */ - public function __construct(TempStoreFactory $temp_store_factory, Request $request) { + public function __construct(TempStoreFactory $temp_store_factory, RequestStack $requestStack) { $this->tempStore = $temp_store_factory->get('views'); - $this->request = $request; + $this->requestStack = $requestStack; } /** @@ -57,7 +57,7 @@ public function __construct(TempStoreFactory $temp_store_factory, Request $reque public static function create(ContainerInterface $container) { return new static( $container->get('user.tempstore'), - $container->get('request') + $container->get('request_stack') ); } @@ -292,7 +292,7 @@ public function submit(array $form, array &$form_state) { $view->set('display', $displays); // @todo: Revisit this when http://drupal.org/node/1668866 is in. - $query = $this->request->query; + $query = $this->requestStack->getCurrentRequest()->query; $destination = $query->get('destination'); if (!empty($destination)) { @@ -765,7 +765,7 @@ public function renderDisplayTop(ViewUI $view) { * should not yet redirect to the destination. */ public function submitDelayDestination($form, &$form_state) { - $query = $this->request->query; + $query = $this->requestStack->getCurrentRequest()->query; // @todo: Revisit this when http://drupal.org/node/1668866 is in. $destination = $query->get('destination'); if (isset($destination) && $form_state['redirect'] !== FALSE) { diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index 004067c1d6bc..5508fe0e2fb7 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -16,6 +16,7 @@ use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -82,6 +83,13 @@ class AccessManagerTest extends UnitTestCase { */ protected $argumentsResolver; + /** + * The request stack. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + /** * {@inheritdoc} */ @@ -122,7 +130,9 @@ protected function setUp() { $this->account = $this->getMock('Drupal\Core\Session\AccountInterface'); $this->argumentsResolver = $this->getMock('Drupal\Core\Access\AccessArgumentsResolverInterface'); - $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver); + $this->requestStack = new RequestStack(); + + $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver, $this->requestStack); $this->accessManager->setContainer($this->container); } @@ -151,7 +161,7 @@ public function testSetChecks() { */ public function testSetChecksWithDynamicAccessChecker() { // Setup the access manager. - $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver); + $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver, $this->requestStack); $this->accessManager->setContainer($this->container); // Setup the dynamic access checker. @@ -406,7 +416,7 @@ public function testCheckNamedRoute() { $this->assertTrue($this->accessManager->checkNamedRoute('test_route_4', array(), $this->account, $request)); // Tests the access with routes without given request. - $this->accessManager->setRequest(new Request()); + $this->requestStack->push(new Request()); $this->paramConverter->expects($this->at(0)) ->method('convert') @@ -453,9 +463,9 @@ public function testCheckNamedRouteWithUpcastedValues() { $subrequest = Request::create('/test-route-1/example'); - $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver); + $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver, $this->requestStack); $this->accessManager->setContainer($this->container); - $this->accessManager->setRequest(new Request()); + $this->requestStack->push(new Request()); $access_check = $this->getMock('Drupal\Tests\Core\Access\TestAccessCheckInterface'); $access_check->expects($this->any()) @@ -507,9 +517,9 @@ public function testCheckNamedRouteWithDefaultValue() { $subrequest = Request::create('/test-route-1/example'); - $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver); + $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver, $this->requestStack); $this->accessManager->setContainer($this->container); - $this->accessManager->setRequest(new Request()); + $this->requestStack->push(new Request()); $access_check = $this->getMock('Drupal\Tests\Core\Access\TestAccessCheckInterface'); $access_check->expects($this->any()) @@ -585,7 +595,7 @@ public function testCheckException($return_value, $access_mode) { ->will($this->returnValue($return_value)); $container->set('test_incorrect_value', $access_check); - $access_manager = new AccessManager($route_provider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver); + $access_manager = new AccessManager($route_provider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver, $this->requestStack); $access_manager->setContainer($container); $access_manager->addCheckService('test_incorrect_value', 'access'); @@ -640,7 +650,7 @@ protected static function convertAccessCheckInterfaceToString($constant) { * Adds a default access check service to the container and the access manager. */ protected function setupAccessChecker() { - $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver); + $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver, $this->requestStack); $this->accessManager->setContainer($this->container); $access_check = new DefaultAccessCheck(); $this->container->register('test_access_default', $access_check); diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php index 83bae6020b8c..a3f41142bf37 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php @@ -29,6 +29,9 @@ public function testSetOnSynchronizedService() { $container->register('bar', 'BarClass') ->addMethodCall('setBaz', array(new Reference('baz'))); + // Ensure that we can set services on a compiled container. + $container->compile(); + $container->set('baz', $baz = new \BazClass()); $this->assertSame($baz, $container->get('bar')->getBaz()); diff --git a/core/tests/Drupal/Tests/Core/DrupalTest.php b/core/tests/Drupal/Tests/Core/DrupalTest.php index 9e4c4b39488f..a254d4e10066 100644 --- a/core/tests/Drupal/Tests/Core/DrupalTest.php +++ b/core/tests/Drupal/Tests/Core/DrupalTest.php @@ -45,14 +45,6 @@ public function testService() { $this->assertNotNull(\Drupal::service('test_service')); } - /** - * Tests the service() method. - */ - public function testRequest() { - $this->setMockContainerService('request'); - $this->assertNotNull(\Drupal::request()); - } - /** * Tests the currentUser() method. */ diff --git a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php index 640ce9878334..a6c2e769d11b 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php +++ b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php @@ -129,7 +129,7 @@ abstract class FormTestBase extends UnitTestCase { protected $translationManager; /** - * @var \Drupal\Core\HttpKernel|\PHPUnit_Framework_MockObject_MockObject + * @var \Symfony\Component\HttpKernel\HttpKernel|\PHPUnit_Framework_MockObject_MockObject */ protected $httpKernel; @@ -153,7 +153,7 @@ public function setUp() { $this->csrfToken = $this->getMockBuilder('Drupal\Core\Access\CsrfTokenGenerator') ->disableOriginalConstructor() ->getMock(); - $this->httpKernel = $this->getMockBuilder('Drupal\Core\HttpKernel') + $this->httpKernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel') ->disableOriginalConstructor() ->getMock(); $this->account = $this->getMock('Drupal\Core\Session\AccountInterface'); diff --git a/core/tests/Drupal/Tests/Core/HttpKernelTest.php b/core/tests/Drupal/Tests/Core/HttpKernelTest.php deleted file mode 100644 index 4e5509c18266..000000000000 --- a/core/tests/Drupal/Tests/Core/HttpKernelTest.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\Tests\Core\HttpKernelTest. - */ - -namespace Drupal\Tests\Core; - -use Drupal\Core\Controller\ControllerResolver; -use Drupal\Core\DependencyInjection\ClassResolver; -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\HttpKernel; -use Drupal\Tests\UnitTestCase; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Component\DependencyInjection\Scope; -use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\KernelEvents; - -/** - * @coversDefaultClass \Drupal\Core\HttpKernel - * @group HttpKernelTest - */ -class HttpKernelTest extends UnitTestCase { - - /** - * Tests the forward method. - * - * @see \Drupal\Core\HttpKernel::setupSubrequest() - */ - public function testSetupSubrequest() { - $container = new ContainerBuilder(); - - $request = new Request(); - $container->addScope(new Scope('request')); - $container->enterScope('request'); - $container->set('request', $request, 'request'); - - $dispatcher = new EventDispatcher(); - $class_resolver = new ClassResolver(); - $class_resolver->setContainer($container); - $controller_resolver = new ControllerResolver($class_resolver); - - $http_kernel = new HttpKernel($dispatcher, $controller_resolver); - $http_kernel->setContainer($container); - - $test_controller = '\Drupal\Tests\Core\Controller\TestController'; - $random_attribute = $this->randomName(); - $subrequest = $http_kernel->setupSubrequest($test_controller, array('custom_attribute' => $random_attribute), array('custom_query' => $random_attribute)); - $this->assertNotSame($subrequest, $request, 'The subrequest is not the same as the main request.'); - $this->assertEquals($subrequest->attributes->get('custom_attribute'), $random_attribute, 'Attributes are set from the subrequest.'); - $this->assertEquals($subrequest->query->get('custom_query'), $random_attribute, 'Query attributes are set from the subrequest.'); - $this->assertEquals($subrequest->attributes->get('_controller'), $test_controller, 'Controller attribute got set.'); - - $subrequest = $http_kernel->setupSubrequest(NULL, array(), array()); - $this->assertFalse($subrequest->attributes->has('_controller'), 'Ensure that _controller is not copied when no controller was set before.'); - } - -} diff --git a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php index 00360c25b2d4..99c8689abc42 100644 --- a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php +++ b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php @@ -11,6 +11,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; // @todo Remove once watchdog() is removed. if (!defined('WATCHDOG_EMERGENCY')) { @@ -50,7 +51,7 @@ class LoggerChannelTest extends UnitTestCase { * @dataProvider providerTestLog * @covers ::log * @covers ::setCurrentUser - * @covers ::setRequest + * @covers ::setRequestStack */ public function testLog(callable $expected, Request $request = NULL, AccountInterface $current_user = NULL) { $channel = new LoggerChannel('test'); @@ -61,7 +62,9 @@ public function testLog(callable $expected, Request $request = NULL, AccountInte ->with($this->anything(), $message, $this->callback($expected)); $channel->addLogger($logger); if ($request) { - $channel->setRequest($request); + $requestStack = new RequestStack(); + $requestStack->push($request); + $channel->setRequestStack($requestStack); } if ($current_user) { $channel->setCurrentUser($current_user); @@ -116,10 +119,11 @@ function ($context) { return $context['channel'] == 'test' && empty($contex['uid']) && empty($context['ip']); }, ); - // With account but not request. + // With account but not request. Since the request is not available the + // current user should not be used. $cases [] = array( function ($context) { - return $context['uid'] === 1 && empty($context['ip']); + return $context['uid'] === 0 && empty($context['ip']); }, NULL, $account_mock, diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index bd56fa26ac11..03b7b0fcaf9a 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -13,6 +13,7 @@ use Drupal\Core\Site\Settings; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RequestContext; @@ -113,7 +114,7 @@ function setUp() { $this->aliasManager = $alias_manager; $context = new RequestContext(); - $context->fromRequest(Request::create('/some/path')); + $context->fromRequest($request = Request::create('/some/path')); $processor = new PathProcessorAlias($this->aliasManager); $processor_manager = new PathProcessorManager(); @@ -125,12 +126,15 @@ function setUp() { $config_factory_stub = $this->getConfigFactoryStub(array('system.filter' => array('protocols' => array('http', 'https')))); - $generator = new UrlGenerator($provider, $processor_manager, $this->routeProcessorManager, $config_factory_stub, new Settings(array())); + $requestStack = new RequestStack(); + $requestStack->push($request); + + $generator = new UrlGenerator($provider, $processor_manager, $this->routeProcessorManager, $config_factory_stub, new Settings(array()), NULL, $requestStack); $generator->setContext($context); $this->generator = $generator; // Second generator for mixed-mode sessions. - $generator = new UrlGenerator($provider, $processor_manager, $this->routeProcessorManager, $config_factory_stub, new Settings(array('mixed_mode_sessions' => TRUE))); + $generator = new UrlGenerator($provider, $processor_manager, $this->routeProcessorManager, $config_factory_stub, new Settings(array('mixed_mode_sessions' => TRUE)), NULL, $requestStack); $generator->setContext($context); $this->generatorMixedMode = $generator; } diff --git a/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php b/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php index e918fa4ed776..7bdb506af4db 100644 --- a/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php +++ b/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php @@ -12,6 +12,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Scope; +use Symfony\Component\HttpFoundation\RequestStack; /** * @coversDefaultClass \Drupal\Core\Session\AnonymousUserSession @@ -30,9 +31,9 @@ public function testAnonymousUserSessionWithRequest() { ->method('getClientIp') ->will($this->returnValue('test')); $container = new ContainerBuilder(); - $container->addScope(new Scope('request')); - $container->enterScope('request'); - $container->set('request', $request, 'request'); + $requestStack = new RequestStack(); + $requestStack->push($request); + $container->set('request_stack', $requestStack); \Drupal::setContainer($container); $anonymous_user = new AnonymousUserSession(); @@ -48,11 +49,6 @@ public function testAnonymousUserSessionWithRequest() { public function testAnonymousUserSessionWithNoRequest() { $container = new ContainerBuilder(); - // Set a synthetic 'request' definition on the container. - $definition = new Definition(); - $definition->setSynthetic(TRUE); - - $container->setDefinition('request', $definition); \Drupal::setContainer($container); $anonymous_user = new AnonymousUserSession(); -- GitLab