We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

File validator

Should I know zephir or c to add constants to a class in phalconphp ? Reason behind is is that i'm currenlty using the file validator but when settting the options that I need I always need to go back to the documentation to find out the name of it. And what I would like to see is something like.

    <?php
    $file =   new Validation\Validator\File();
    $file->setOption(Validation\Validator\File::MAX_SIZE,'2M');
    $file->setOption(Validation\Validator\File::ALLOWED_TYPES,['image/jpeg','image/png');

Is this a better way or am I just delusional?

You can override (extend) File validator class in pure PHP. There are few ways depending on your use case, but usually I'd resolve any common dependencies on object instantiation. That way you can do something like: new MyFileValidator();