Skip to content

Commit b61cc15

Browse files
committed
overriding of request validator exception type
1 parent 12f5dbd commit b61cc15

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/Factory/Server/Validator.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66

77
use Psr\Http\Message\ServerRequestInterface;
88
use SimpleAsFuck\ApiToolkit\Model\Server\RequestRules;
9+
use SimpleAsFuck\Validator\Factory\Exception;
910
use SimpleAsFuck\Validator\Model\RuleChain;
1011
use SimpleAsFuck\Validator\Model\Validated;
1112
use SimpleAsFuck\Validator\Rule\String\StringRule;
1213

1314
final class Validator
1415
{
15-
public static function make(ServerRequestInterface $request): RequestRules
16+
public static function make(ServerRequestInterface $request, Exception $exception = new ApiValidationException()): RequestRules
1617
{
17-
return new RequestRules(new ApiValidationException(), $request);
18+
return new RequestRules($exception, $request);
1819
}
1920

2021
/**
2122
* @param non-empty-string $name
2223
*/
23-
public static function parameter(?string $value, string $name): StringRule
24+
public static function parameter(?string $value, string $name, Exception $exception = new ApiValidationException()): StringRule
2425
{
2526
/** @var Validated<mixed> $value */
2627
$value = new Validated($value);
27-
return new StringRule(new ApiValidationException(), new RuleChain(), $value, 'Url path parameter: '.$name);
28+
return new StringRule($exception, new RuleChain(), $value, 'Url path parameter: '.$name);
2829
}
2930
}

src/Factory/Symfony/Validator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GuzzleHttp\Psr7\HttpFactory;
88
use SimpleAsFuck\ApiToolkit\Model\Server\RequestRules;
9+
use SimpleAsFuck\Validator\Factory\Exception;
910
use SimpleAsFuck\Validator\Model\RuleChain;
1011
use SimpleAsFuck\Validator\Model\Validated;
1112
use SimpleAsFuck\Validator\Rule\String\StringRule;
@@ -14,22 +15,21 @@
1415

1516
final class Validator
1617
{
17-
public static function make(Request $request): RequestRules
18+
public static function make(Request $request, Exception $exception = new BadRequestException()): RequestRules
1819
{
1920
$psrFactory = new HttpFactory();
2021
$factory = new PsrHttpFactory($psrFactory, $psrFactory, $psrFactory, $psrFactory);
2122
$request = $factory->createRequest($request);
22-
return new RequestRules(new BadRequestException(), $request);
23+
return new RequestRules($exception, $request);
2324
}
2425

2526
/**
2627
* @param non-empty-string $name
27-
* @return StringRule
2828
*/
29-
public static function parameter(?string $value, string $name): StringRule
29+
public static function parameter(?string $value, string $name, Exception $exception = new BadRequestException()): StringRule
3030
{
3131
/** @var Validated<mixed> $value */
3232
$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);
3434
}
3535
}

0 commit comments

Comments
 (0)