| 1 |
<?php |
| 2 |
/** |
| 3 |
* The Preload Mode Manager, allows enabling/disabling and getting the status of |
| 4 |
* high performance mode. |
| 5 |
* |
| 6 |
* @package SolidWP\Performance |
| 7 |
*/ |
| 8 |
|
| 9 |
declare( strict_types=1 ); |
| 10 |
|
| 11 |
namespace SolidWP\Performance\Preload; |
| 12 |
|
| 13 |
use SolidWP\Performance\Config\Config; |
| 14 |
|
| 15 |
/** |
| 16 |
* The Preload Mode Manager, allows enabling/disabling and getting the status of |
| 17 |
* high performance mode. |
| 18 |
* |
| 19 |
* @package SolidWP\Performance |
| 20 |
*/ |
| 21 |
class Preload_Mode_Manager { |
| 22 |
|
| 23 |
/** |
| 24 |
* @var Config |
| 25 |
*/ |
| 26 |
private Config $config; |
| 27 |
|
| 28 |
/** |
| 29 |
* The preload high performance mode config key. |
| 30 |
* |
| 31 |
* @var string |
| 32 |
*/ |
| 33 |
private string $config_key; |
| 34 |
|
| 35 |
/** |
| 36 |
* @param Config $config The config object. |
| 37 |
* @param string $config_key The preload high performance mode config key. |
| 38 |
*/ |
| 39 |
public function __construct( Config $config, string $config_key = 'page_cache.preload.high_performance_mode' ) { |
| 40 |
$this->config = $config; |
| 41 |
$this->config_key = $config_key; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Check if high performance mode is enabled. |
| 46 |
* |
| 47 |
* @return bool |
| 48 |
*/ |
| 49 |
public function is_high_performance_mode(): bool { |
| 50 |
return (bool) $this->config->refresh()->get( $this->config_key ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Enable high performance mode. |
| 55 |
* |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
public function enable_high_performance_mode(): void { |
| 59 |
$this->config->set( $this->config_key, true )->save(); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Disable high performance mode. |
| 64 |
* |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
public function disable_high_performance_mode(): void { |
| 68 |
$this->config->set( $this->config_key, false )->save(); |
| 69 |
} |
| 70 |
} |
| 71 |
|