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

Logic behind detectMimeType is a bit odd (or could be improved) #19

Open
uuf6429 opened this issue Sep 28, 2022 · 0 comments
Open

Logic behind detectMimeType is a bit odd (or could be improved) #19

uuf6429 opened this issue Sep 28, 2022 · 0 comments

Comments

@uuf6429
Copy link

uuf6429 commented Sep 28, 2022

Current behaviour of detectMimeType():

  • if file content is passed, it tries to get its mime type with finfo
  • if that mime type is null or 'inconclusive', it falls back to map

In other words, we're forced to read the file contents to use this.
On the other hand, detectMimeTypeFromFile returns the mime type by checking the file contents without requiring the contents to be passed.

My expectation of the function logic would have been:

  • if contents are passed, guess from contents
  • otherwise, guess from file (path)
  • if inconclusive, use map

i.e. in other words $contents would be optional, but it would still check the file.

https://github.com/thephpleague/mime-type-detection/blob/main/src/FinfoMimeTypeDetector.php#L54

I guess updating the behaviour now could be considered as a BC break though.

@uuf6429 uuf6429 changed the title Logic behind detectMimeType is a bit odd Logic behind detectMimeType is a bit odd (or code be improved) Sep 28, 2022
@uuf6429 uuf6429 changed the title Logic behind detectMimeType is a bit odd (or code be improved) Logic behind detectMimeType is a bit odd (or could be improved) Aug 18, 2024
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

No branches or pull requests

1 participant