itsgoingd / clockwork

Clockwork - php dev tools in your browser - server-side component
https://underground.works/clockwork
MIT License
5.69k stars 321 forks source link

PSR-based Middleware #680

Closed UlrichEckhardt closed 8 months ago

UlrichEckhardt commented 9 months ago

This PR adds a generic middleware, based only on the PSR-7, PSR-15 and PSR-17 standards. It should work with any framework that provides implementations for those PSR interfaces. At the moment (2024-02-09) this is still a bit work in progress.

For testing, there are two examples, which implement this middleware:

DominicDetta commented 9 months ago

It's there a reason why you didn't use the usePsrMessage method of the vanilla clockwork instance?

UlrichEckhardt commented 9 months ago

Actually, the only thing from the vanilla Clockwork helper class I used was the configuration handling. My problem with the rest of the code is that is mixes between stuff based on superglobals and the PSR classes, without any type hinting and without clear instructions how to use things. Getting a better understanding was actually one of the reasons for #671, too.

itsgoingd commented 9 months ago

Hey, thanks for giving this some foundation. I also think this should be a part of the Vanilla integration and delegate all the work to the Clockwork helper class there. That helper class needs to be improved to properly read input from a PSR request (it already handles outputting to a PSR response).

Also some of the type-hints will need to be removed here (when we decide to up our PHP version requirement and use them, they should be added everywhere, instead of having an odd class in the source).

Of course, feel free to stop working on this when it stops being fun, I can finish where you leave off. :)

UlrichEckhardt commented 9 months ago

Concerning the type hints, you're right. As long as Clockwork targets legacy PHP5.6 and to some extent 7.x, a few of the hints need to be removed. However, they can live on in docblocks. Together with Psalm or PHPStan that's just as good and to some extent even better: You can only annotate e.g. Generator but in the docblock you can use Generator<SomeType> to make clear what exactly is generated.

Concerning the helper class, I think that it would be cleaner to separate the implementation based on superglobals and the one based on PSR messages. I don't want to force people to provide the PSR-factories if they don't need them. Also, the code inside would be much simpler if it didn't mix the two implementations, I believe. One question that might influence the path here is whether this will go into Clockwork 5 or 6.

Oh, and I'm enjoying this, both the coding and the exchange. :)

Uli

itsgoingd commented 8 months ago

A variation of this idea is now merged. Thanks for coming up with the idea and working on the foundation for the implementation. :)