I'm not sure if there's currently validator for sub array. However, --one of my favorite feature of phalcon-- we can customize it.
For example, you can create custom presence validator like:
use Phalcon\Validation\Validator,
Phalcon\Validation\ValidatorInterface,
Phalcon\Validation\Message;
class MyPresenceValidator extends Validator implements ValidatorInterface
{
/**
* Executes the validation
*
* @param \Phalcon\Validation $validator
* @param string $attribute
* @return boolean
*/
public function validate($validator, $attribute)
{
$array = explode(".", $attribute);
if (count($array) > 0){
$value = $validator->getValue($array[0]);
for($i = 1; $i < count($array); $i++){
if (!isset($value[$array[$i]])){
$validator->appendMessage(new Message(str_replace(":field", $attribute, $validator->getDefaultMessage("PresenceOf")), $attribute));
return false;
}
$value = $value[$array[$i]];
}
if ($value !== null){
return true;
}
}
return false;
}
}
and use it on the validation:
$validation = new \Phalcon\Validation();
$data = ['external' => ['internal' => ['deeper' => 1]]];
$validation->add("external", new \Phalcon\Validation\Validator\PresenceOf());
$validation->add('external.internal', new MyPresenceValidator());
$validation->add('external.internal.deeper', new MyPresenceValidator());
$validation->add('external.internal.crazystuff', new MyPresenceValidator());
$errors = $validation->validate($data);
echo "errors:";
foreach($errors as $error){
/* @var $error Message */
print_r($error->getMessage());
}
Well, it's a quick and dirty way to do it, but I hope you get the point.
Cheers,