Closed svycka closed 8 years ago
workaround example:
class User extends InputFilter
{
public function __construct()
{
$this->add([
'name' => 'country_code',
'required' => true,
'validators' => [
new CountryCode()
],
]);
$this->add([
'name' => 'phone',
'required' => true,
'validators' => [
'name' => 'Zend\Validator\Callback',
'options' => array(
'messages' => [
\Zend\Validator\Callback::INVALID_VALUE => 'Invalid phone number.',
],
'callback' => function ($phone, $context) {
$phoneValidator = new PhoneNumber([
'country' => $context['country_code'],
]);
return $phoneValidator->isValid($phone);
},
),
],
]);
}
}
Thanks, @svycka
I guess this was desired behavior but didn't worked.
this is extremely useful for example with input filters, example:
before I had to wrap
PhoneNumber
intocallback
validator and pass country in constructor.