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 UploadedFileInterface to valid types of $value parameter of MimeType::isValid() #236

Merged

Conversation

akrabat
Copy link
Member

@akrabat akrabat commented Mar 13, 2024

The $value parameter of MimeType::isValid() is passed to FileInformationTrait::getFileInfo() which takes string|array|object, so isValid()'s $value should accept the same types.

The $value parameter is passed to FileInformationTrait::getFileInfo()
which takes string|array|object, so isValid()'s $value should accept the
same types.

Signed-off-by: Rob Allen <rob@akrabat.com>
@akrabat akrabat force-pushed the update-mimetype-isvalid-value-annotation branch from 5590fc3 to a0ef89e Compare March 13, 2024 14:43
This needs to match MimeType::isValid().

Signed-off-by: Rob Allen <rob@akrabat.com>
@Ocramius
Copy link
Member

@akrabat should the baseline be reduced, given your explanation? 🤔

@akrabat
Copy link
Member Author

akrabat commented Mar 13, 2024

@akrabat should the baseline be reduced, given your explanation? 🤔

@Ocramius I don't think we can as the fallback if $value is not a string, array or instance of UploadedFileInterface is:

return $this->getFileBasedFileInfo($value, $hasType, $hasBasename);

Within getFileBasedFileInfo(), $value is treated as a string, and I'm pretty sure any object that has a __toString() would work.

@Ocramius
Copy link
Member

I'm pretty sure any object that has a __toString() would work.

Perhaps we should limit to Stringable then? Will try to catch you today about this 👍

@akrabat
Copy link
Member Author

akrabat commented Mar 15, 2024

Thanks @Ocramius.

I've checked the code in a little more detail and it turns out that $value can only be a string, an array or an instance of UploadedFileInterface. It cannot be an object that's Stringable as we call basename() on which only supports native PHP strings. The only other thing to worry about is that is_array() is called on $value and again is_array() only works with native PHP arrays.

Updated to limit to this.

@akrabat akrabat force-pushed the update-mimetype-isvalid-value-annotation branch from 3a84259 to 1ca7652 Compare March 15, 2024 14:18
akrabat added 2 commits March 15, 2024 15:21
Investigating the code in more detail shows that $value can only be a
string, an array or an instance of UploadedFileInterface. It cannot be
an object that's Stringable as we call basename() which only supports
real strings.

Signed-off-by: Rob Allen <rob@akrabat.com>
Signed-off-by: Rob Allen <rob@akrabat.com>
@akrabat akrabat force-pushed the update-mimetype-isvalid-value-annotation branch from 1ca7652 to bec5e0e Compare March 15, 2024 14:21
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 @akrabat!

@Ocramius Ocramius self-assigned this Mar 16, 2024
@Ocramius Ocramius added this to the 2.51.0 milestone Mar 16, 2024
@Ocramius Ocramius merged commit 25cc42e into laminas:2.51.x Mar 16, 2024
11 checks passed
@Ocramius Ocramius changed the title Add object to $value parameter of MimeType::isValid() Add UploadedFileInterface to valid types of $value parameter of MimeType::isValid() Mar 16, 2024
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.

2 participants