| @@ 9-35 (lines=27) @@ | ||
| 6 | use League\Tactician\Middleware; |
|
| 7 | use Hechoenlaravel\JarvisFoundation\Exceptions\FieldValidationException; |
|
| 8 | ||
| 9 | class EditFieldTypeValidator implements Middleware |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * Rules to validate a Field |
|
| 13 | * @var array |
|
| 14 | */ |
|
| 15 | protected $rules = [ |
|
| 16 | 'name' => 'required', |
|
| 17 | 'description' => 'required', |
|
| 18 | 'id' => 'required|exists:app_entities_fields,id', |
|
| 19 | ]; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param object $command |
|
| 23 | * @param callable $next |
|
| 24 | * |
|
| 25 | * @return mixed |
|
| 26 | */ |
|
| 27 | public function execute($command, callable $next) |
|
| 28 | { |
|
| 29 | $validator = Validator::make((array) $command, $this->rules); |
|
| 30 | if ($validator->fails()) { |
|
| 31 | throw new FieldValidationException($validator); |
|
| 32 | } |
|
| 33 | return $next($command); |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| @@ 13-41 (lines=29) @@ | ||
| 10 | * Class FieldGeneratorValidator |
|
| 11 | * @package Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware |
|
| 12 | */ |
|
| 13 | class FieldGeneratorValidator implements Middleware |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * Rules to validate a Field |
|
| 17 | * @var array |
|
| 18 | */ |
|
| 19 | protected $rules = [ |
|
| 20 | 'name' => 'required', |
|
| 21 | 'description' => 'required', |
|
| 22 | 'entity_id' => 'required|exists:app_entities,id', |
|
| 23 | 'type' => 'required' |
|
| 24 | ]; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Validate field type information |
|
| 28 | * @param object $command |
|
| 29 | * @param callable $next |
|
| 30 | * |
|
| 31 | * @return mixed |
|
| 32 | */ |
|
| 33 | public function execute($command, callable $next) |
|
| 34 | { |
|
| 35 | $validator = Validator::make((array) $command, $this->rules); |
|
| 36 | if ($validator->fails()) { |
|
| 37 | throw new FieldValidationException($validator); |
|
| 38 | } |
|
| 39 | return $next($command); |
|
| 40 | } |
|
| 41 | } |
|
| 42 | ||
| @@ 13-55 (lines=43) @@ | ||
| 10 | * Class EntityGeneratorValidator |
|
| 11 | * @package Hechoenlaravel\JarvisFoundation\EntityGenerator\Middleware |
|
| 12 | */ |
|
| 13 | class EntityGeneratorValidator implements Middleware |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @var |
|
| 17 | */ |
|
| 18 | public $validator; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * validation rules |
|
| 22 | * @var array |
|
| 23 | */ |
|
| 24 | public $rules = [ |
|
| 25 | 'name' => 'required', |
|
| 26 | 'description' => 'required', |
|
| 27 | 'slug' => 'required', |
|
| 28 | 'locked' => 'required|boolean' |
|
| 29 | ]; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @param Validator $validator |
|
| 33 | */ |
|
| 34 | public function __construct(Validator $validator) |
|
| 35 | { |
|
| 36 | $this->validator = $validator; |
|
| 37 | } |
|
| 38 | ||
| 39 | ||
| 40 | /** |
|
| 41 | * Validates the data coming into the handler |
|
| 42 | * @param object $command |
|
| 43 | * @param callable $next |
|
| 44 | * @return mixed |
|
| 45 | * @throws CommandValidationException |
|
| 46 | */ |
|
| 47 | public function execute($command, callable $next) |
|
| 48 | { |
|
| 49 | $validator = Validator::make((array) $command, $this->rules); |
|
| 50 | if ($validator->fails()) { |
|
| 51 | throw new CommandValidationException($validator); |
|
| 52 | } |
|
| 53 | return $next($command); |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||