| 1 |
<?php |
| 2 |
/** |
| 3 |
* The preload monitor repository to store the status. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Preload\Monitor; |
| 11 |
|
| 12 |
/** |
| 13 |
* The preload monitor repository to store the status. |
| 14 |
* |
| 15 |
* @package SolidWP\Performance |
| 16 |
*/ |
| 17 |
final class Repository { |
| 18 |
|
| 19 |
public const OPTION = 'swpsp_preload_monitor'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Get preloader monitor status. |
| 23 |
* |
| 24 |
* @return array{count: int, last_activity: int, retries: int} |
| 25 |
*/ |
| 26 |
public function get(): array { |
| 27 |
return (array) get_option( self::OPTION, [] ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Set the current URL count, current time and retries to compare to later. |
| 32 |
* |
| 33 |
* @param int $url_count The current URL count. |
| 34 |
* @param int $retries The incremented retries. |
| 35 |
* |
| 36 |
* @return bool |
| 37 |
*/ |
| 38 |
public function set( int $url_count, int $retries = 0 ): bool { |
| 39 |
$status = [ |
| 40 |
'count' => $url_count, |
| 41 |
'last_activity' => time(), |
| 42 |
'retries' => $retries, |
| 43 |
]; |
| 44 |
|
| 45 |
return update_option( self::OPTION, $status, false ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Delete the monitor data. |
| 50 |
* |
| 51 |
* @return bool |
| 52 |
*/ |
| 53 |
public function delete(): bool { |
| 54 |
return delete_option( self::OPTION ); |
| 55 |
} |
| 56 |
} |
| 57 |
|