From c21992c1b0960e11cea2c1351c3682a3e42c49c8 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 29 Apr 2024 18:40:15 +0100 Subject: [PATCH] Issue #3443492 by smustgrave, quietone, mikelutz: Remove deprecated code from lib/Routing --- .../lib/Drupal/Core/Routing/MatcherDumper.php | 39 ++-------- .../Drupal/Core/Routing/RoutePreloader.php | 26 ++----- .../Core/Routing/LegacyMatcherDumperTest.php | 76 ------------------- .../Tests/Core/Routing/RoutePreloaderTest.php | 8 -- 4 files changed, 12 insertions(+), 137 deletions(-) delete mode 100644 core/tests/Drupal/KernelTests/Core/Routing/LegacyMatcherDumperTest.php diff --git a/core/lib/Drupal/Core/Routing/MatcherDumper.php b/core/lib/Drupal/Core/Routing/MatcherDumper.php index cbd3aac0d04..0e15546bb3a 100644 --- a/core/lib/Drupal/Core/Routing/MatcherDumper.php +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php @@ -17,13 +17,6 @@ use Drupal\Core\Database\Connection; */ class MatcherDumper implements MatcherDumperInterface { - /** - * The database connection to which to dump route information. - * - * @var \Drupal\Core\Database\Connection - */ - protected $connection; - /** * The routes to be dumped. * @@ -31,12 +24,6 @@ class MatcherDumper implements MatcherDumperInterface { */ protected $routes; - /** - * The state. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; /** * The name of the SQL table to which to dump the routes. @@ -45,13 +32,6 @@ class MatcherDumper implements MatcherDumperInterface { */ protected $tableName; - /** - * The logger. - * - * @var \Psr\Log\LoggerInterface - */ - protected LoggerInterface $logger; - /** * Construct the MatcherDumper. * @@ -60,22 +40,17 @@ class MatcherDumper implements MatcherDumperInterface { * information. * @param \Drupal\Core\State\StateInterface $state * The state. - * @param \Psr\Log\LoggerInterface|null $logger + * @param \Psr\Log\LoggerInterface $logger * The logger. * @param string $table * (optional) The table to store the route info in. Defaults to 'router'. */ - public function __construct(Connection $connection, StateInterface $state, LoggerInterface|string|null $logger = NULL, $table = 'router') { - $this->connection = $connection; - $this->state = $state; - if (is_string($logger) || is_null($logger)) { - @trigger_error('Calling ' . __METHOD__ . '() without the $logger argument is deprecated in drupal:10.1.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/2932520', E_USER_DEPRECATED); - $this->logger = \Drupal::service('logger.channel.router'); - $this->tableName = $logger; - } - else { - $this->logger = $logger; - } + public function __construct( + protected Connection $connection, + protected StateInterface $state, + protected LoggerInterface $logger, + protected $table = 'router', + ) { if (is_null($this->tableName)) { $this->tableName = $table; } diff --git a/core/lib/Drupal/Core/Routing/RoutePreloader.php b/core/lib/Drupal/Core/Routing/RoutePreloader.php index 9748980965e..97536ca088b 100644 --- a/core/lib/Drupal/Core/Routing/RoutePreloader.php +++ b/core/lib/Drupal/Core/Routing/RoutePreloader.php @@ -17,20 +17,6 @@ use Symfony\Component\Routing\Route; */ class RoutePreloader implements EventSubscriberInterface { - /** - * The route provider. - * - * @var \Drupal\Core\Routing\RouteProviderInterface|\Drupal\Core\Routing\PreloadableRouteProviderInterface - */ - protected $routeProvider; - - /** - * The state key value store. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - /** * Contains the non-admin routes while rebuilding the routes. * @@ -41,17 +27,15 @@ class RoutePreloader implements EventSubscriberInterface { /** * Constructs a new RoutePreloader. * - * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider + * @param \Drupal\Core\Routing\RouteProviderInterface $routeProvider * The route provider. * @param \Drupal\Core\State\StateInterface $state * The state key value store. */ - public function __construct(RouteProviderInterface $route_provider, StateInterface $state) { - $this->routeProvider = $route_provider; - $this->state = $state; - if (func_num_args() > 2) { - @trigger_error(sprintf('Passing a cache bin to %s is deprecated in drupal:10.3.0 and will be removed before drupal:11.0.0. Caching is now managed by the state service. See https://www.drupal.org/node/3177901', __METHOD__), E_USER_DEPRECATED); - } + public function __construct( + protected RouteProviderInterface $routeProvider, + protected StateInterface $state, + ) { } /** diff --git a/core/tests/Drupal/KernelTests/Core/Routing/LegacyMatcherDumperTest.php b/core/tests/Drupal/KernelTests/Core/Routing/LegacyMatcherDumperTest.php deleted file mode 100644 index 644b824b742..00000000000 --- a/core/tests/Drupal/KernelTests/Core/Routing/LegacyMatcherDumperTest.php +++ /dev/null @@ -1,76 +0,0 @@ -connection = $this->createMock(Connection::class); - $this->state = $this->createMock(State::class); - } - - /** - * Tests the constructor deprecations. - */ - public function testConstructorDeprecationNoLogger() { - $this->expectDeprecation('Calling Drupal\Core\Routing\MatcherDumper::__construct() without the $logger argument is deprecated in drupal:10.1.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/2932520'); - $dumper = new MatcherDumper($this->connection, $this->state); - $this->assertNotNull($dumper); - } - - /** - * Tests the constructor deprecations. - */ - public function testConstructorDeprecationWithLegacyTableNameParam() { - $this->expectDeprecation('Calling Drupal\Core\Routing\MatcherDumper::__construct() without the $logger argument is deprecated in drupal:10.1.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/2932520'); - $dumper = new MatcherDumper($this->connection, $this->state, 'foo'); - $this->assertNotNull($dumper); - } - - /** - * Tests the constructor deprecations. - */ - public function testConstructorDeprecationWithLogger() { - $logger = $this->createMock(LoggerInterface::class); - $dumper = new MatcherDumper($this->connection, $this->state, $logger); - $this->assertNotNull($dumper); - - $logger = $this->createMock(LoggerInterface::class); - $dumper = new MatcherDumper($this->connection, $this->state, $logger, 'foo'); - $this->assertNotNull($dumper); - } - -} diff --git a/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php b/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php index 796844a6cbe..a18b0a80af3 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php @@ -176,12 +176,4 @@ class RoutePreloaderTest extends UnitTestCase { $this->preloader->onRequest($event); } - /** - * @group legacy - */ - public function testConstructorDeprecation() { - $this->expectDeprecation('Passing a cache bin to Drupal\Core\Routing\RoutePreloader::__construct is deprecated in drupal:10.3.0 and will be removed before drupal:11.0.0. Caching is now managed by the state service. See https://www.drupal.org/node/3177901'); - new RoutePreloader($this->routeProvider, $this->state, $this->createMock('Drupal\Core\Cache\CacheBackendInterface')); - } - }