本文整理汇总了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;
}
示例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;
}
示例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();
}