Skip to content

Support PSR-17 StreamFactoryInterface #56

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

Merged
merged 1 commit into from
Dec 17, 2019

Conversation

deguif
Copy link
Contributor

@deguif deguif commented Jun 5, 2019

Q A
Bug fix? yes
New feature? no
BC breaks? no?
Deprecations? no
Related tickets php-http/HttplugBundle#339
Documentation
License MIT

What's in this PR?

Support for PSR-17 StreamFactoryInterface

@deguif
Copy link
Contributor Author

deguif commented Jun 5, 2019

Build is failing because PHP 5.4 is still supported (unsupported ::class constant), maybe support for unmaintained PHP versions could be dropped?

@shulard
Copy link

shulard commented Jun 5, 2019

I think you are right. The whole PHP-HTTP ecosystem is moving around the v2 so its time to deprecate some old PHP versions. Regarding that update, maybe supporting both HttplugFactory and PSR17Factory is not relevant anymore... PSR17 will be the de facto standard.

@dbu
Copy link
Contributor

dbu commented Jun 5, 2019

not just "de facto" but "officially accepted" standard :-)

afaik @Nyholm did a lot of thinking to have a clean upgrade path for the PSR, maybe he can chime in on this?

@deguif deguif force-pushed the psr17-compatibility branch from 16de5ac to a282d11 Compare June 5, 2019 15:35
@deguif
Copy link
Contributor Author

deguif commented Jun 5, 2019

Yes, let's wait for his comment(s).
I would be very interested to know about the upgrade path ;)

@dbu
Copy link
Contributor

dbu commented Dec 2, 2019

@Nyholm do you have input on this one?

@dbu
Copy link
Contributor

dbu commented Dec 9, 2019

ping @Nyholm

@dbu dbu requested a review from Nyholm December 9, 2019 07:39
Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Im sorry for the awful delay.

This looks super solid.

@Nyholm Nyholm mentioned this pull request Dec 16, 2019
{
if (!($streamFactory instanceof StreamFactory) && !($streamFactory instanceof StreamFactoryInterface)) {
throw new \LogicException(\sprintf('StreamFactory must be an instance of %s or %s', StreamFactory::class, StreamFactoryInterface::class));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we throw a TypeError here?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh good idea. @deguif could you change this to throw a TypeError instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I can change this ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And ✅

@deguif deguif force-pushed the psr17-compatibility branch from a282d11 to f2b89be Compare December 17, 2019 09:30
{
if (!($streamFactory instanceof StreamFactory) && !($streamFactory instanceof StreamFactoryInterface)) {
throw new \TypeError(\sprintf('StreamFactory must be an instance of %s or %s.', StreamFactory::class, StreamFactoryInterface::class));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be:

throw new \TypeError(\sprintf('Argument 2 passed to %s::__construct() must be of type %s|%s, %s given.', self::class, StreamFactory::class, StreamFactoryInterface::class, gettype($streamFactory)));

To match the message given by PHP 8 for type errors with union types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even better: \is_object($streamFactory) ? \get_class($streamFactory) : \gettype($streamFactory) for the given type ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yes. 👍

@deguif deguif force-pushed the psr17-compatibility branch from f2b89be to 0a2115c Compare December 17, 2019 10:00
@deguif deguif force-pushed the psr17-compatibility branch from 0a2115c to a4e5617 Compare December 17, 2019 10:14
Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thanks a lot!

@dbu dbu merged commit d80a1b1 into php-http:master Dec 17, 2019
@@ -33,7 +34,7 @@ final class CachePlugin implements Plugin
private $pool;

/**
* @var StreamFactory
* @var StreamFactory|StreamFactoryInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

once php-http/message-factory#38 is released, we can raise our version constraint to get that version and only use the psr interface from then on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and let ping me at this moment, I will be glad to do the PR ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants