form-manager
form-manager copied to clipboard
Use Symfony File constraints
Hi,
I tried to add a maxSize constraint from Symfony on a file input. Turns out it's not working because Symfony expect a Symfony\Component\HttpFoundation\File\File object.
Is there any way to make file constraints work? If not, that would probably deserves a mention in the docs.
Yep, this is not supported at this moment.
A possible workaround might be adding a Constraint\Callback and create the Symfony File object and file validator in the callback.
Other option (maybe better) could be create a SymfonyFile input, extending the default File class (https://github.com/oscarotero/form-manager/blob/master/src/Inputs/File.php) and modify the setValue method to create and save the Symfony File instance, instead the array data.
Thanks for the fast feedback! I'll try those ways and maybe come back with a PR if I have enough time.
BTW, making a file input required doesn't work either. I add to provide a custom Constraint\Callback for that.