|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WebTheory\Saveyour\Report; |
|
4
|
|
|
|
|
5
|
|
|
use WebTheory\Saveyour\Contracts\Report\ProcessedFieldReportInterface; |
|
6
|
|
|
use WebTheory\Saveyour\Contracts\Report\ProcessedInputReportInterface; |
|
7
|
|
|
|
|
8
|
|
|
class ProcessedInputReport extends ProcessedFieldReport implements ProcessedInputReportInterface |
|
9
|
|
|
{ |
|
10
|
|
|
protected bool $requestVarPresent; |
|
11
|
|
|
|
|
12
|
|
|
protected ?string $rawInputValue = null; |
|
13
|
|
|
|
|
14
|
|
|
protected bool $validationStatus; |
|
15
|
|
|
|
|
16
|
|
|
protected array $ruleViolations; |
|
17
|
|
|
|
|
18
|
39 |
|
public function __construct( |
|
19
|
|
|
bool $requestVarPresent, |
|
20
|
|
|
?string $inputValue, |
|
21
|
|
|
$sanitizedInputValue, |
|
22
|
|
|
bool $updateAttempted, |
|
23
|
|
|
bool $updateSuccessful, |
|
24
|
|
|
bool $validationStatus, |
|
25
|
|
|
array $ruleViolations |
|
26
|
|
|
) { |
|
27
|
39 |
|
parent::__construct( |
|
28
|
|
|
$sanitizedInputValue, |
|
29
|
|
|
$updateAttempted, |
|
30
|
|
|
$updateSuccessful |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
39 |
|
$this->requestVarPresent = $requestVarPresent; |
|
34
|
39 |
|
$this->rawInputValue = $inputValue; |
|
35
|
39 |
|
$this->validationStatus = $validationStatus; |
|
36
|
39 |
|
$this->ruleViolations = $ruleViolations; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
9 |
|
public function requestVarPresent(): bool |
|
40
|
|
|
{ |
|
41
|
9 |
|
return $this->requestVarPresent; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
9 |
|
public function rawInputValue(): ?string |
|
45
|
|
|
{ |
|
46
|
9 |
|
return $this->rawInputValue; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
9 |
|
public function validationStatus(): bool |
|
50
|
|
|
{ |
|
51
|
9 |
|
return $this->validationStatus; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
9 |
|
public function ruleViolations(): array |
|
55
|
|
|
{ |
|
56
|
9 |
|
return $this->ruleViolations; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function toArray(): array |
|
60
|
|
|
{ |
|
61
|
|
|
return [ |
|
62
|
|
|
'request_var_present' => $this->requestVarPresent, |
|
63
|
|
|
'raw_input_value' => $this->rawInputValue, |
|
64
|
|
|
'validation_status' => $this->validationStatus, |
|
65
|
|
|
'rule_violations' => $this->ruleViolations, |
|
66
|
|
|
] + parent::toArray(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
3 |
|
public static function voided(): ProcessedInputReportInterface |
|
70
|
|
|
{ |
|
71
|
3 |
|
return new static(false, null, null, false, false, false, []); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
3 |
|
public static function invalid(string $input, array $violations): ProcessedInputReportInterface |
|
75
|
|
|
{ |
|
76
|
3 |
|
return new static(true, $input, null, false, false, false, $violations); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
3 |
|
public static function unprocessed(string $input): ProcessedInputReportInterface |
|
80
|
|
|
{ |
|
81
|
3 |
|
return new static(true, $input, null, false, false, true, []); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
30 |
|
public static function processed(string $input, ProcessedFieldReportInterface $field): ProcessedInputReportInterface |
|
85
|
|
|
{ |
|
86
|
30 |
|
return new static( |
|
87
|
|
|
true, |
|
88
|
|
|
$input, |
|
89
|
30 |
|
$field->sanitizedInputValue(), |
|
90
|
30 |
|
$field->updateAttempted(), |
|
91
|
30 |
|
$field->updateSuccessful(), |
|
92
|
|
|
true, |
|
93
|
30 |
|
[] |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|