当前位置: 首页>>代码示例>>PHP>>正文


PHP ValidatorChain::addByName方法代码示例

本文整理汇总了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);
 }
开发者ID:nieldm,项目名称:zf2,代码行数:34,代码来源:ValidatorChainTest.php

示例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');
     }
 }
开发者ID:Rovak,项目名称:zf2,代码行数:26,代码来源:Factory.php


注:本文中的Zend\Validator\ValidatorChain::addByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。