Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Skip404 | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addRules | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| removeRules | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * BurstSafetyMode\Skip404 |
| 4 | * |
| 5 | * Reuses the existing Skip404 fragment to register/unregister the .htaccess |
| 6 | * rules that short-circuit WordPress 404 handling for static-like requests. |
| 7 | * Uses the centralized HtaccessApi to ensure safe, debounced writes. |
| 8 | * |
| 9 | * @package NewfoldLabs\WP\Module\Performance\BurstSafetyMode |
| 10 | * @since 1.0.0 |
| 11 | */ |
| 12 | |
| 13 | namespace NewfoldLabs\WP\Module\Performance\BurstSafetyMode; |
| 14 | |
| 15 | use NewfoldLabs\WP\Module\Htaccess\Api as HtaccessApi; |
| 16 | use NewfoldLabs\WP\Module\Performance\Skip404\Fragments\Skip404Fragment; |
| 17 | |
| 18 | /** |
| 19 | * Skip 404 cache type (Burst Safety Mode). |
| 20 | * |
| 21 | * Thin wrapper that reuses the shared Skip404Fragment from the Performance |
| 22 | * module to manage the same static-file skip rules under Burst Safety Mode. |
| 23 | * |
| 24 | * @since 1.0.0 |
| 25 | */ |
| 26 | class Skip404 { |
| 27 | |
| 28 | /** |
| 29 | * Human-friendly marker shown in BEGIN/END comments inside .htaccess. |
| 30 | * |
| 31 | * @var string |
| 32 | */ |
| 33 | const MARKER = 'Newfold Skip 404 Handling for Static Files'; |
| 34 | |
| 35 | /** |
| 36 | * Globally-unique fragment identifier used by the registry. |
| 37 | * |
| 38 | * Reusing the same ID as the primary Skip404 ensures there is a single |
| 39 | * source of truth for this block in .htaccess. |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | const FRAGMENT_ID = 'nfd.skip404.static'; |
| 44 | |
| 45 | /** |
| 46 | * Constructor. |
| 47 | * |
| 48 | * Registers the fragment immediately. |
| 49 | * |
| 50 | * @since 1.0.0 |
| 51 | */ |
| 52 | public function __construct() { |
| 53 | self::addRules(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Register (or replace) the shared Skip404 fragment. |
| 58 | * |
| 59 | * @since 1.0.0 |
| 60 | * @return void |
| 61 | */ |
| 62 | public static function addRules(): void { |
| 63 | HtaccessApi::register( |
| 64 | new Skip404Fragment( |
| 65 | self::FRAGMENT_ID, |
| 66 | self::MARKER |
| 67 | ), |
| 68 | true // queue apply to coalesce writes |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Unregister the shared Skip404 fragment. |
| 74 | * |
| 75 | * @since 1.0.0 |
| 76 | * @return void |
| 77 | */ |
| 78 | public static function removeRules(): void { |
| 79 | HtaccessApi::unregister( self::FRAGMENT_ID ); |
| 80 | } |
| 81 | } |