本文整理汇总了PHP中Zend\Validator\ValidatorChain::addByName方法的典型用法代码示例。如果您正苦于以下问题:PHP ValidatorChain::addByName方法的具体用法?PHP ValidatorChain::addByName怎么用?PHP ValidatorChain::addByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Validator\ValidatorChain
的用法示例。
在下文中一共展示了ValidatorChain::addByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCanAttachMultipleValidatorsOfTheSameTypeAsDiscreteInstances
/**
* @group ZF-412
*/
public function testCanAttachMultipleValidatorsOfTheSameTypeAsDiscreteInstances()
{
$this->validator->addByName('Callback', array('callback' => function ($value) {
return true;
}, 'messages' => array('callbackValue' => 'This should not be seen in the messages')));
$this->validator->addByName('Callback', array('callback' => function ($value) {
return false;
}, 'messages' => array('callbackValue' => 'Second callback trapped')));
$this->assertEquals(2, count($this->validator));
$validators = $this->validator->getValidators();
$compare = null;
foreach ($validators as $validator) {
$this->assertNotSame($compare, $validator);
$compare = $validator;
}
$this->assertFalse($this->validator->isValid('foo'));
$messages = $this->validator->getMessages();
$found = false;
$test = 'Second callback trapped';
foreach ($messages as $messageSet) {
if (is_string($messageSet) && $messageSet === $test) {
$found = true;
break;
}
if (is_array($messageSet) && in_array('Second callback trapped', $messageSet)) {
$found = true;
break;
}
}
$this->assertTrue($found);
}
示例2: populateValidators
protected function populateValidators(ValidatorChain $chain, $validators)
{
foreach ($validators as $validator) {
if ($validator instanceof ValidatorInterface) {
$chain->addValidator($validator);
continue;
}
if (is_array($validator)) {
if (!isset($validator['name'])) {
throw new Exception\RuntimeException('Invalid validator specification provided; does not include "name" key');
}
$name = $validator['name'];
$options = array();
if (isset($validator['options'])) {
$options = $validator['options'];
}
$breakChainOnFailure = false;
if (isset($validator['break_chain_on_failure'])) {
$breakChainOnFailure = $validator['break_chain_on_failure'];
}
$chain->addByName($name, $options, $breakChainOnFailure);
continue;
}
throw new Exception\RuntimeException('Invalid validator specification provided; was neither a validator instance nor an array specification');
}
}