Cphalcon: File Validation compatibility with Phalcon\Http\Request\File

Created on 25 Aug 2016  路  5Comments  路  Source: phalcon/cphalcon

Hello,

I think the way that File Validation "Phalcon\Validation\Validator\File" need to be changed to work with Phalcon\Http\Request\File instances since the framework already make an instances of $_FILES in the ,

In my opinion, the File Validator is not responsible to work with external service Like HTTP Requests , as the validator only validate Values, the File Validator must not check if the _SERVER is POST request , _FILES empty or not , we can just pass a value that implements an interface like "Phalcon\Http\Request\FileInterface", this may be useful for unit testing to mock file instances, and the _SERVER['REQUEST_METHOD'] is not available in the CLI .

$data = $this->request->getPost();
foreach ($this->request->getUploadedFiles() as $uploadedFile) {           
    $data[$uploadedFile->getKey()] =  $uploadedFile;
}

if(!$form->isValid($data)){
   //validation error ....
}

What do you think?

Regards

stale

Most helpful comment

Exactly. Such behaviour is odd. This validation needs to be self injectable.
instead of:
$validator->validate($_FILES);

it should accept reference to a files from $this->request->getUploadedFiles() object.

All 5 comments

Exactly. Such behaviour is odd. This validation needs to be self injectable.
instead of:
$validator->validate($_FILES);

it should accept reference to a files from $this->request->getUploadedFiles() object.

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

This was never solved, it should be possible to validate with the validator the files obtained through the method $this->request->getUploadedFiles()

Yeah, this one seems to be still present in such a dirty way. :/ We have to refactor it for 4.0 release.

@sergeyklay @niden

Was this page helpful?
0 / 5 - 0 ratings