@@ -40,14 +40,9 @@ public function setNonce(Nonce $nonce): Policy
40
40
return $ this ;
41
41
}
42
42
43
- public function isReportOnly (): bool
44
- {
45
- return $ this ->reportOnly ;
46
- }
47
-
48
43
public function getSecurityHeaderKey (): string
49
44
{
50
- if ($ this ->isReportOnly () ) {
45
+ if ($ this ->reportOnly ) {
51
46
return self ::SECURITY_HEADER_KEY_REPORT_ONLY ;
52
47
}
53
48
@@ -59,10 +54,16 @@ public function getDirectives(): array
59
54
return $ this ->directives ;
60
55
}
61
56
57
+ public function hasNonceDirectiveValue (): bool
58
+ {
59
+ return $ this ->hasNonceDirectiveValue ;
60
+ }
61
+
62
62
/**
63
+ * @param string[] $values
63
64
* @throws InvalidDirectiveException
64
65
*/
65
- public function addDirective (string $ directive , $ values ): self
66
+ public function addDirective (string $ directive , array $ values ): self
66
67
{
67
68
if (! Directive::isValidDirective ($ directive )) {
68
69
throw new InvalidDirectiveException ($ directive );
@@ -74,16 +75,6 @@ public function addDirective(string $directive, $values): self
74
75
return $ this ;
75
76
}
76
77
77
- public function getNonce (): Nonce
78
- {
79
- return $ this ->nonce ;
80
- }
81
-
82
- public function hasNonceDirectiveValue (): bool
83
- {
84
- return $ this ->hasNonceDirectiveValue ;
85
- }
86
-
87
78
public function __toString (): string
88
79
{
89
80
$ directives = $ this ->getDirectives ();
@@ -95,26 +86,21 @@ public function __toString(): string
95
86
return "$ directive $ value " ;
96
87
}, $ directives , $ keys );
97
88
98
- return implode ('; ' , $ items ).'; ' ;
89
+ return implode ('; ' , $ items ).'; ' ;
99
90
}
100
91
101
92
private function sanitizeValue (string $ value ): string
102
93
{
103
- if ($ this -> isSpecialValue ($ value )) {
94
+ if (in_array ($ value, self :: SPECIAL_DIRECTIVES )) {
104
95
return "' $ value' " ;
105
96
}
106
97
107
98
if ($ value === '{nonce} ' ) {
108
99
$ this ->hasNonceDirectiveValue = true ;
109
100
110
- return "'nonce- " .$ this ->getNonce () ->getValue ()."' " ;
101
+ return "'nonce- " .$ this ->nonce ->getValue ()."' " ;
111
102
}
112
103
113
104
return $ value ;
114
105
}
115
-
116
- private function isSpecialValue (string $ directive ): bool
117
- {
118
- return in_array ($ directive , self ::SPECIAL_DIRECTIVES );
119
- }
120
106
}
0 commit comments