|
6 | 6 |
|
7 | 7 | use GuzzleHttp\Psr7\HttpFactory; |
8 | 8 | use SimpleAsFuck\ApiToolkit\Model\Server\RequestRules; |
| 9 | +use SimpleAsFuck\Validator\Factory\Exception; |
9 | 10 | use SimpleAsFuck\Validator\Model\RuleChain; |
10 | 11 | use SimpleAsFuck\Validator\Model\Validated; |
11 | 12 | use SimpleAsFuck\Validator\Rule\String\StringRule; |
|
14 | 15 |
|
15 | 16 | final class Validator |
16 | 17 | { |
17 | | - public static function make(Request $request): RequestRules |
| 18 | + public static function make(Request $request, Exception $exception = new BadRequestException()): RequestRules |
18 | 19 | { |
19 | 20 | $psrFactory = new HttpFactory(); |
20 | 21 | $factory = new PsrHttpFactory($psrFactory, $psrFactory, $psrFactory, $psrFactory); |
21 | 22 | $request = $factory->createRequest($request); |
22 | | - return new RequestRules(new BadRequestException(), $request); |
| 23 | + return new RequestRules($exception, $request); |
23 | 24 | } |
24 | 25 |
|
25 | 26 | /** |
26 | 27 | * @param non-empty-string $name |
27 | | - * @return StringRule |
28 | 28 | */ |
29 | | - public static function parameter(?string $value, string $name): StringRule |
| 29 | + public static function parameter(?string $value, string $name, Exception $exception = new BadRequestException()): StringRule |
30 | 30 | { |
31 | 31 | /** @var Validated<mixed> $value */ |
32 | 32 | $value = new Validated($value); |
33 | | - return new StringRule(new BadRequestException(), new RuleChain(), $value, 'Url path parameter: '.$name); |
| 33 | + return new StringRule($exception, new RuleChain(), $value, 'Url path parameter: '.$name); |
34 | 34 | } |
35 | 35 | } |
0 commit comments