Verified Commit a058be43 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3431362 by Spokje, longwave: Remove support for ContainerAwareInterface

parent 5aaf92bb
Loading
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -37,8 +37,3 @@
%Since symfony/dependency-injection 6.4: "Symfony\\Component\\DependencyInjection\\ContainerAwareTrait" is deprecated, use dependency injection instead.%
%The "Drupal\\Core\\Logger\\LoggerChannelFactory" class implements "Symfony\\Component\\DependencyInjection\\ContainerAwareInterface" that is deprecated since Symfony 6.4, use dependency injection instead.%
%The "Drupal\\Core\\Logger\\LoggerChannelFactory" class uses "Symfony\\Component\\DependencyInjection\\ContainerAwareTrait" that is deprecated since Symfony 6.4, use dependency injection instead.%
%The "Drupal\\Core\\Queue\\QueueFactory" class implements "Symfony\\Component\\DependencyInjection\\ContainerAwareInterface" that is deprecated since Symfony 6.4, use dependency injection instead.%
%The "Drupal\\Core\\Queue\\QueueFactory" class uses "Symfony\\Component\\DependencyInjection\\ContainerAwareTrait" that is deprecated since Symfony 6.4, use dependency injection instead.%
%The "Drupal\\Tests\\Core\\Controller\\MockContainerAware" class implements "Symfony\\Component\\DependencyInjection\\ContainerAwareInterface" that is deprecated since Symfony 6.4, use dependency injection instead.%
%The "Drupal\\Tests\\Core\\DependencyInjection\\DependencySerializationTestDummy" class implements "Symfony\\Component\\DependencyInjection\\ContainerAwareInterface" that is deprecated since Symfony 6.4, use dependency injection instead.%
%The "Drupal\\Tests\\Core\\Utility\\MockContainerAware" class implements "Symfony\\Component\\DependencyInjection\\ContainerAwareInterface" that is deprecated since Symfony 6.4, use dependency injection instead.%
+0 −18
Original line number Diff line number Diff line
@@ -2264,24 +2264,12 @@
	'count' => 1,
	'path' => __DIR__ . '/tests/Drupal/Tests/Core/Config/ConfigTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Class Drupal\\\\Tests\\\\Core\\\\Controller\\\\MockContainerAware implements deprecated interface Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\:
since Symfony 6\\.4, use dependency injection instead$#',
	'count' => 1,
	'path' => __DIR__ . '/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Call to deprecated method expectError\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#',
	'count' => 1,
	'path' => __DIR__ . '/tests/Drupal/Tests/Core/Database/ConditionTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Class Drupal\\\\Tests\\\\Core\\\\DependencyInjection\\\\DependencySerializationTestDummy implements deprecated interface Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\:
since Symfony 6\\.4, use dependency injection instead$#',
	'count' => 1,
	'path' => __DIR__ . '/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Trying to mock an undefined method getRevisionId\\(\\) on class Drupal\\\\Tests\\\\Core\\\\Entity\\\\UrlTestEntity\\.$#',
	'count' => 1,
@@ -2374,12 +2362,6 @@
	'count' => 1,
	'path' => __DIR__ . '/tests/Drupal/Tests/Core/Test/AssertContentTraitTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Class Drupal\\\\Tests\\\\Core\\\\Utility\\\\MockContainerAware implements deprecated interface Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\:
since Symfony 6\\.4, use dependency injection instead$#',
	'count' => 1,
	'path' => __DIR__ . '/tests/Drupal/Tests/Core/Utility/CallableResolverTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Call to deprecated method getConfig\\(\\) of class GuzzleHttp\\\\ClientInterface\\:
