Fuel\Validation\Validator::runField PHP Method

runField() public method

The array is expected to have keys named after fields. This function will call reset() before it runs.
Since: 2.0
public runField ( string $field, array $data, Fuel\Validation\ResultInterface $result = null ) : Fuel\Validation\ResultInterface
$field string
$data array
$result Fuel\Validation\ResultInterface
return Fuel\Validation\ResultInterface
    public function runField($field, array $data, ResultInterface $result = null)
    {
        if ($result === null) {
            $result = new Result();
        }
        $fieldResult = false;
        if (isset($data[$field])) {
            $fieldResult = $this->validateField($field, $data, $result);
        }
        // Log the result
        $result->setResult($fieldResult);
        return $result;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Validates one key-value pair
  *
  * @param string $key
  * @param mixed  $value
  */
 public function validateOne($key, $value)
 {
     $result = $this->validator->runField($key, array($key => $value));
     if ($result->isValid() === false) {
         throw new InvalidArgumentException($result->getError($key));
     }
 }
All Usage Examples Of Fuel\Validation\Validator::runField