1 | <?php |
||
17 | class Headers |
||
18 | { |
||
19 | /** |
||
20 | * Default header values. |
||
21 | * |
||
22 | * @var string[] |
||
23 | */ |
||
24 | protected $headers = [ |
||
25 | 'Access-Control-Allow-Methods' => 'GET, POST', |
||
26 | 'Access-Control-Allow-Origin' => '*', |
||
27 | 'Expires' => '-', |
||
28 | 'Last-Modified' => '-', |
||
29 | 'Pragma' => 'no-cache', |
||
30 | 'Cache-Control' => 'private, no-cache, no-store, must-revalidate, post-check=0, pre-check=0', |
||
31 | 'Content-Type' => 'text/html; charset=UTF-8', |
||
32 | 'Referrer-Policy' => 'no-referrer', |
||
33 | 'Permissions-Policy' => 'fullscreen=(self), camera=(), geolocation=()', |
||
34 | 'Cross-Origin-Embedder-Policy' => 'require-corp', |
||
35 | 'Cross-Origin-Opener-Policy: ' => 'same-origin', |
||
36 | 'Cross-Origin-Resource-Policy: ' => 'same-origin', |
||
37 | 'Expect-Ct' => 'enforce; max-age=3600', |
||
38 | 'X-Frame-Options' => 'sameorigin', |
||
39 | 'X-Xss-Protection' => '1; mode=block', |
||
40 | 'X-Content-Type-Options' => 'nosniff', |
||
41 | 'X-Robots-Tag' => 'none', |
||
42 | 'X-Permitted-Cross-Domain-Policies' => 'none', |
||
43 | ]; |
||
44 | /** |
||
45 | * Default CSP header values. |
||
46 | * |
||
47 | * @var string[] |
||
48 | */ |
||
49 | public $csp = [ |
||
50 | 'default-src' => '\'self\' blob:', |
||
51 | 'img-src' => '\'self\' data:', |
||
52 | 'script-src' => '\'self\' \'unsafe-inline\' blob:', |
||
53 | 'form-action' => '\'self\'', |
||
54 | 'frame-ancestors' => '\'self\'', |
||
55 | 'frame-src' => '\'self\' mailto: tel:', |
||
56 | 'style-src' => '\'self\' \'unsafe-inline\'', |
||
57 | 'connect-src' => '\'self\'', |
||
58 | ]; |
||
59 | /** |
||
60 | * Headers to delete. |
||
61 | * |
||
62 | * @var string[] |
||
63 | */ |
||
64 | protected $headersToDelete = ['X-Powered-By', 'Server']; |
||
65 | |||
66 | /** |
||
67 | * Headers instance.. |
||
68 | * |
||
69 | * @var self |
||
70 | */ |
||
71 | public static $instance; |
||
72 | |||
73 | /** |
||
74 | * Get headers instance. |
||
75 | * |
||
76 | * @return \self |
||
|
|||
77 | */ |
||
78 | public static function getInstance() |
||
88 | |||
89 | /** |
||
90 | * Construct, loads default headers depending on the browser and environment. |
||
91 | */ |
||
92 | public function __construct() |
||
118 | |||
119 | /** |
||
120 | * Set header. |
||
121 | * |
||
122 | * @param string $key |
||
123 | * @param string $value |
||
124 | */ |
||
125 | public function setHeader(string $key, string $value) |
||
129 | |||
130 | /** |
||
131 | * Send headers. |
||
132 | * |
||
133 | * @return void |
||
134 | */ |
||
135 | public function send(): void |
||
147 | |||
148 | /** |
||
149 | * Get headers string. |
||
150 | * |
||
151 | * @return string[] |
||
152 | */ |
||
153 | public function getHeaders(): array |
||
164 | |||
165 | /** |
||
166 | * Load CSP directive. |
||
167 | * |
||
168 | * @return void |
||
169 | */ |
||
170 | public function loadCsp() |
||
173 | |||
174 | /** |
||
175 | * Get CSP headers string. |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | public function getCspHeader(): string |
||
187 | |||
188 | /** |
||
189 | * Generate Content Security Policy token. |
||
190 | * |
||
191 | * @return void |
||
192 | */ |
||
193 | public static function generateCspToken(): void |
||
197 | } |
||
198 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.