當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ValidatorChain::getMessages方法代碼示例

本文整理匯總了PHP中Zend\Validator\ValidatorChain::getMessages方法的典型用法代碼示例。如果您正苦於以下問題:PHP ValidatorChain::getMessages方法的具體用法?PHP ValidatorChain::getMessages怎麽用?PHP ValidatorChain::getMessages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Validator\ValidatorChain的用法示例。


在下文中一共展示了ValidatorChain::getMessages方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getMessages

 public function getMessages()
 {
     $parent = parent::getMessages();
     $language = $this->languageValidator->getMessages();
     $chain = $this->chain->getMessages();
     return array_merge($parent, $language, $chain);
 }
開發者ID:Theodia,項目名稱:theodia.org,代碼行數:7,代碼來源:Localization.php

示例2: __construct

 /**
  * Constructor.
  *
  * @param  string  $host OPTIONAL Hostname of remote connection (default: 127.0.0.1)
  * @param  integer $port OPTIONAL Port number (default: null)
  * @throws Exception\RuntimeException
  */
 public function __construct($host = '127.0.0.1', $port = null)
 {
     $this->validHost = new Validator\ValidatorChain();
     $this->validHost->attach(new Validator\Hostname(Validator\Hostname::ALLOW_ALL));
     if (!$this->validHost->isValid($host)) {
         throw new Exception\RuntimeException(implode(', ', $this->validHost->getMessages()));
     }
     $this->host = $host;
     $this->port = $port;
 }
開發者ID:totolouis,項目名稱:ZF2-Auth,代碼行數:17,代碼來源:AbstractProtocol.php

示例3: 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

示例4: testAllowsPrependingValidatorsByName

 public function testAllowsPrependingValidatorsByName()
 {
     $this->validator->addValidator($this->getValidatorTrue())->prependByName('NotEmpty', array(), true);
     $this->assertFalse($this->validator->isValid(''));
     $messages = $this->validator->getMessages();
     $this->assertArrayHasKey('isEmpty', $messages);
 }
開發者ID:navassouza,項目名稱:zf2,代碼行數:7,代碼來源:ValidatorChainTest.php

示例5: __construct

 /**
  * Constructor.
  *
  * @param  string  $host OPTIONAL Hostname of remote connection (default: 127.0.0.1)
  * @param  integer $port OPTIONAL Port number (default: null)
  * @throws \Zend\Mail\Protocol\Exception
  * @return void
  */
 public function __construct($host = '127.0.0.1', $port = null)
 {
     $this->_validHost = new Validator\ValidatorChain();
     $this->_validHost->addValidator(new HostnameValidator(HostnameValidator::ALLOW_ALL));
     if (!$this->_validHost->isValid($host)) {
         throw new Protocol\Exception\RuntimeException(implode(', ', $this->_validHost->getMessages()));
     }
     $this->_host = $host;
     $this->_port = $port;
 }
開發者ID:hjr3,項目名稱:zf2,代碼行數:18,代碼來源:AbstractProtocol.php

示例6: __construct

 /**
  * Constructor.
  *
  * @param  string  $host OPTIONAL Hostname of remote connection (default: 127.0.0.1)
  * @param  integer $port OPTIONAL Port number (default: null)
  * @throws \Zend\Mail\Protocol\Exception
  * @return void
  */
 public function __construct($host = '127.0.0.1', $port = null)
 {
     $this->_validHost = new Validator\ValidatorChain();
     $this->_validHost->addValidator(new HostnameValidator\Hostname(HostnameValidator\Hostname::ALLOW_ALL));
     if (!$this->_validHost->isValid($host)) {
         throw new Exception(join(', ', $this->_validHost->getMessages()));
     }
     $this->_host = $host;
     $this->_port = $port;
 }
開發者ID:alab1001101,項目名稱:zf2,代碼行數:18,代碼來源:AbstractProtocol.php

示例7: __construct

 /**
  * @param array $value
  *
  */
 protected function __construct(array $value)
 {
     /** @var \AGmakonts\STL\String\String $name */
     $name = $value[0];
     $nameValue = $name->value();
     $validatorChain = new ValidatorChain();
     $validatorChain->attach(new AlphaValidator(TRUE));
     $validatorChain->attach(new StringLength(['min' => self::MINIMUM_LENGTH]));
     $validatorChain->attach(new NotEmpty());
     if (FALSE === $validatorChain->isValid($nameValue)) {
         throw new InvalidNameException($name, $validatorChain->getMessages());
     }
     $this->name = $name;
 }
開發者ID:Code-Mine-Development,項目名稱:Famil.io,代碼行數:18,代碼來源:Name.php

