Skip to content

Instantly share code, notes, and snippets.

@codenamegary
Created December 9, 2013 21:21
Show Gist options
  • Save codenamegary/7881140 to your computer and use it in GitHub Desktop.
Save codenamegary/7881140 to your computer and use it in GitHub Desktop.
<?php
use Validator;
use RuleSet;
use Filters;
use Rule;
use Constraints;
class ValidationBuilder {
protected $input;
protected $validator;
protected $ruleSet;
public function __construct(array $input)
{
$this->input = $input;
$this->ruleSet = new RuleSet;
}
public function addRule($fieldName, $message, array $filters, array $constraints)
{
$rule = new Rule;
$rule->setFieldName($fieldName);
$rule->setMessage($message);
foreach($filters as $filterMethod) $rule->addFilter(Filters::$filterMethod());
foreach($constraints as $constraintMethod) $rule->addConstraint(Constraints::$constraintMethod());
$this->ruleSet->add($rule);
return $this;
}
public function make()
{
$validation = new Validator;
$validation->setRuleSet($this->ruleSet);
$validation->setForm($this->input);
return $validation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment