Apparently, I have to implement isAllowEmpty method as below to get the desired behavior:
public function isAllowEmpty(\Phalcon\Filter\Validation $validation, $field): bool
{
$value = $validation->getValue($field);
return $this->allowEmpty($field, $value);
}
Now this is my output:
Executing allowEmpty! // from preChecking method in Phalcon\Filter\Validation class.
Executing allowEmpty! // one from my validate method.
Field `foo` is invalid!
I found out that there is a check for isAllowEmpty method existance in Phalcon source code of Phalcon\Filter\Validation class. But isAllowEmpty method could only be found in Phalcon\Filter\Validation\Validator\File\AbstractFile and not in AbsctractValidator.
Later I will try to open the issue at Phalcon's GitHub repo.