ClientInterface\\:\\:getConfig will be removed in guzzlehttp/guzzle\\:8\\.0\\.$#',
+1 −6
Original line number Diff line number Diff line
@@ -10,12 +10,7 @@
/**
 * ControllerResolver to enhance controllers beyond Symfony's basic handling.
 *
 * It adds two behaviors:
 *
 *  - When creating a new object-based controller that implements
 *    ContainerAwareInterface, inject the container into it. While not always
 *    necessary, that allows a controller to vary the services it needs at
 *    runtime.
 * It adds one behavior:
 *
 *  - By default, a controller name follows the class::method notation. This
 *    class adds the possibility to use a service from the container as a
+2 −26
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\Core\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
@@ -15,14 +14,10 @@ class ClassResolver implements ClassResolverInterface {
  /**
   * Constructs a new ClassResolver object.
   *
   * @param \Symfony\Component\DependencyInjection\ContainerInterface|null $container
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   *   The service container.
   */
  public function __construct(protected ?ContainerInterface $container = NULL) {
    if ($this->container === NULL) {
      @trigger_error('Calling ' . __METHOD__ . ' without the $container argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3419963', E_USER_DEPRECATED);
      $this->container = \Drupal::getContainer();
    }
  public function __construct(protected ContainerInterface $container) {
  }

  /**
@@ -45,26 +40,7 @@ public function getInstanceFromDefinition($definition) {
      }
    }

    if ($instance instanceof ContainerAwareInterface) {
      @trigger_error('Implementing \Symfony\Component\DependencyInjection\ContainerAwareInterface is deprecated in drupal:10.3.0 and it will be removed in drupal:11.0.0. Implement \Drupal\Core\DependencyInjection\ContainerInjectionInterface and use dependency injection instead. See https://www.drupal.org/node/3428661', E_USER_DEPRECATED);
      $instance->setContainer($this->container);
    }

    return $instance;
  }

  /**
   * Sets the service container.
   *
   * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0.
   *    Instead, you should pass the container as an argument in the
   *    __construct() method.
   *
   * @see https://www.drupal.org/node/3419963
   */
  public function setContainer(?ContainerInterface $container): void {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Instead, you should pass the container as an argument in the __construct() method. See https://www.drupal.org/node/3419963', E_USER_DEPRECATED);
    $this->container = $container;
  }

}
+6 −39
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@
use Drupal\Core\Utility\CallableResolver;
use Drupal\Tests\UnitTestCase;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -52,12 +51,8 @@ protected function setUp(): void {
   * Tests createController().
   *
   * @dataProvider providerTestCreateController
   * @group legacy
   */
  public function testCreateController($controller, $class, $output, string $deprecation = NULL) {
    if ($deprecation) {
      $this->expectDeprecation($deprecation);
    }
  public function testCreateController($controller, $class, $output) {
    $this->container->set('some_service', new MockController());
    $result = $this->controllerResolver->getControllerFromDefinition($controller);
    $this->assertCallableController($result, $class, $output);
@@ -74,13 +69,6 @@ public static function providerTestCreateController() {
      ['some_service:getResult', 'Drupal\Tests\Core\Controller\MockController', 'This is a regular controller.'],
      // Tests a class with injection.
      ['Drupal\Tests\Core\Controller\MockContainerInjection::getResult', 'Drupal\Tests\Core\Controller\MockContainerInjection', 'This used injection.'],
      // Tests a ContainerAware class.
      [
        'Drupal\Tests\Core\Controller\MockContainerAware::getResult',
        'Drupal\Tests\Core\Controller\MockContainerAware',
        'This is container aware.',
        'Implementing \Symfony\Component\DependencyInjection\ContainerAwareInterface is deprecated in drupal:10.3.0 and it will be removed in drupal:11.0.0. Implement \Drupal\Core\DependencyInjection\ContainerInjectionInterface and use dependency injection instead. See https://www.drupal.org/node/3428661',
      ],
    ];
  }

@@ -104,12 +92,8 @@ public function testCreateControllerInvalidName() {
   * Tests getController().
   *
   * @dataProvider providerTestGetController
   * @group legacy
   */
  public function testGetController($attributes, $class, $output = NULL) {
    if ($class) {
      $this->expectDeprecation('Implementing \Symfony\Component\DependencyInjection\ContainerAwareInterface is deprecated in drupal:10.3.0 and it will be removed in drupal:11.0.0. Implement \Drupal\Core\DependencyInjection\ContainerInjectionInterface and use dependency injection instead. See https://www.drupal.org/node/3428661');
    }
    $request = new Request([], [], $attributes);
    $result = $this->controllerResolver->getController($request);
    if ($class) {
@@ -126,7 +110,11 @@ public function testGetController($attributes, $class, $output = NULL) {
  public static function providerTestGetController() {
    return [
      // Tests passing a controller via the request.
      [['_controller' => 'Drupal\Tests\Core\Controller\MockContainerAware::getResult'], 'Drupal\Tests\Core\Controller\MockContainerAware', 'This is container aware.'],
      [
        ['_controller' => MockContainerInjection::class . '::getResult'],
        MockContainerInjection::class,
        'This used injection.',
      ],
      // Tests a request with no controller specified.
      [[], FALSE],
    ];
@@ -232,28 +220,7 @@ public function getResult() {
  }

}
class MockContainerAware implements ContainerAwareInterface {

  /**
   * The service container.
   */
  protected ContainerInterface $container;

  /**
   * Sets the service container.
   */
  public function setContainer(?ContainerInterface $container): void {
    $this->container = $container;
  }

  public function getResult() {
    if (empty($this->container)) {
      throw new \Exception('Container was not injected.');
    }
    return 'This is container aware.';
  }

}
class MockInvokeController {

  public function __invoke() {
Loading