RegisterStreamWrappersPass.php 903 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Drupal\Core\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. /**
  6. * Adds services tagged 'stream_wrapper' to the stream_wrapper_manager service.
  7. */
  8. class RegisterStreamWrappersPass implements CompilerPassInterface {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function process(ContainerBuilder $container) {
  13. if (!$container->hasDefinition('stream_wrapper_manager')) {
  14. return;
  15. }
  16. $stream_wrapper_manager = $container->getDefinition('stream_wrapper_manager');
  17. foreach ($container->findTaggedServiceIds('stream_wrapper') as $id => $attributes) {
  18. $class = $container->getDefinition($id)->getClass();
  19. $scheme = $attributes[0]['scheme'];
  20. $stream_wrapper_manager->addMethodCall('addStreamWrapper', [$id, $class, $scheme]);
  21. }
  22. }
  23. }