diff --git a/core/core.services.yml b/core/core.services.yml index 80d94f2..e009094 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -492,7 +492,7 @@ services: arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] plugin.manager.stream_wrapper: class: Drupal\Core\StreamWrapper\StreamWrapperManager - arguments: ['@container.namespaces', '@module_handler'] + arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] kernel_destruct_subscriber: class: Drupal\Core\EventSubscriber\KernelDestructionSubscriber tags: diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 6e271d5..338a3dd 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -996,7 +996,9 @@ function install_base_system(&$install_state) { // created by this point in the installer, since Drupal creates them during // the install_verify_requirements() task. Note that we cannot call // file_ensure_access() any earlier than this, since it relies on - // system.module in order to work. + // system.module in order to work. Flush stream wrapper plugins to make sure + // that we correctly discovered all stream wrapper plugins. + \Drupal::service('plugin.manager.stream_wrapper')->clearCachedDefinitions(); file_ensure_htaccess(); // Enable the user module so that sessions can be recorded during the diff --git a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php index 3d9fef8..e2780a7 100644 --- a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php @@ -8,7 +8,9 @@ namespace Drupal\Core\StreamWrapper; use Drupal\Component\Plugin\Exception\PluginException; +use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; /** @@ -33,13 +35,18 @@ class StreamWrapperManager extends DefaultPluginManager { * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations. + * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend + * Cache backend instance to use. + * @param \Drupal\Core\Language\LanguageManager $language_manager + * The language manager. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook with. */ - public function __construct(\Traversable $namespaces, ModuleHandlerInterface $module_handler) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { parent::__construct('StreamWrapper', $namespaces, array(), 'Drupal\Core\Annotation\StreamWrapper'); $this->alterInfo($module_handler, 'stream_wrappers'); + $this->setCacheBackend($cache_backend, $language_manager, 'stream_wrappers'); } /** @@ -95,6 +102,7 @@ public function getWrappers($filter = STREAM_WRAPPERS_ALL) { if (!$this->wrappers) { $wrappers = $this->getDefinitions(); foreach ($wrappers as $scheme => $info) { + $this->registerWrapper($info, $scheme); // Pre-populate the static cache with the filters most typically used. $this->wrappers[STREAM_WRAPPERS_ALL][$scheme] = $info; if (($info['type'] & STREAM_WRAPPERS_WRITE_VISIBLE) == STREAM_WRAPPERS_WRITE_VISIBLE) { @@ -117,11 +125,14 @@ public function getWrappers($filter = STREAM_WRAPPERS_ALL) { } /** - * {@inheritdoc} + * Registers stream wrapper with PHP. + * + * @param array $definition + * The stream wrapper definition. + * @param string $plugin_id + * The stream wrapper plugin ID. */ - public function processDefinition(&$definition, $plugin_id) { - parent::processDefinition($definition, $plugin_id); - + protected function registerWrapper(&$definition, $plugin_id) { // Record whether we are overriding an existing scheme. if (in_array($plugin_id, stream_get_wrappers(), TRUE)) { $definition['override'] = TRUE; @@ -166,4 +177,14 @@ public function getInstance(array $options) { } } + /** + * {@inheritdoc} + */ + public function clearCachedDefinitions() { + parent::clearCachedDefinitions(); + $this->wrappers = NULL; + // All stream wrappers must always be registered. + $this->getWrappers(); + } + } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/ReadOnlyStreamWrapperTest.php b/core/modules/system/lib/Drupal/system/Tests/File/ReadOnlyStreamWrapperTest.php index d043de5..18bb51c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/ReadOnlyStreamWrapperTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/ReadOnlyStreamWrapperTest.php @@ -20,7 +20,7 @@ class ReadOnlyStreamWrapperTest extends FileTestBase { public static $modules = array('file_test'); protected $scheme = 'dummy-readonly'; - protected $classname = 'Drupal\file_test\DummyReadOnlyStreamWrapper'; + protected $classname = 'Drupal\file_test\StreamWrapper\DummyReadOnlyStreamWrapper'; public static function getInfo() { return array( @@ -32,7 +32,7 @@ public static function getInfo() { function setUp() { parent::setUp(); - drupal_static_reset('file_get_stream_wrappers'); + $this->container->get('plugin.manager.stream_wrapper')->clearCachedDefinitions(); } function tearDown() { diff --git a/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php b/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php index 548f342..7098022 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php @@ -35,7 +35,7 @@ public static function getInfo() { function setUp() { parent::setUp(); - drupal_static_reset('file_get_stream_wrappers'); + $this->container->get('plugin.manager.stream_wrapper')->clearCachedDefinitions(); } function tearDown() {