Fuel\Validation\Validator::run PHP Method

run() public method

The array is expected to have keys named after fields. This function will call reset() before it runs.
Since: 2.0
public run ( array $data, Fuel\Validation\ResultInterface $result = null ) : Fuel\Validation\ResultInterface
$data array
$result Fuel\Validation\ResultInterface
return Fuel\Validation\ResultInterface
    public function run($data, ResultInterface $result = null)
    {
        if ($result === null) {
            $result = new Result();
        }
        $result->setResult(true);
        foreach ($this->fields as $fieldName => $rules) {
            $fieldResult = $this->validateField($fieldName, $data, $result);
            if (!$fieldResult) {
                // There was a failure so log it to the result object
                $result->setResult(false);
            }
        }
        return $result;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Validates a dataset
  *
  * @param [] $data
  *
  * @throws InvalidArgumentException
  */
 public function validate(array $data)
 {
     $result = $this->validator->run($data);
     if ($result->isValid() === false) {
         $error = $result->getErrors();
         $error = reset($error);
         throw new InvalidArgumentException($error);
     }
 }
All Usage Examples Of Fuel\Validation\Validator::run