示例#1
0
 /**
  * Get an error instance
  * 
  * @return sndsgd\field\Error
  */
 public function getError()
 {
     $error = new Error($this->getMessage());
     $error->setValue($this->value);
     if ($this->field !== null) {
         $error->setName($this->field->getName());
     }
     if ($this->valueIndex !== null) {
         $error->setIndex($this->valueIndex);
     }
     return $error;
 }
示例#2
0
 /**
  * Add values to the fields in the collection
  *
  * @param array.<string,mixed> $fieldValues
  */
 public function addValues(array $fieldValues)
 {
     foreach ($fieldValues as $fieldName => $values) {
         $values = Arr::cast($values);
         if (null === ($field = $this->getField($fieldName))) {
             $message = "unknown field";
             $len = count($values);
             if ($len !== 1) {
                 $message .= " (encountered {$len} values)";
             }
             $error = new Error($message);
             $error->setName($fieldName);
             $this->addError($error);
         } else {
             foreach ($values as $index => $value) {
                 $field->addValue($value, $index);
             }
         }
     }
 }