auraphp / Aura.Filter

Validate and sanitize arrays and objects.
MIT License
159 stars 33 forks source link

PSR-7 upload validator? #111

Closed designermonkey closed 7 years ago

designermonkey commented 8 years ago
$filter->validate('field')->is('upload');

Using this, with a PSR based request, how do I test the uploadedFiles part of the request?

harikt commented 8 years ago

I thought $_FILES is all what psr request was using. What is the trouble you are going through ?

designermonkey commented 8 years ago

Yeah, a modified version. I have been overthinking this as per usual and expected it to be much more complicated than it actually is.

designermonkey commented 8 years ago

Using $filter->validate('field')->is('upload'); does not successfully validate a PSR standard UploadedFileInterface instance.

designermonkey commented 8 years ago

Can there be a psr-uploaded-file validator that uses the available methods of the interface to validate the file?

pmjones commented 8 years ago

This is a good idea. If you'd like to send a PR with a validator like that, I can review it.

designermonkey commented 8 years ago

Ok, I'll do my best :)

jakejohns commented 8 years ago

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?

pmjones commented 8 years ago

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',
]);
harikt commented 8 years ago

yes I am also for array as @pmjones mentioned.

jakejohns commented 8 years ago

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:

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?

harikt commented 7 years ago

@pmjones any thoughts on releasing v3 ? In that case we could close this issue for the PR is merged.

harikt commented 7 years ago

@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 .

pmjones commented 7 years ago

This will have to be in 3.x, as the 2.x series does not allow external dependencies.

harikt commented 7 years ago

@pmjones 3.x already has this functionality merged. We probably need to move to 3.x in this case ;) .