Last active
June 8, 2016 20:20
-
-
Save Mulkave/f5020d74a585df90af1f2884794d51b3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Directory\Foundation; | |
class Validator | |
{ | |
protected $rules = []; | |
protected $validation; | |
public function __construct(Validation $validation) | |
{ | |
$this->validation = $validation; | |
} | |
public function validate($input, array $rules = []) | |
{ | |
$validation = $this->validation($input, $rules); | |
if ($validation->fails()) { | |
throw new InvalidInputException($validation->messages()); | |
} | |
return true; | |
} | |
public function validation($input, array $rules = []) | |
{ | |
// allow overriding with custom rules per call | |
if (empty($rules)) { | |
$rules = $this->rules; | |
} | |
return $this->validation->make($input, $rules); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment