Skip to content

[Validator][Mime] add a Constraint to check if string is valid mime type? #59015

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

Open
Hanmac opened this issue Nov 27, 2024 · 4 comments
Open

Comments

@Hanmac
Copy link
Contributor

Hanmac commented Nov 27, 2024

Description

I got a BinaryObjectType class, with having xsd:base64Binary as text value, and mimeCode attribute.

Now, I would like to check if mimeCode is a valid mime type.

Maybe in strict mode, check against MimeTypes::MAP?

Example

No response

@stof
Copy link
Member

stof commented Nov 27, 2024

I don't think this use case is common enough to ship such constraint in Symfony itself. I would suggest you to implement a custom constraint in your project.

@Hanmac
Copy link
Contributor Author

Hanmac commented Nov 27, 2024

@stof but MimeTypes::MAP is hidden from my grasp, so I can't rely on an already existing list

@stof
Copy link
Member

stof commented Nov 27, 2024

MimeTypes::MAP is also hidden from the validator component.

You would have to use the public API of the MimeTypes. A way to check whether a mime type is know in this map is to use MimeTypesInterface::getExtensions(), and checking whether you get a non-empty list.

@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

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

No branches or pull requests

3 participants