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

Allow Streams to be instantiated using GD resources #45

Merged

Conversation

settermjd
Copy link
Contributor

Q A
Documentation no
Bugfix no
BC Break no
New Feature yes
RFC no
QA no

Description

I've been working on a patch to laminas-barcode, which requires a Stream to be able to be created from a GD resource. However, the patch fails, as Diactoros only allows resource types to be of type stream. So, this patch expands the list of types allowed to instantiate a Stream to include GD types. I'm submitting this after discussing the idea with @weierophinney some time ago. I hope that I understood what he meant.

@settermjd settermjd self-assigned this Aug 3, 2020
@settermjd settermjd marked this pull request as draft August 3, 2020 20:13
@weierophinney
Copy link
Member

Ping me for a review when it's ready, @settermjd !

Also, don't forget to use the -s switch to sign-off your commits! There's instructions in the contributors guide on how to use rebase to add them.

src/Stream.php Outdated Show resolved Hide resolved
@settermjd settermjd marked this pull request as ready for review August 3, 2020 20:51
@settermjd
Copy link
Contributor Author

Ping me for a review when it's ready, @settermjd !

Also, don't forget to use the -s switch to sign-off your commits! There's instructions in the contributors guide on how to use rebase to add them.

Ready for review. It's not a big patch, and I hope that I understood what you were saying in our previous discussion a little while ago.

I've been working on a patch to laminas-barcode to create a Stream from
a GD resource, but am unable to, as the resource type has to be a
stream. However, after talking to mwop, some time ago, he suggested that
it'd be fine to patch Diactoros to allow for GD resource types to
instantiate streams as well; hence, this patch.

Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
As the same code was used in both Stream and StreamFactory, it, to me,
made sense to make it reusable by creating a trait to store it and then
reusing that code among Stream and StreamFactory.. Seeing that traits
are already used in the library, it seemed okay to create another one
for use in this context.

Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
Thanks to feedback from @samsonasik.

Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
@settermjd settermjd force-pushed the expand-list-of-resource-types branch from e551b1e to 21e4b65 Compare August 3, 2020 20:55
src/StreamTrait.php Outdated Show resolved Hide resolved
src/Stream.php Outdated Show resolved Hide resolved
I don't expect the visibility to be anything other than private, so
setting it appropriately. The previous public visibility was an
oversight on my part.

Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
After quite a bit of thinking about this, I feel that @samsonasik is
correct. It doesn't make sense, to me, to expose an internal detail for
no good reason. Given that, this change moves the constant to the trait
and sets its visibility to private.

Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
Perhaps it's a minor thing, but @localheinz always pushed for
readability wherever possible. So, to make the code just that much more
readable is worth it; which is the motivation for this, minor, change.

Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
src/StreamTrait.php Outdated Show resolved Hide resolved
src/Stream.php Outdated Show resolved Hide resolved
src/StreamTrait.php Outdated Show resolved Hide resolved
Following on from the advice of @lcobucci, this change refactors the
StreamTrait functionality into Stream, and removes the trait from both
Stream and StreamFactory. On thinking about it, it makes most sense to
have this functionality directly in Stream, and not, in effect,
duplicated in multiple locations by another form.

Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
Copy link
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

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

Just a teeny tiny thing! Thanks for your work here... things look much better and the stream class is much more coherent to me 👍

src/StreamFactory.php Outdated Show resolved Hide resolved
@lcobucci
Copy link
Member

The failing integration test seems to come from php-http/psr7-integration-tests... it's doing external calls without retrying on failure, which makes the suite a bit flaky.

Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
@weierophinney weierophinney added this to the 2.4.0 milestone Sep 2, 2020
Copy link
Member

@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.

🚢

@weierophinney weierophinney changed the base branch from develop to 2.4.x September 2, 2020 13:46
@weierophinney weierophinney merged commit 539c75f into laminas:2.4.x Sep 2, 2020
@settermjd
Copy link
Contributor Author

Big thanks to everyone for all your support on this PR.

@settermjd settermjd deleted the expand-list-of-resource-types branch March 12, 2021 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants