Unverified Commit 1ee7cb4e authored by Alex Pott's avatar Alex Pott
Browse files

task: #3571094 Remove RegisterStreamWrappersPass

By: longwave
(cherry picked from commit a4cda857)
parent 643d4cd1
Loading
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -10159,12 +10159,6 @@
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\StreamWrapper\\\\StreamWrapperManager\\:\\:addStreamWrapper\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\StreamWrapper\\\\StreamWrapperManager\\:\\:register\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+1 −0
Original line number Diff line number Diff line
@@ -1554,6 +1554,7 @@ services:
  Drupal\Core\Render\ElementInfoManagerInterface: '@plugin.manager.element_info'
  stream_wrapper_manager:
    class: Drupal\Core\StreamWrapper\StreamWrapperManager
    autowire: true
  Drupal\Core\StreamWrapper\StreamWrapperManagerInterface: '@stream_wrapper_manager'
  stream_wrapper.assets:
    class: Drupal\Core\StreamWrapper\AssetsStream
+0 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
use Drupal\Core\DependencyInjection\Compiler\RegisterAccessChecksPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterServicesForDestructionPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterStreamWrappersPass;
use Drupal\Core\DependencyInjection\Compiler\StackedKernelPass;
use Drupal\Core\DependencyInjection\Compiler\StackedSessionHandlerPass;
use Drupal\Core\DependencyInjection\Compiler\SuperUserAccessPolicyPass;
@@ -91,7 +90,6 @@ public function register(ContainerBuilder $container) {

    // Collect tagged handler services as method calls on consumer services.
    $container->addCompilerPass(new TaggedHandlersPass());
    $container->addCompilerPass(new RegisterStreamWrappersPass());
    $container->addCompilerPass(new TwigExtensionPass());

    // Add a compiler pass for registering event subscribers.
+0 −42
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Adds services tagged 'stream_wrapper' to the stream_wrapper_manager service.
 */
class RegisterStreamWrappersPass implements CompilerPassInterface {

  /**
   * {@inheritdoc}
   */
  public function process(ContainerBuilder $container): void {
    if (!$container->hasDefinition('stream_wrapper_manager')) {
      return;
    }

    $stream_wrapper_manager = $container->getDefinition('stream_wrapper_manager');

    $services = [];
    foreach ($container->findTaggedServiceIds('stream_wrapper') as $id => $tags) {
      $class = $container->getDefinition($id)->getClass();
      // Loop through all the tags for this stream wrapper as we may have
      // multiple schemes.
      foreach ($tags as $attributes) {
        $stream_wrapper_manager->addMethodCall('addStreamWrapper', [
          $id,
          $class,
          $attributes['scheme'],
        ]);
      }
      $services[$id] = new Reference($id);
    }
    $stream_wrapper_manager->addArgument(ServiceLocatorTagPass::register($container, $services));
  }

}
+13 −43
Original line number Diff line number Diff line
@@ -3,7 +3,8 @@
namespace Drupal\Core\StreamWrapper;

use Drupal\Core\Site\Settings;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
use Symfony\Component\DependencyInjection\ServiceLocator;

/**
 * Provides a StreamWrapper manager.
@@ -15,24 +16,14 @@ class StreamWrapperManager implements StreamWrapperManagerInterface {
  /**
   * Constructs a StreamWrapperManager object.
   *
   * @param \Psr\Container\ContainerInterface $container
   *   The stream wrapper service locator.
   * @param \Symfony\Component\DependencyInjection\ServiceLocator $container
   *   A service locator containing stream wrapper services, keyed by scheme.
   */
  public function __construct(
    protected readonly ContainerInterface $container,
    #[AutowireLocator('stream_wrapper', indexAttribute: 'scheme')]
    protected readonly ServiceLocator $container,
  ) {}

  /**
   * Contains stream wrapper info.
   *
   * An associative array where keys are scheme names and values are themselves
   * associative arrays with the keys class, type and (optionally) service_id,
   * and string values.
   *
   * @var array
   */
  protected $info = [];

  /**
   * Contains collected stream wrappers.
   *
@@ -42,7 +33,6 @@ public function __construct(
   *   - class: stream wrapper class name
   *   - type: a bitmask corresponding to the type constants in
   *     StreamWrapperInterface
   *   - service_id: name of service
   *
   * The array on key StreamWrapperInterface::ALL contains representations of
   * all schemes and corresponding wrappers.
@@ -116,10 +106,9 @@ public function getViaUri($uri) {
   * {@inheritdoc}
   */
  public function getClass($scheme) {
    if (isset($this->info[$scheme])) {
      return $this->info[$scheme]['class'];
    if ($this->container->has($scheme)) {
      return get_class($this->container->get($scheme));
    }

    return FALSE;
  }

@@ -135,8 +124,8 @@ public function getClass($scheme) {
   *   A stream wrapper object, or false if the scheme is not available.
   */
  protected function getWrapper($scheme, $uri) {
    if (isset($this->info[$scheme]['service_id'])) {
      $instance = $this->container->get($this->info[$scheme]['service_id']);
    if ($this->container->has($scheme)) {
      $instance = $this->container->get($scheme);
      $instance->setUri($uri);
      return $instance;
    }
@@ -144,34 +133,15 @@ protected function getWrapper($scheme, $uri) {
    return FALSE;
  }

  /**
   * Adds a stream wrapper.
   *
   * Internal use only.
   *
   * @param string $service_id
   *   The service id.
   * @param string $class
   *   The stream wrapper class.
   * @param string $scheme
   *   The scheme for which the wrapper should be registered.
   */
  public function addStreamWrapper($service_id, $class, $scheme) {
    $this->info[$scheme] = [
      'class' => $class,
      'type' => $class::getType(),
      'service_id' => $service_id,
    ];
  }

  /**
   * Registers the tagged stream wrappers.
   *
   * Internal use only.
   */
  public function register() {
    foreach ($this->info as $scheme => $info) {
      $this->registerWrapper($scheme, $info['class'], $info['type']);
    foreach (array_keys($this->container->getProvidedServices()) as $scheme) {
      $class = $this->getClass($scheme);
      $this->registerWrapper($scheme, $class, $class::getType());
    }
  }

Loading