Services\SessionLimit should type-hint dependencies using interfaces

Created on 8 September 2022, about 2 years ago
Updated 28 July 2024, 4 months ago

Session Limit's \Drupal\session_limit\Services\SessionLimit class currently type-hints the default ModuleHandler class instead of the interface. This prevents custom overrides of ModuleHandler, for example by Hux and Hook Event Dispatcher .

Problem/Motivation

Updated Hook Event Dispatcher from 3.2.0 to 3.3.1 , now getting fatal errors like this:

The website encountered an unexpected error. Please try again later.
TypeError: Drupal\session_limit\Services\SessionLimit::__construct(): Argument #6 ($moduleHandler) must be of type Drupal\Core\Extension\ModuleHandler, Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler given, called in E:\Web\Omnipedia\Web\drupal\core\lib\Drupal\Component\DependencyInjection\Container.php on line 262 in Drupal\session_limit\Services\SessionLimit->__construct() (line 119 of modules\contrib\session_limit\src\Services\SessionLimit.php).

Drupal\session_limit\Services\SessionLimit->__construct(Object, Object, Object, Object, Object, Object, Object, Object) (Line: 262)
Drupal\Component\DependencyInjection\Container->createService(Array, 'session_limit') (Line: 176)
Drupal\Component\DependencyInjection\Container->get('session_limit') (Line: 136)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.request') (Line: 134)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 49)
Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Install Hook Event Dispatcher 3.3.0+ after installing any module that injects the module_handler service with the parameter being type-hinted to the core ModuleHandler class instead of ModuleHandlerInterface. This should result in a similar fatal error to the above. The module in the error is Session Limit , and the error causing parameter can be found in Services/SessionLimit::__construct()

Proposed resolution

Change type-hint from the default service implementation \Drupal\Core\Extension\ModuleHandler to the interface \Drupal\Core\Extension\ModuleHandlerInterface.

Remaining tasks

Make the changes above.

User interface changes

None.

API changes

Unsure?

Data model changes

None?

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇨🇦Canada ambient.impact Toronto

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024