Skip to content

Commit 718d67a

Browse files
committed
fix(parametervalidator): throws problem exception
1 parent 33df802 commit 718d67a

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/ParameterValidator/Exception/ValidationException.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,55 @@
1313

1414
namespace ApiPlatform\ParameterValidator\Exception;
1515

16+
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
17+
1618
/**
1719
* Filter validation exception.
1820
*
1921
* @author Julien DENIAU <[email protected]>
2022
*/
21-
final class ValidationException extends \Exception implements ValidationExceptionInterface
23+
final class ValidationException extends \Exception implements ValidationExceptionInterface, ProblemExceptionInterface
2224
{
25+
/**
26+
* @param string[] $constraintViolationList
27+
*/
2328
public function __construct(private readonly array $constraintViolationList, string $message = '', int $code = 0, \Exception $previous = null)
2429
{
2530
parent::__construct($message ?: $this->__toString(), $code, $previous);
2631
}
2732

33+
public function getConstraintViolationList(): array
34+
{
35+
return $this->constraintViolationList;
36+
}
37+
2838
public function __toString(): string
2939
{
3040
return implode("\n", $this->constraintViolationList);
3141
}
42+
43+
public function getType(): string
44+
{
45+
return '/parameter_validation/'.$this->code;
46+
}
47+
48+
public function getTitle(): ?string
49+
{
50+
return $this->message ?: $this->__toString();
51+
}
52+
53+
public function getStatus(): ?int
54+
{
55+
return 400;
56+
}
57+
58+
public function getDetail(): ?string
59+
{
60+
return $this->message ?: $this->__toString();
61+
}
62+
63+
public function getInstance(): ?string
64+
{
65+
return null;
66+
}
3267
}

src/Symfony/Validator/State/QueryParameterValidateProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
final class QueryParameterValidateProvider implements ProviderInterface
2525
{
26-
public function __construct(private readonly ProviderInterface $decorated, private readonly ParameterValidator $queryParameterValidator)
26+
public function __construct(private readonly ProviderInterface $decorated, private readonly ParameterValidator $parameterValidator)
2727
{
2828
}
2929

@@ -49,7 +49,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4949
$class = $options->getEntityClass();
5050
}
5151

52-
$this->queryParameterValidator->validateFilters($class, $operation->getFilters() ?? [], $queryParameters);
52+
$this->parameterValidator->validateFilters($class, $operation->getFilters() ?? [], $queryParameters);
5353

5454
return $this->decorated->provide($operation, $uriVariables, $context);
5555
}

0 commit comments

Comments
 (0)