Skip to content
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

Add PSR-17 StreamFactoryInterface Support in ImplicitHeadMiddleware #48

Merged
merged 6 commits into from
Apr 24, 2023

Conversation

gsteel
Copy link
Member

@gsteel gsteel commented Mar 29, 2023

Q A
BC Break yes
New Feature yes

Description

Replaces all callable parameters and properties with StreamFactoryInterface and ResponseFactoryInterface where appropriate and removes the callable compatability layer.

Closes #29

@gsteel gsteel added BC Break Enhancement New feature or request labels Mar 29, 2023
@gsteel gsteel added this to the 4.0.0 milestone Mar 29, 2023
@froschdesign
Copy link
Member

@gsteel
The target branch 4.0.x is missing.

@gsteel
Copy link
Member Author

gsteel commented Mar 29, 2023

The target branch 4.0.x is missing.

I'll create the branch if this is approved 👍

@boesing
Copy link
Member

boesing commented Mar 29, 2023

Can we please go with the logic as in https://github.com/mezzio/mezzio-authorization/pull/11/files?
Forward compatibility in current major versions should be the goal to reduce the amount of pain when migrating to new majors.
We can fix our internal types in the next major version but until then, providing support for both callable and the factory interfaces is doable. There are some caveats (i.e. due to the aliases / delegators registered in upstream projects - also initializers but I forgot these in the other components already) but IMHO worth doing so.

@gsteel
Copy link
Member Author

gsteel commented Mar 29, 2023

I'm not sure I understand the point of preserving support for callables @boesing - As this lib is only useful to a Mezzio app, it's most likely that Stream|Response factories are already wired up in the container via Diactoros, making migration a zero effort chore.

The callable response decorator was already deprecated, and I'll have to introduce a callable stream decorator to satisfy StreamFactoryInterface which in turn will create a hard dependency on Diactoros' StreamFactory so that createStreamFromFile etc can be implemented.

I thought that this patch was more about removing support for callables than adding PSR-17 because at least ResponseFactoryInterface has been supported for quite a while now???

@boesing
Copy link
Member

boesing commented Mar 29, 2023

I thought that this patch was more about removing support for callables than adding PSR-17 because at least ResponseFactoryInterface has been supported for quite a while now???

It is not supported in this component for quite a while and thus I dont understand why you think it is already supported.
The whole point of introducing PSR-17 is that we provide the possibility from within all the components before we require upstream to provide PSR-17.
Just because you have laminas/laminas-diactoros required does not mean that you automatically have its config provider registered (which would be required to have the factory interfaces available via $container - or upstream registered manually all the factory interfaces which is most likely not the case as it is not required to do so in mezzio v3).
Furthermore, diactoros is not required in mezzio, you can use nyholm/psr7 which (AFAIR) does not provide any PSR-17 factories provides PSR-17 factories but would require configuration changes to actually register all the factory interfaces to the nyholm/psr7 PSR-17 factory).

So overall, adding support for both makes sense as a first step while dropping support in next major.
Starting with mezzio v4, I'd expect all components do support PSR-17 as there won't be any callable registered anymore.

But maybe I am missing something, can you probably elaborate why you think that there is already PSR-17 support in this component?


So all I want to say is, I spent quite a lot of time in providing proper forward compatibility for PSR-17 so that we can switch to full PSR-17 in the next major. All I want is that we provide compatibility layer in mezzio-router v3 so that we can do this change (so the change in this PR) in mezzio-router v4.

Replaces all callable parameters and properties with `StreamFactoryInterface` and `ResponseFactoryInterface` where appropriate and removes the callable compatability layer.

Closes mezzio#29

Signed-off-by: George Steel <george@net-glue.co.uk>
This reverts commit c127396.

