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

Prevent false positive triggering of deprecated notice in FilteredStream #81

Closed
wants to merge 1 commit into from
Closed

Conversation

ste93cry
Copy link
Contributor

@ste93cry ste93cry commented Jun 23, 2017

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets #78
License MIT

What's in this PR?

In this PR the $writeFilterOptions argument of the FilteredStream::__construct method is normalized because some built-in PHP stream filters doesn't accept null as options. As a consequence of this, the deprecation message was triggered in some cases when it should not had to, and this has been addressed too. I'm not sure about the entry I added in the CHANGELOG, as I'm not a native English speaker maybe you can find a better phrase... I don't know if unit tests are needed for this PR as currently there is nothing hat tests the throwing of the error or the call to the Filter\fun function with the correct arguments. Ast a last thing, I can't test what options the bzip2.compress and bzip2.decompress accept, so the PR is not ready yet until someone finds out if null is a valid value or not.

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix

…recation message if the value is the default one for that filter
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.

Thank you for this PR.

@@ -57,10 +57,22 @@
*/
public function __construct(StreamInterface $stream, $readFilterOptions = null, $writeFilterOptions = null)
{
$triggerDeprecationNotice = null !== $writeFilterOptions;

if (null === $readFilterOptions && in_array($this->readFilter(), ['convert.base64-encode', 'convert.base64-decode', 'convert.quoted-printable-encode', 'zlib.deflate', 'zlib.inflate'/*, 'bzip2.compress', 'bzip2.decompress'*/], true)) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of listing functions like this, we could do:

if (empty($readFilterOptions)) {
  $this->readFilterCallback = Filter\fun($this->readFilter());
} else {  
  $this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately the code as you wrote it won't work because Filter\fun by default pass null as value of the $params argument of the stream_filter_append function. I proposed a solution in #78 that I tested with the base64_encode filter (which is the reason I found the problem and opened the issue), but @dbu told me to explicitly check for the filter names. I don't know if there is a third solution, but at the moment the only two that I tested and works are these

$this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions);
$this->writeFilterCallback = Filter\fun($this->writeFilter(), $writeFilterOptions);

if (null !== $writeFilterOptions) {
if ($triggerDeprecationNotice) {
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 always trigger a deprecation notice if the $writeFilterOptions is used. The $this->writeFilterCallback is deprecated because it is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This with the if statements that I added above does exactly this, but I can't trigger a deprecation notice when the value of $writeFilterOptions is the default value for its filter

@dbu
Copy link
Contributor

dbu commented Jun 30, 2017

@ste93cry when you address the feedback from tobias, please also rebase on master - there is a conflict with the CHANGELOG file that will prevent automatic merging.

@Nyholm
Copy link
Member

Nyholm commented Jul 1, 2017

Thank you @ste93cry for your responses.

What I do not like about this PR is that we list a bunch of filters (and it is missing tests). This is a "workaround" and not a "fix".

I have submitted some PRs to the clue/php-stream-filter in order to actually fix this problem.
I hope you are okey with closing this PR update our dependencies to the next version of that library?

@ste93cry
Copy link
Contributor Author

ste93cry commented Jul 1, 2017

I hope you are okey with closing this PR update our dependencies to the next version of that library?

I agree that fixing this upstream is a better solution that this PR, so it's fine. Just for reference in case someone lands here in the future, the ticket related to this problem is clue/stream-filter#15

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.

None yet

3 participants