Problem/Motivation
When collecting services (using the service collector provided by TaggedHandlersPass
), the consumer service method called MUST provide a type-hinted parameter (that will receive the tagged services).
First of all, this is not stated anywhere in the documentation (see:
https://www.drupal.org/docs/8/api/services-and-dependency-injection/serv... β
). The documentation simply states that the first parameter of the method will be passed the tagged service.
Instead, if you look at the code (https://github.com/drupal/drupal/blob/8.3.x/core/lib/Drupal/Core/Depende...), you will notice that the expected interface is actually the last one in the method signature.
So basically, if you want to call a method like:
public function callMe(Extension $extension, $id, SomeService $service = null)
the TaggedHandlersPass
will actually fail (because it will expect that all tagged services are of type SomeService
when in reality, they should be of type Extension
.
Secondly, this is an "annoyance" to most users. I'm currently trying to create a Stratigility middleware pipe service in Drupal. I want stratigility middleware services to be automatically piped to the middleware pipe. To do this, I wrote:
stratigility_pipe:
class: Zend\Stratigility\MiddlewarePipe
calls:
- [raiseThrowables, []]
tags:
- { name: service_collector, tag: http_interop_middleware, call: pipe }
But unfortunately, the "pipe" method of MiddlewarePipe
has a signature with no type hint (https://github.com/zendframework/zend-stratigility/blob/master/src/Middl...).
And Drupal forces the method handling the signature to have a type hint. IMHO, there is really no good reason for this. Type-hinting the service in the method should not be compulsory (as this forces users relying on third party code to write a useless wrapper).
Proposed resolution
Let's completely get rid of forcing the collector service method to provide a type-hint. This is not documented and is actually harmful as it can require user to write useless boilerplate code.
Also, if there is a type-hint, let's solve the bug that makes the TaggedHandlersPass
crash if it is given a method with 2 type hints.