Signed-off-by: George Steel <george@net-glue.co.uk>
…ctoryInterface` where appropriate

Signed-off-by: George Steel <george@net-glue.co.uk>
@gsteel
Copy link
Member Author

gsteel commented Mar 29, 2023

@boesing - I reverted the patch and added compatibility for StreamFactoryInterface - I was actually targeting 4 here, so I think I understand now that whilst the response factory was already supported here, the stream factory was still outstanding for the 3.x series. I will revert a couple more things here so that this can go into 3.x

Signed-off-by: George Steel <george@net-glue.co.uk>
@gsteel gsteel modified the milestones: 4.0.0, 3.16.0 Mar 29, 2023
@gsteel gsteel changed the title Add PSR-17 Support Add PSR-17 StreamFactoryInterface Support in ImplicitHeadMiddleware Mar 29, 2023
@gsteel gsteel removed the BC Break label Mar 29, 2023
Copy link
Member

@boesing boesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me, the only thing which might happen is that there are custom factories provided by upstream factories for the StreamInterface which could be slightly modified to i.e. decorate the StreamInterface by default which won't be the case once the StreamFactoryInterface creates the StreamInterface.

If you need more input on the problem I try to outline, just let me know.
I guess you can adapt the tests regarding the ResponseFactoryInterface, that should outline the issue quite good.

src/Middleware/ImplicitHeadMiddleware.php Outdated Show resolved Hide resolved
src/Middleware/ImplicitHeadMiddleware.php Outdated Show resolved Hide resolved
src/Middleware/ImplicitHeadMiddlewareFactory.php Outdated Show resolved Hide resolved
@boesing
Copy link
Member

boesing commented Mar 29, 2023

the stream factory was still outstanding for the 3.x series

That was probably my fault. I did not properly detected the callable in #23 :-/

…Middleware

The decorator enables a StreamFactoryInterface type internally whilst preserving BC with callable stream factories.

Signed-off-by: George Steel <george@net-glue.co.uk>
… the deprecated callable

Signed-off-by: George Steel <george@net-glue.co.uk>
@gsteel gsteel requested a review from boesing March 31, 2023 09:33
@ghostwriter
Copy link
Contributor

review is based on the assumption that this PR will target v4.

@gsteel
Copy link
Member Author

gsteel commented Apr 23, 2023

@ghostwriter

review is based on the assumption that this PR will target v4.

This patch is targeting 3.x - In v4, callable will be dropped along with the decorators

@boesing - when you get a chance, can you review again please?

@boesing
Copy link
Member

boesing commented Apr 23, 2023

Can you probably adapt the unit tests from the other PRs we've already created?
I have created some weird edge-case tests to verify we do not oversee something.

I havent had a full look on this as I currently dont want to spend time on non-SM or psalm stuff.
https://github.com/mezzio/mezzio-authorization/pull/11/files#diff-2a887fd425446ffddd77e23296b0972d2d60b1692d7151e1ade245217fc7d5d6 has some special checks regarding decorators and stuff, not quite sure if its worth to adapt these changes here or if we are good to go.
Maybe some1 else can have a look on this or you take some more time until I've finished with SM v4. My next target would've been mezzio v4 AFAIR.

@gsteel
Copy link
Member Author

gsteel commented Apr 23, 2023

Pretty confident everything is covered - the StreamFactory only has 1 responsibility here and that is to generate an empty stream for implicit HEAD requests.

Perhaps @weierophinney or @Ocramius could review to get this one over the line - we'll need it to get v4 out the door right?

Copy link
Contributor

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality looks sane, and tests cover the changes. 🚢

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 LGTM, thanks @gsteel!

throw new RuntimeException('This method will not be implemented');
}

/** @inheritDoc */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably document @returns never?

return ($this->streamFactory)();
}

/** @inheritDoc */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably document @returns never?

@Ocramius Ocramius assigned Ocramius and unassigned boesing Apr 24, 2023
@Ocramius Ocramius merged commit 49d9ada into mezzio:3.16.x Apr 24, 2023
@gsteel gsteel deleted the psr-17 branch April 24, 2023 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add PSR-17 support
6 participants