Commit cf89a29c authored by catch's avatar catch
Browse files

Issue #3261265 by andypost, longwave: Remove deprecated MimeTypeGuesser code

parent 37a10582
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1585,6 +1585,8 @@ services:
  file.mime_type.guesser:
    class: Drupal\Core\File\MimeType\MimeTypeGuesser
    arguments: ['@stream_wrapper_manager']
    tags:
      - { name: service_collector, tag: mime_type_guesser, call: addMimeTypeGuesser }
    lazy: true
  file.mime_type.guesser.extension:
    class: Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser
+0 −2
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\Compiler\ModifyServiceDefinitionsPass;
use Drupal\Core\DependencyInjection\Compiler\MimeTypePass;
use Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterAccessChecksPass;
@@ -74,7 +73,6 @@ public function register(ContainerBuilder $container) {

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

+0 −58
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Mime\MimeTypeGuesserInterface;

/**
 * Adds @mime_type_guesser tagged services to handle forwards compatibility.
 *
 * @internal
 *
 * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct
 * replacement is provided.
 *
 * @see https://www.drupal.org/node/3133341
 */
class MimeTypePass implements CompilerPassInterface {

  /**
   * {@inheritdoc}
   */
  public function process(ContainerBuilder $container) {
    $consumer = $container->getDefinition('file.mime_type.guesser');

    $tag = 'mime_type_guesser';
    $interface = MimeTypeGuesserInterface::class;

    // Find all tagged handlers.
    $handlers = [];
    foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) {
      // Validate the interface.
      $handler = $container->getDefinition($id);
      if (!is_subclass_of($handler->getClass(), $interface)) {
        throw new LogicException("Service '$id' does not implement $interface.");
      }
      $handlers[$id] = $attributes[0]['priority'] ?? 0;
      $interfaces[$id] = $handler->getClass();
    }
    if (empty($handlers)) {
      throw new LogicException(sprintf("At least one service tagged with '%s' is required.", $tag));
    }

    // Sort all handlers by priority.
    arsort($handlers, SORT_NUMERIC);

    // Add a method call for each handler to the consumer service
    // definition.
    foreach ($handlers as $id => $priority) {
      $arguments = [new Reference($id), $priority];
      $consumer->addMethodCall('addMimeTypeGuesser', $arguments);
    }
  }

}
+0 −8
Original line number Diff line number Diff line
@@ -885,14 +885,6 @@ public function __construct(ModuleHandlerInterface $module_handler) {
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public function guess($path) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use ::guessMimeType() instead. See https://www.drupal.org/node/3133341', E_USER_DEPRECATED);
    return $this->guessMimeType($path);
  }

  /**
   * {@inheritdoc}
   */
+0 −8
Original line number Diff line number Diff line
@@ -74,14 +74,6 @@ public function guessMimeType(string $path) : ?string {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function guess($path) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use ::guessMimeType() instead. See https://www.drupal.org/node/3133341', E_USER_DEPRECATED);
    return $this->guessMimeType($path);
  }

  /**
   * Appends a MIME type guesser to the guessers chain.
   *
Loading