Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Browser | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addRules | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| removeRules | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * BurstSafetyMode\Browser |
| 4 | * |
| 5 | * Reuses the shared BrowserCacheFragment to emit browser caching rules during |
| 6 | * Burst Safety Mode. Registers a fragment with a fixed cache level defined by |
| 7 | * BURST_SAFETY_CACHE_LEVEL, and keeps the same human-readable marker for parity. |
| 8 | * |
| 9 | * Uses the centralized HtaccessApi to ensure safe, debounced writes. |
| 10 | * |
| 11 | * @package NewfoldLabs\WP\Module\Performance\BurstSafetyMode |
| 12 | * @since 1.0.0 |
| 13 | */ |
| 14 | |
| 15 | namespace NewfoldLabs\WP\Module\Performance\BurstSafetyMode; |
| 16 | |
| 17 | use NewfoldLabs\WP\Module\Htaccess\Api as HtaccessApi; |
| 18 | use NewfoldLabs\WP\Module\Performance\Cache\Types\Fragments\BrowserCacheFragment; |
| 19 | |
| 20 | /** |
| 21 | * Browser cache (Burst Safety Mode). |
| 22 | * |
| 23 | * Thin wrapper that registers the standard BrowserCacheFragment with a |
| 24 | * burst-mode cache level, and sets an identifying response header. |
| 25 | * |
| 26 | * @since 1.0.0 |
| 27 | */ |
| 28 | class Browser { |
| 29 | |
| 30 | /** |
| 31 | * Human-friendly marker label used in BEGIN/END comments. |
| 32 | * |
| 33 | * @var string |
| 34 | */ |
| 35 | const MARKER = 'Newfold Browser Cache'; |
| 36 | |
| 37 | /** |
| 38 | * Globally-unique fragment identifier (same as the primary Browser cache). |
| 39 | * |
| 40 | * Reusing the same ID ensures only a single Browser cache block exists in |
| 41 | * .htaccess. Last registration wins and replaces the prior one. |
| 42 | * |
| 43 | * @var string |
| 44 | */ |
| 45 | const FRAGMENT_ID = 'nfd.cache.browser'; |
| 46 | |
| 47 | /** |
| 48 | * Constructor. |
| 49 | * |
| 50 | * Sets an identifying response header and registers the fragment using the |
| 51 | * burst safety cache level. Exclusions are not applied in burst mode. |
| 52 | * |
| 53 | * @since 1.0.0 |
| 54 | */ |
| 55 | public function __construct() { |
| 56 | self::addRules(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Register (or replace) the Browser cache fragment with burst cache level. |
| 61 | * |
| 62 | * @since 1.0.0 |
| 63 | * @return void |
| 64 | */ |
| 65 | public static function addRules(): void { |
| 66 | HtaccessApi::register( |
| 67 | new BrowserCacheFragment( |
| 68 | self::FRAGMENT_ID, |
| 69 | self::MARKER, |
| 70 | (int) BURST_SAFETY_CACHE_LEVEL, // cache level (1–3) |
| 71 | '' // no exclusion pattern in burst mode |
| 72 | ), |
| 73 | true // queue apply to coalesce writes |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Unregister the Browser cache fragment. |
| 79 | * |
| 80 | * Provided for symmetry; call when exiting burst mode. |
| 81 | * |
| 82 | * @since 1.0.0 |
| 83 | * @return void |
| 84 | */ |
| 85 | public static function removeRules(): void { |
| 86 | HtaccessApi::unregister( self::FRAGMENT_ID ); |
| 87 | } |
| 88 | } |