1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* It's free open-source software released under the MIT License. |
5
|
|
|
* |
6
|
|
|
* @author Anatoly Nekhay <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2018, Anatoly Nekhay |
8
|
|
|
* @license https://github.com/sunrise-php/http-router/blob/master/LICENSE |
9
|
|
|
* @link https://github.com/sunrise-php/http-router |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sunrise\Http\Router\Validation\ConstraintViolation; |
15
|
|
|
|
16
|
|
|
use Sunrise\Http\Router\Dictionary\TranslationDomain; |
17
|
|
|
use Sunrise\Http\Router\Validation\ConstraintViolationInterface as RouterConstraintViolationInterface; |
18
|
|
|
use Symfony\Component\Validator\ConstraintViolationInterface as ValidatorConstraintViolationInterface; |
19
|
|
|
|
20
|
|
|
use function preg_replace; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @since 3.0.0 |
24
|
|
|
*/ |
25
|
|
|
final class ValidatorConstraintViolationAdapter implements RouterConstraintViolationInterface |
26
|
|
|
{ |
27
|
6 |
|
public function __construct( |
28
|
|
|
private readonly ValidatorConstraintViolationInterface $validatorConstraintViolation, |
29
|
|
|
) { |
30
|
6 |
|
} |
31
|
|
|
|
32
|
5 |
|
public static function create(ValidatorConstraintViolationInterface $validatorConstraintViolation): self |
33
|
|
|
{ |
34
|
5 |
|
return new self($validatorConstraintViolation); |
35
|
|
|
} |
36
|
|
|
|
37
|
6 |
|
public function getMessage(): string |
38
|
|
|
{ |
39
|
6 |
|
return (string) $this->validatorConstraintViolation->getMessage(); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function getMessageTemplate(): string |
43
|
|
|
{ |
44
|
1 |
|
return $this->validatorConstraintViolation->getMessageTemplate(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritDoc |
49
|
|
|
*/ |
50
|
1 |
|
public function getMessagePlaceholders(): array |
51
|
|
|
{ |
52
|
|
|
/** @var array<string, mixed> */ |
53
|
1 |
|
return $this->validatorConstraintViolation->getParameters(); |
54
|
|
|
} |
55
|
|
|
|
56
|
6 |
|
public function getPropertyPath(): string |
57
|
|
|
{ |
58
|
6 |
|
return self::adaptPropertyPath($this->validatorConstraintViolation->getPropertyPath()); |
59
|
|
|
} |
60
|
|
|
|
61
|
6 |
|
public function getCode(): ?string |
62
|
|
|
{ |
63
|
6 |
|
return $this->validatorConstraintViolation->getCode(); |
64
|
|
|
} |
65
|
|
|
|
66
|
6 |
|
public function getInvalidValue(): mixed |
67
|
|
|
{ |
68
|
6 |
|
return $this->validatorConstraintViolation->getInvalidValue(); |
69
|
|
|
} |
70
|
|
|
|
71
|
6 |
|
private static function adaptPropertyPath(string $propertyPath): string |
72
|
|
|
{ |
73
|
6 |
|
return (string) preg_replace(['/\x5b([^\x5b\x5d]+)\x5d/', '/^\x2e/'], ['.$1'], $propertyPath); |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function getTranslationDomain(): string |
77
|
|
|
{ |
78
|
1 |
|
return TranslationDomain::VALIDATOR; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|