Skip to content
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

Implement option for ignoring is_uploaded_file check in File validator #16710

Open
FaimMedia opened this issue Mar 5, 2025 · 0 comments
Open

Comments

@FaimMedia
Copy link

The AbstractFile class has the method checkIsUploadedFile. However if I want to mock/fake an uploaded file for in example unit testing, I have implement/override all these classes, since they all extend from it:

  • Phalcon\Filter\Validation\Validator\File\Resolution\Min
  • Phalcon\Filter\Validation\Validator\File\Resolution\Max
  • Phalcon\Filter\Validation\Validator\File\Resolution\Equal
  • Phalcon\Filter\Validation\Validator\File\Size\Min
  • Phalcon\Filter\Validation\Validator\File\Size\Max
  • Phalcon\Filter\Validation\Validator\File\Size\Equal
  • Phalcon\Filter\Validation\Validator\File\MimeType
  • Phalcon\Filter\Validation\Validator\File

/**
* Checks if a file has been uploaded; Internal check that can be
* overridden in a subclass if you do not want to check uploaded files
*
* @param string $name
*
* @return bool
*/
protected function checkIsUploadedFile(string name) -> bool
{
return is_uploaded_file(name);
}

Would be much easier if an option would be implemented like:

    protected function checkIsUploadedFile(string name) -> bool
    {
         if ($this->getOption('ignoreCheckUploadedFile')) {
            return true;
        }

        return is_uploaded_file(name);
    }

As an addition, it would also be nice if this validator accepted the Phalcon native $this->request->getUploadedFiles() instead of the PHP's $_FILES.

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

No branches or pull requests

1 participant