Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
Browser | |
0.00% |
0 / 25 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
addRules | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | namespace NewfoldLabs\WP\Module\Performance\BurstSafetyMode; |
3 | |
4 | use WP_Forge\WP_Htaccess_Manager\htaccess; |
5 | |
6 | /** |
7 | * Browser cache. |
8 | */ |
9 | class Browser { |
10 | /** |
11 | * The file marker name. |
12 | * |
13 | * @var string |
14 | */ |
15 | const MARKER = 'Newfold Browser Cache'; |
16 | |
17 | /** |
18 | * Constructor. |
19 | */ |
20 | public function __construct() { |
21 | $responseHeaderManager = new ResponseHeaderManager(); |
22 | $responseHeaderManager->add_header( 'X-Newfold-Cache-Level', BURST_SAFETY_CACHE_LEVEL ); |
23 | $this->addRules(); |
24 | } |
25 | |
26 | /** |
27 | * Add htaccess rules. |
28 | */ |
29 | public static function addRules() { |
30 | |
31 | $file_typ_expirations = array( |
32 | 'default' => '1 week', |
33 | 'text/html' => '8 hours', |
34 | 'image/jpg' => '1 week', |
35 | 'image/jpeg' => '1 week', |
36 | 'image/gif' => '1 week', |
37 | 'image/png' => '1 week', |
38 | 'text/css' => '1 week', |
39 | 'text/javascript' => '1 week', |
40 | 'application/pdf' => '1 month', |
41 | 'image/x-icon' => '1 year', |
42 | ); |
43 | |
44 | $tab = "\t"; |
45 | |
46 | $rules[] = '<IfModule mod_expires.c>'; |
47 | $rules[] = "{$tab}ExpiresActive On"; |
48 | |
49 | foreach ( $file_typ_expirations as $file_type => $expiration ) { |
50 | if ( 'default' === $file_type ) { |
51 | $rules[] = "{$tab}ExpiresDefault \"access plus {$expiration}\""; |
52 | } else { |
53 | $rules[] = "{$tab}ExpiresByType {$file_type} \"access plus {$expiration}\""; |
54 | } |
55 | } |
56 | |
57 | $rules [] = '</IfModule>'; |
58 | |
59 | $htaccess = new htaccess( self::MARKER ); |
60 | |
61 | return $htaccess->addContent( $rules ); |
62 | } |
63 | } |