1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebTheory\Saveyour\Report\Builder; |
4
|
|
|
|
5
|
|
|
use WebTheory\Saveyour\Contracts\Report\Builder\ProcessedInputReportBuilderInterface; |
6
|
|
|
use WebTheory\Saveyour\Contracts\Report\ProcessedInputReportInterface; |
7
|
|
|
use WebTheory\Saveyour\Report\ProcessedInputReport; |
8
|
|
|
|
9
|
|
|
class ProcessedInputReportBuilder extends ProcessedFieldReportBuilder implements ProcessedInputReportBuilderInterface |
10
|
|
|
{ |
11
|
|
|
protected bool $requestVarPresent; |
12
|
|
|
|
13
|
|
|
protected string $rawInputValue; |
14
|
|
|
|
15
|
|
|
protected bool $validationStatus; |
16
|
|
|
|
17
|
|
|
protected array $ruleViolations; |
18
|
|
|
|
19
|
|
|
public function __construct(ProcessedInputReportInterface $previous = null) |
20
|
|
|
{ |
21
|
|
|
if ($previous) { |
22
|
|
|
$this->requestVarPresent = $previous->requestVarPresent(); |
23
|
|
|
$this->rawInputValue = $previous->rawInputValue(); |
24
|
|
|
$this->sanitizedInputValue = $previous->sanitizedInputValue(); |
25
|
|
|
$this->updateAttempted = $previous->updateAttempted(); |
26
|
|
|
$this->updateSuccessful = $previous->updateSuccessful(); |
27
|
|
|
$this->validationStatus = $previous->validationStatus(); |
28
|
|
|
$this->ruleViolations = $previous->ruleViolations(); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return $this |
34
|
|
|
*/ |
35
|
|
|
public function withRequestVarPresent(bool $result): ProcessedInputReportBuilderInterface |
36
|
|
|
{ |
37
|
|
|
$this->requestVarPresent = $result; |
38
|
|
|
|
39
|
|
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
|
|
public function withRawInputValue(string $value): ProcessedInputReportBuilderInterface |
46
|
|
|
{ |
47
|
|
|
$this->rawInputValue = $value; |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return $this |
54
|
|
|
*/ |
55
|
|
|
public function withValidationStatus(bool $result): ProcessedInputReportBuilderInterface |
56
|
|
|
{ |
57
|
|
|
$this->validationStatus = $result; |
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
|
|
public function withRuleViolations(array $violations): ProcessedInputReportBuilderInterface |
66
|
|
|
{ |
67
|
|
|
$this->ruleViolations = $violations; |
68
|
|
|
|
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return $this |
74
|
|
|
*/ |
75
|
|
|
public function withRuleViolation(string $violation): ProcessedInputReportBuilderInterface |
76
|
|
|
{ |
77
|
|
|
$this->ruleViolations[] = $violation; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function build(): ProcessedInputReportInterface |
83
|
|
|
{ |
84
|
|
|
return new ProcessedInputReport( |
85
|
|
|
$this->requestVarPresent, |
86
|
|
|
$this->rawInputValue, |
87
|
|
|
$this->sanitizedInputValue, |
88
|
|
|
$this->updateAttempted, |
89
|
|
|
$this->updateSuccessful, |
90
|
|
|
$this->validationStatus, |
91
|
|
|
$this->ruleViolations |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|