1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/money-interop project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Money\Validator; |
10
|
|
|
|
11
|
|
|
use Assert\Assert; |
12
|
|
|
use Daikon\Boot\Middleware\Action\ValidatorInterface; |
13
|
|
|
use Daikon\Boot\Middleware\Action\ValidatorTrait; |
14
|
|
|
use Daikon\Boot\Middleware\ActionHandler; |
15
|
|
|
use Daikon\Money\Service\PaymentServiceInterface; |
16
|
|
|
use Daikon\Money\Service\PaymentServiceMap; |
17
|
|
|
|
18
|
|
|
final class PaymentServiceValidator implements ValidatorInterface |
19
|
|
|
{ |
20
|
|
|
use ValidatorTrait; |
|
|
|
|
21
|
|
|
|
22
|
|
|
private PaymentServiceMap $paymentServiceMap; |
23
|
|
|
|
24
|
|
|
private string $input; |
25
|
|
|
|
26
|
|
|
/** @var null|bool|string */ |
27
|
|
|
private $export; |
28
|
|
|
|
29
|
|
|
/** @var mixed */ |
30
|
|
|
private $default; |
31
|
|
|
|
32
|
|
|
private bool $required; |
33
|
|
|
|
34
|
|
|
private int $severity; |
35
|
|
|
|
36
|
|
|
private string $payload; |
37
|
|
|
|
38
|
|
|
private string $exportErrors; |
39
|
|
|
|
40
|
|
|
private string $exportErrorCode; |
41
|
|
|
|
42
|
|
|
private string $exportErrorSeverity; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param mixed $export |
46
|
|
|
* @param mixed $default |
47
|
|
|
*/ |
48
|
|
|
public function __construct( |
49
|
|
|
PaymentServiceMap $paymentServiceMap, |
50
|
|
|
string $input, |
51
|
|
|
$export = null, |
52
|
|
|
$default = null, |
53
|
|
|
bool $required = true, |
54
|
|
|
int $severity = self::SEVERITY_ERROR, |
55
|
|
|
string $payload = ActionHandler::ATTR_PAYLOAD, |
56
|
|
|
string $exportErrors = ActionHandler::ATTR_ERRORS, |
57
|
|
|
string $exportErrorCode = ActionHandler::ATTR_ERROR_CODE, |
58
|
|
|
string $exportErrorSeverity = ActionHandler::ATTR_ERROR_SEVERITY |
59
|
|
|
) { |
60
|
|
|
$this->paymentServiceMap = $paymentServiceMap; |
61
|
|
|
$this->input = $input; |
62
|
|
|
$this->export = $export; |
63
|
|
|
$this->default = $default; |
64
|
|
|
$this->required = $required; |
65
|
|
|
$this->severity = $severity; |
66
|
|
|
$this->payload = $payload; |
67
|
|
|
$this->exportErrors = $exportErrors; |
68
|
|
|
$this->exportErrorCode = $exportErrorCode; |
69
|
|
|
$this->exportErrorSeverity = $exportErrorSeverity; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** @param mixed $input */ |
73
|
|
|
private function validate(string $name, $input): PaymentServiceInterface |
74
|
|
|
{ |
75
|
|
|
Assert::that($input) |
76
|
|
|
->string('Must be a string.') |
77
|
|
|
->notBlank('Must not be empty.') |
78
|
|
|
->satisfy([$this->paymentServiceMap, 'has'], 'Unknown service.'); |
79
|
|
|
|
80
|
|
|
/** @var PaymentServiceInterface $service */ |
81
|
|
|
$service = $this->paymentServiceMap->get($input); |
82
|
|
|
|
83
|
|
|
return $service; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|