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), geolocation=(), camera=()', |
||
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() |
||
85 | |||
86 | /** |
||
87 | * Construct, loads default headers depending on the browser and environment. |
||
88 | */ |
||
89 | public function __construct() |
||
112 | |||
113 | /** |
||
114 | * Set header. |
||
115 | * |
||
116 | * @param string $key |
||
117 | * @param string $value |
||
118 | */ |
||
119 | public function setHeader(string $key, string $value) |
||
123 | |||
124 | /** |
||
125 | * Send headers. |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | public function send() |
||
141 | |||
142 | /** |
||
143 | * Get headers string. |
||
144 | * |
||
145 | * @return string[] |
||
146 | */ |
||
147 | public function getHeaders(): array |
||
158 | |||
159 | /** |
||
160 | * Load CSP directive. |
||
161 | * |
||
162 | * @return void |
||
163 | */ |
||
164 | public function loadCsp() |
||
167 | |||
168 | /** |
||
169 | * Get CSP headers string. |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getCspHeader(): string |
||
181 | } |
||
182 |
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.