-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proof-of-Concept: Implementation of an ApplicationPipeline
class for better static code analysis
#107
Conversation
0b470f6
to
276bf12
Compare
I frequently create "Marker Interfaces" for app specific pipelines that are simply |
I would prefer having the whole pipeline retrievable via So I'd be open to add another service to reference In order to these changes, the following needs to be done to this PR:
In v4.0.0 we can drop all WDYT? |
Sorry if I'm adding noise here. I think I misunderstood the ultimate goal of getting rid of |
276bf12
to
f52102f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, don't see any problems/defects in the patch, but what I'm missing is why this is needed :|
Is this so that downstream consumers can use @var ApplicationPipeline $pipeline
, with better type-hinted methods? If we mark it @internal
, it doesn't really help then :D
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
final class ApplicationPipeline implements MiddlewarePipeInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this @internal
? If it's a PoC, that allows us to modify it in future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document the purpose of this class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can not mark it as @internal
as static analysis might report InternalClassUsage
when used in a dependency configuration (in delegators
).
Actually, the class does not exist (but is being retrieved from the container) and therefore it might be used in upstream projects already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about deprecating it to make sure that with 4.0.0, this "service" will be replaced with the MiddlewarePipeInterface
.
Hm, but well, deprecation will also trigger psalm issue 😂
*/ | ||
public function __clone() | ||
{ | ||
$this->pipeline = clone $this->pipeline; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test this cloning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, |
I don't get why this is needed. What is the use case for this? |
The use-case is, that we get rid of magic services which do not represent actual classes but in-fact do provide a service via the container. Using FQCN are way more helpful than using random strings. Given the fact, that some1 might want to decorate the application pipeline (whyever), one has to create a delegator for that non-FQCN (but namespaced, why the heck is it namespaced when its not an actual class anyways?) service name and then still needs to search in the source code what kind of service is actually returned. Maybe this makes it clear:
We already use it as FQCN but it is not a class which does exist. Therefore, thats not really helpful when it comes to IDE autocompletion and stuff. And this: Lines 10 to 14 in 9d12898
|
…es in mezzio projects This also reduces the baseline a little as we do not have a reference to a non-existing class anymore. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
f52102f
to
a59a70b
Compare
This also adds the purpose of the application pipeline implementation. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a thought: instead of introducing a new class, we could:
- Map
Laminas\Stratigility\MiddlewarePipeInterface
to theApplicationPipelineFactory
- Alias the existing
ApplicationPipeline
service toMiddlewarePipeInterface
- Add migration documentation suggesting that if users want to substitute an alternative application pipeline, they map it to
MiddlewarePipeInterface
instead ofApplicationPipeline
- Remove the
ApplicationPipeline
service in v4.
This eliminates the need for a proxy class such as you've proposed, and accomplishes the same thing with regards to static analysis.
As-is, I'm "meh" for this patch
Changing service names in minors always leads to delegator registration issues. Project config 3.10.X: $config = [
'dependencies' => [
'delegators' => [
'Mezzio\ApplicationPipeline' => [
static function (ContainerInterface $container, string $requestedName, callable $pipelineFactory) {
$pipeline = $pipelineFactory();
$pipeline->pipe(MyMiddleware::class);
return $pipeline;
}
],
],
],
]; Project config 3.11.X: $config = [
'dependencies' => [
'delegators' => [
'Laminas\Stratigility\MiddlewarePipeInterface' => [
static function (ContainerInterface $container, string $requestedName, callable $pipelineFactory) {
$pipeline = $pipelineFactory();
$pipeline->pipe(MyMiddleware::class);
return $pipeline;
}
],
],
],
]; Thus said, this would introduce a massive BC break to applications (from what I can see). |
Description
As requested in #105, this provides an
ApplicationPipeline
implementation which fits directly in theMiddlewarePipeInterface
withinApplication#__construct
.However, in a very strict PoV, this introduces a BC break when applications do directly check for
MiddlewarePipe
implementation rather thanMiddlewarePipeInterface
. Not sure if we need to address this as working with concrete implementations is not suggested, but I wanted to drop that information here so we can decide on how to proceed.I'd be also fine to target 4.0.0 with this.
closes #105