Closed designermonkey closed 7 years ago
I thought $_FILES
is all what psr request was using. What is the trouble you are going through ?
Yeah, a modified version. I have been overthinking this as per usual and expected it to be much more complicated than it actually is.
Using $filter->validate('field')->is('upload');
does not successfully validate a PSR standard UploadedFileInterface
instance.
Can there be a psr-uploaded-file
validator that uses the available methods of the interface to validate the file?
This is a good idea. If you'd like to send a PR with a validator like that, I can review it.
Ok, I'll do my best :)
I previously had been working on a suite of validation to work with PSR7 upload stuff, but never really formalized it or finished it. For what it's worth, here's the approach I was taking: https://github.com/jakejohns/aura-upload-filter/tree/master/src/Validate/Upload
The idea was something like this:
<?php
// require that file is uploaded
$filter->validate('field')->is('upload/required');
// require extension
$filter->validate('field')->is('upload/fileExtension', 'txt');
$filter->validate('field')->is('upload/fileExtension', ['txt', 'rtf']);
// require media type
$filter->validate('field')->is('upload/fileMedia', ['text/html']);
// Max size
$filter->validate('field')->is('upload/sizeMax', 100); // bytes
$filter->validate('field')->is('upload/sizeMax', '1MB'); // parse human readable stuff
// Min size
$filter->validate('field')->is('upload/sizeMin', 100); // bytes
$filter->validate('field')->is('upload/sizeMin', '1MB'); // parse human readable stuff
Thoughts? Anyone think anything here is useful?
Interesting. I wonder if it would make more sense to pass an array as the second param, and skip the slashes in the filter name? E.g.:
$filter->validate('field')->is('upload', [
'fileExtension' => ['txt', 'rtf'],
'fileMedia' => 'text/html',
'sizeMax' => '5MB',
'sizeMin' => '1MB',
]);
yes I am also for array as @pmjones mentioned.
It seems like the suggestion is to combine the 5 rules into a single rule configured by an array. That seems a little counter intuitive to me as they seem to be 'different' rules, but I'm not horrified by it as the rules are obviously related.
My concerns would be:
__invoke($subject, $field, $options)
)Maybe I'm off on this though.
In regards to the slash in the name, I'm pretty sure that could easily be eliminated regardless of the combination approach, as that's just how the locator is configured, and could certainly just be something like uploadSizeMax
or maxUploadSize
thoughts, feelings, concerns, rebuttals, remarks to alleviate my concerns?
@pmjones any thoughts on releasing v3 ? In that case we could close this issue for the PR is merged.
@pmjones can we move to 3.x releases for this package ?
Else we can close this for it will never be implemented in 2.x .
This will have to be in 3.x, as the 2.x series does not allow external dependencies.
@pmjones 3.x already has this functionality merged. We probably need to move to 3.x in this case ;) .
Using this, with a PSR based request, how do I test the uploadedFiles part of the request?