-
-
Save heruputra/9832356 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 Smile\Services\Creators; | |
| use Illuminate\Validation\Factory as Validator; | |
| abstract class Creator implements CreatorInterface | |
| { | |
| protected $model; | |
| protected $errors; | |
| protected $rules = []; | |
| protected $messages = []; | |
| protected $input = []; | |
| public function __construct(Validator $validator) { | |
| $this->model = new $this->model; | |
| $this->validator = $validator; | |
| } | |
| abstract public function create($input); | |
| public function validate($input, $rules = array(), $messages = array()) | |
| { | |
| $validator = $this->validator->make($input, $rules, $messages); | |
| if($validator->passes()) | |
| { | |
| return true; | |
| } | |
| $this->errors = $validator->messages(); | |
| return false; | |
| } | |
| public function isValid($input = null) | |
| { | |
| $input = $input ?: $this->input; | |
| return $this->validate($input, $this->rules, $this->messages); | |
| } | |
| public function getErrors() | |
| { | |
| return $this->errors; | |
| } | |
| } |
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 Smile\Services\Creators; | |
| use Exception; | |
| class CreatorException extends Exception | |
| { | |
| protected $errors; | |
| public function __construct($errors, $code = 0, Exception $previous = null) | |
| { | |
| $this->errors = $errors; | |
| } | |
| public function getErrors() | |
| { | |
| return $this->errors; | |
| } | |
| } |
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 Smile\Services\Creators; | |
| interface CreatorInterface | |
| { | |
| public function create($input); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment