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


PHP ValidationResult::addError方法代码示例

本文整理汇总了PHP中ValidationResult::addError方法的典型用法代码示例。如果您正苦于以下问题:PHP ValidationResult::addError方法的具体用法?PHP ValidationResult::addError怎么用?PHP ValidationResult::addError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ValidationResult的用法示例。


在下文中一共展示了ValidationResult::addError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: check

 /**
  * @param $value
  * @param IValidationData $data
  *
  * @return ValidationResult
  */
 public function check($value, IValidationData $data = null)
 {
     $result = new ValidationResult();
     foreach ($this->getConstraints() as $constraint) {
         if (!$constraint->check($value, $data)) {
             $result->addError(new ValidationError($this->getName(), $value, $constraint));
         }
     }
     return $result;
 }
开发者ID:weew,项目名称:validator,代码行数:16,代码来源:ConstraintGroup.php

示例2: validate

 /**
  * Indicates wether the object passed as a parameter is valid as defined by the rules.
  * 
  * Loops through the rules defined for this validator, calling the rule's validate method, 
  * passing $obj as a parameter. Returns false at the first rule that fails. If all rules
  * succeed, true is returned.
  * 
  * @param mixed $obj is the object on which we want to test the validations
  * @return bool indicating wether $obj was valid according to the rules
  */
 public function validate($obj)
 {
     $results = new ValidationResult();
     foreach ($this->rules as $rule) {
         //Get the rule condition from the array if there is one
         $rule_id = $rule->get_id();
         //If a condition exists for the rule
         if (array_key_exists($rule_id, $this->rules_conditions)) {
             $rule_condition = $this->rules_conditions[$rule_id];
             //Skip the rule if the condition is not met
             if (!$rule_condition($obj)) {
                 continue;
             }
         }
         //For each rule, we get the props associated with their id
         //in the other array containing the props.
         foreach ($this->rules_props[$rule_id] as $prop) {
             //Check if $prop is a method or property
             if (method_exists($obj, $prop)) {
                 $value = $obj->{$prop}();
             } else {
                 if (property_exists($obj, $prop)) {
                     $value = $obj->{$prop};
                 }
             }
             if (!$rule->validate($value)) {
                 if (array_key_exists($rule_id, $this->rules_messages)) {
                     $error_message = $this->rules_messages[$rule_id];
                 } else {
                     $error_message = 'Field is invalid';
                 }
                 $results->addError($prop, $error_message);
             }
         }
     }
     return $results;
 }
开发者ID:marco-fiset,项目名称:flute,代码行数:47,代码来源:flute.php

示例3: testGetErrorWarningWithMultiple

 /**
  * @expectedException PHPUnit_Framework_Error_Notice
  * @expectedExceptionDescription There are multiple errors, returning only the first
  */
 public function testGetErrorWarningWithMultiple()
 {
     $validation = new ValidationResult();
     $validation->addError("Foo");
     $validation->addError("Bar");
     $validation->getError();
 }
开发者ID:jasny,项目名称:validation-result,代码行数:11,代码来源:ValidationResultTest.php


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