Skip to content

Instantly share code, notes, and snippets.

@Mulkave
Last active June 8, 2016 20:20
Show Gist options
  • Save Mulkave/f5020d74a585df90af1f2884794d51b3 to your computer and use it in GitHub Desktop.
Save Mulkave/f5020d74a585df90af1f2884794d51b3 to your computer and use it in GitHub Desktop.
<?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