diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php index b210a92..463ba34 100644 --- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php +++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php @@ -19,11 +19,9 @@ */ class ContainerBuilder extends SymfonyContainerBuilder { - public function __construct(ParameterBagInterface $parameterBag = null) - { - $this->setResourceTracking(false); - - parent::__construct($parameterBag); + public function __construct(ParameterBagInterface $parameterBag = null) { + $this->setResourceTracking(false); + parent::__construct($parameterBag); } /** diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php index 5d02543..8848d3f 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 @@ 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 = \Drupal::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/Logger/LoggerChannelFactory.php b/core/lib/Drupal/Core/Logger/LoggerChannelFactory.php index 98724ca..7d66887 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. diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php index 6f5dd45..a5684ff 100644 --- a/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -101,25 +101,28 @@ public function __construct(RouteProviderInterface $provider, OutboundPathProces $allowed_protocols = $config->get('system.filter')->get('protocols') ?: array('http', 'https'); UrlHelper::setAllowedProtocols($allowed_protocols); $this->requestStack = $requestStack; - $this->updateRequest(); + $this->updateFromRequest(); } - // @todo this should probably be inline in the constructor as this is only - // useful to get some current tests pass - public function updateRequest() - { - $request = $this->requestStack->getCurrentRequest(); - // Set some properties, based on the request, that are used during path-based - // url generation. - $this->basePath = $request->getBasePath() . '/'; - $this->baseUrl = $request->getSchemeAndHttpHost() . $this->basePath; - $this->scriptPath = ''; - $base_path_with_script = $request->getBaseUrl(); - $script_name = $request->getScriptName(); - if (!empty($base_path_with_script) && strpos($base_path_with_script, $script_name) !== FALSE) { - $length = strlen($this->basePath); - $this->scriptPath = ltrim(substr($script_name, $length), '/') . '/'; - } + /** + * 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 updateFromRequest() { + $request = $this->requestStack->getCurrentRequest(); + // Set some properties, based on the request, that are used during path-based + // url generation. + $this->basePath = $request->getBasePath() . '/'; + $this->baseUrl = $request->getSchemeAndHttpHost() . $this->basePath; + $this->scriptPath = ''; + $base_path_with_script = $request->getBaseUrl(); + $script_name = $request->getScriptName(); + if (!empty($base_path_with_script) && strpos($base_path_with_script, $script_name) !== FALSE) { + $length = strlen($this->basePath); + $this->scriptPath = ltrim(substr($script_name, $length), '/') . '/'; + } } /** diff --git a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php index 6a7158a..7a7448f 100644 --- a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php +++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php @@ -11,7 +11,6 @@ use Drupal\book\BookManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; /** * Provides a 'Book navigation' block. @@ -27,9 +26,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 +46,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 +66,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('request_stack')->getCurrentRequest(), + $container->get('request_stack'), $container->get('book.manager') ); } @@ -113,7 +112,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 +172,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/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index fd6f683..ac2f0a0 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -2695,7 +2695,7 @@ protected function prepareRequestForGenerator($clean_urls = TRUE, $override_serv $request = Request::create($request_path, 'GET', array(), array(), array(), $server); $this->container->get('request_stack')->push($request); - $generator->updateRequest(); + $generator->updateFromRequest(); return $request; } }