Created
October 17, 2013 00:28
-
-
Save dadamssg/7017332 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace ProgrammingAreHard\Data\Validators; | |
use Illuminate\Validation\Validator; | |
class ValidationService implements ValidatorInterface { | |
protected $validator; | |
protected $errors = []; | |
protected $rules = []; | |
public function __construct(Validator $validator) | |
{ | |
$this->validator = $validator; | |
} | |
public function setRules(array $rules) | |
{ | |
$this->rules = $rules; | |
} | |
public function addRules(array $rules) | |
{ | |
$this->rules = array_merge($this->rules, $rules); | |
} | |
public function validate(array $data) | |
{ | |
$this->errors = []; | |
$this->validator->setRules($this->rules); | |
$this->validator->setData($data); | |
if ($this->validator->passes()) { | |
return true; | |
} | |
$this->errors = $this->validator->messages()->all(); | |
return false; | |
} | |
public function getErrors() | |
{ | |
return $this->errors; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment