Version 1
[yaffs-website] / web / core / lib / Drupal / Core / DependencyInjection / Compiler / RegisterStreamWrappersPass.php
diff --git a/web/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterStreamWrappersPass.php b/web/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterStreamWrappersPass.php
new file mode 100644 (file)
index 0000000..f1ea8cd
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace Drupal\Core\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+
+/**
+ * Adds services tagged 'stream_wrapper' to the stream_wrapper_manager service.
+ */
+class RegisterStreamWrappersPass implements CompilerPassInterface {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function process(ContainerBuilder $container) {
+    if (!$container->hasDefinition('stream_wrapper_manager')) {
+      return;
+    }
+
+    $stream_wrapper_manager = $container->getDefinition('stream_wrapper_manager');
+
+    foreach ($container->findTaggedServiceIds('stream_wrapper') as $id => $attributes) {
+      $class = $container->getDefinition($id)->getClass();
+      $scheme = $attributes[0]['scheme'];
+
+      $stream_wrapper_manager->addMethodCall('addStreamWrapper', [$id, $class, $scheme]);
+    }
+  }
+
+}