diff --git a/core/core.services.yml b/core/core.services.yml index c7a6bbf35a..a4dcd8642e 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1376,14 +1376,17 @@ services: class: Drupal\Core\StreamWrapper\ModuleStream tags: - { name: stream_wrapper, scheme: module } + arguments: ['@request_stack', '@module_handler'] stream_wrapper.theme: class: Drupal\Core\StreamWrapper\ThemeStream tags: - { name: stream_wrapper, scheme: theme } + arguments: ['@request_stack', '@theme_handler'] stream_wrapper.profile: class: Drupal\Core\StreamWrapper\ProfileStream tags: - { name: stream_wrapper, scheme: profile } + arguments: ['@request_stack', '@theme_handler', '%install_profile%'] kernel_destruct_subscriber: class: Drupal\Core\EventSubscriber\KernelDestructionSubscriber tags: diff --git a/core/lib/Drupal/Core/StreamWrapper/ExtensionStreamBase.php b/core/lib/Drupal/Core/StreamWrapper/ExtensionStreamBase.php index ae53a33efc..815a769207 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ExtensionStreamBase.php +++ b/core/lib/Drupal/Core/StreamWrapper/ExtensionStreamBase.php @@ -3,6 +3,7 @@ namespace Drupal\Core\StreamWrapper; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Symfony\Component\HttpFoundation\RequestStack; /** * Defines a base stream wrapper implementation. @@ -22,6 +23,16 @@ abstract class ExtensionStreamBase extends LocalReadOnlyStream { */ protected $requestStack; + /** + * Constructor. + * + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + * The request stack service. + */ + public function __construct(RequestStack $requestStack) { + $this->requestStack = $requestStack; + } + /** * {@inheritdoc} */ @@ -40,7 +51,7 @@ public static function getType() { * @return string * The extension name. */ - protected function getOwnerName() { + protected function getOwnerName(): string { $uri_parts = explode('://', $this->uri, 2); return strtok($uri_parts[1], '/'); } @@ -92,9 +103,6 @@ public function dirname($uri = NULL) { * The request stack object. */ protected function getRequestStack() { - if (!isset($this->requestStack)) { - $this->requestStack = \Drupal::service('request_stack'); - } return $this->requestStack; } diff --git a/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php b/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php index 1ab04755b8..e1dccaff72 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php @@ -2,6 +2,9 @@ namespace Drupal\Core\StreamWrapper; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Symfony\Component\HttpFoundation\RequestStack; + /** * Defines the read-only module:// stream wrapper for module files. * @@ -21,10 +24,23 @@ class ModuleStream extends ExtensionStreamBase { */ protected $moduleHandler; + /** + * Constructor. + * + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + * The request stack service. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler + * The module handler service. + */ + public function __construct(RequestStack $requestStack, ModuleHandlerInterface $moduleHandler) { + parent::__construct($requestStack); + $this->moduleHandler = $moduleHandler; + } + /** * {@inheritdoc} */ - protected function getOwnerName() { + protected function getOwnerName(): string { $name = parent::getOwnerName(); if (!$this->getModuleHandler()->moduleExists($name)) { // The module does not exist or is not installed. @@ -61,9 +77,6 @@ public function getDescription() { * The module handler service. */ protected function getModuleHandler() { - if (!isset($this->moduleHandler)) { - $this->moduleHandler = \Drupal::moduleHandler(); - } return $this->moduleHandler; } diff --git a/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php b/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php index f9c9322156..de5920abc6 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php @@ -2,6 +2,9 @@ namespace Drupal\Core\StreamWrapper; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Symfony\Component\HttpFoundation\RequestStack; + /** * Defines the read-only profile:// stream wrapper for installed profile files. * @@ -15,11 +18,33 @@ class ProfileStream extends ModuleStream { use LocalStreamTrait; + /** + * The install profile name. + * + * @var string + */ + protected $installProfile; + + /** + * ProfileStream constructor. + * + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + * The request stack service. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler + * The module handler service. + * @param string $install_profile + * The install profile. + */ + public function __construct(RequestStack $requestStack, ModuleHandlerInterface $moduleHandler, string $install_profile) { + parent::__construct($requestStack, $moduleHandler); + $this->installProfile = $install_profile; + } + /** * {@inheritdoc} */ - protected function getOwnerName() { - return \Drupal::installProfile(); + protected function getOwnerName(): string { + return $this->installProfile; } /** diff --git a/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php b/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php index ddcc1de76a..31b0b80b4a 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php @@ -2,10 +2,14 @@ namespace Drupal\Core\StreamWrapper; +use Drupal\Core\Extension\ThemeHandlerInterface; +use Symfony\Component\HttpFoundation\RequestStack; + /** * Defines the read-only theme:// stream wrapper for theme files. * * Usage: + * * @code * theme://{name} * @endcode @@ -21,10 +25,23 @@ class ThemeStream extends ExtensionStreamBase { */ protected $themeHandler; + /** + * Constructor. + * + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + * The request stack service. + * @param \Drupal\Core\Extension\ThemeHandlerInterface $themeHandler + * The theme handler service. + */ + public function __construct(RequestStack $requestStack, ThemeHandlerInterface $themeHandler) { + parent::__construct($requestStack); + $this->themeHandler = $themeHandler; + } + /** * {@inheritdoc} */ - protected function getOwnerName() { + protected function getOwnerName(): string { $name = parent::getOwnerName(); if (!$this->getThemeHandler()->themeExists($name)) { // The theme does not exist or is not installed. @@ -61,9 +78,6 @@ public function getDescription() { * The theme handler service. */ protected function getThemeHandler() { - if (!isset($this->themeHandler)) { - $this->themeHandler = \Drupal::service('theme_handler'); - } return $this->themeHandler; }