示例8: _validateRule

 /**
  * @param array $validatorRule
  * @return void
  */
 protected function _validateRule(array $validatorRule)
 {
     /**
      * Get one or more data values from input, and check for missing fields.
      * Apply defaults if fields are missing.
      */
     $data = array();
     foreach ((array) $validatorRule[self::FIELDS] as $key => $field) {
         if (array_key_exists($field, $this->_data)) {
             $data[$field] = $this->_data[$field];
         } else {
             if (isset($validatorRule[self::DEFAULT_VALUE])) {
                 /** @todo according to this code default value can't be an array. It has to be reviewed */
                 if (!is_array($validatorRule[self::DEFAULT_VALUE])) {
                     // Default value is a scalar
                     $data[$field] = $validatorRule[self::DEFAULT_VALUE];
                 } else {
                     // Default value is an array. Search for corresponding key
                     if (isset($validatorRule[self::DEFAULT_VALUE][$key])) {
                         $data[$field] = $validatorRule[self::DEFAULT_VALUE][$key];
                     } else {
                         if ($validatorRule[self::PRESENCE] == self::PRESENCE_REQUIRED) {
                             // Default value array is provided, but it doesn't have an entry for current field
                             // and presence is required
                             $this->_missingFields[$validatorRule[self::RULE]][] = $this->_getMissingMessage($validatorRule[self::RULE], $field);
                         }
                     }
                 }
             } else {
                 if ($validatorRule[self::PRESENCE] == self::PRESENCE_REQUIRED) {
                     $this->_missingFields[$validatorRule[self::RULE]][] = $this->_getMissingMessage($validatorRule[self::RULE], $field);
                 }
             }
         }
     }
     /**
      * If any required fields are missing, break the loop.
      */
     if (isset($this->_missingFields[$validatorRule[self::RULE]]) && count($this->_missingFields[$validatorRule[self::RULE]]) > 0) {
         return;
     }
     /**
      * Evaluate the inputs against the validator chain.
      */
     if (count((array) $validatorRule[self::FIELDS]) > 1) {
         if (!$validatorRule[self::ALLOW_EMPTY]) {
             $emptyFieldsFound = false;
             $errorsList = array();
             $messages = array();
             foreach ($data as $fieldKey => $field) {
                 $notEmptyValidator = $this->_getValidator('NotEmpty');
                 $notEmptyValidator->setMessage($this->_getNotEmptyMessage($validatorRule[self::RULE], $fieldKey));
                 if (!$notEmptyValidator->isValid($field)) {
                     foreach ($notEmptyValidator->getMessages() as $messageKey => $message) {
                         if (!isset($messages[$messageKey])) {
                             $messages[$messageKey] = $message;
                         } else {
                             $messages[] = $message;
                         }
                     }
                     $errorsList[] = $notEmptyValidator->getErrors();
                     $emptyFieldsFound = true;
                 }
             }
             if ($emptyFieldsFound) {
                 $this->_invalidMessages[$validatorRule[self::RULE]] = $messages;
                 $this->_invalidErrors[$validatorRule[self::RULE]] = array_unique(call_user_func_array('array_merge', $errorsList));
                 return;
             }
         }
         if (!$validatorRule[self::VALIDATOR_CHAIN]->isValid($data)) {
             $this->_invalidMessages[$validatorRule[self::RULE]] = $validatorRule[self::VALIDATOR_CHAIN]->getMessages();
             $this->_invalidErrors[$validatorRule[self::RULE]] = $validatorRule[self::VALIDATOR_CHAIN]->getErrors();
             return;
         }
     } else {
         if (count($data) > 0) {
             // $data is actually a one element array
             $fieldNames = array_keys($data);
             $fieldName = reset($fieldNames);
             $field = reset($data);
             $failed = false;
             if (!is_array($field)) {
                 $field = array($field);
             }
             $notEmptyValidator = $this->_getValidator('NotEmpty');
             $notEmptyValidator->setMessage($this->_getNotEmptyMessage($validatorRule[self::RULE], $fieldName));
             if ($validatorRule[self::ALLOW_EMPTY]) {
                 $validatorChain = $validatorRule[self::VALIDATOR_CHAIN];
             } else {
                 $validatorChain = new Validator\ValidatorChain();
                 $validatorChain->addValidator($notEmptyValidator, true);
                 $validatorChain->addValidator($validatorRule[self::VALIDATOR_CHAIN]);
             }
             foreach ($field as $value) {
                 if ($validatorRule[self::ALLOW_EMPTY] && !$notEmptyValidator->isValid($value)) {
//.........這裏部分代碼省略.........
開發者ID:heiglandreas,項目名稱:zf2,代碼行數:101,代碼來源:InputFilter.php


注:本文中的Zend\Validator\ValidatorChain::getMessages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。