| 1 |
<?php |
| 2 |
/** |
| 3 |
* The route for getting how many pages are cached. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace SolidWP\Performance\API\Routes\Page_Cache; |
| 9 |
|
| 10 |
use SolidWP\Performance\API\Base_Route; |
| 11 |
use SolidWP\Performance\Page_Cache\Cache_Path; |
| 12 |
use WP_REST_Request; |
| 13 |
use WP_REST_Response; |
| 14 |
use WP_REST_Server; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* The route for getting how many pages are cached. |
| 22 |
* |
| 23 |
* @package SolidWP\Performance |
| 24 |
*/ |
| 25 |
final class Cache_Count extends Base_Route { |
| 26 |
|
| 27 |
/** |
| 28 |
* @var Cache_Path |
| 29 |
*/ |
| 30 |
private Cache_Path $cache_path; |
| 31 |
|
| 32 |
/** |
| 33 |
* @param Cache_Path $cache_path The cache path object. |
| 34 |
*/ |
| 35 |
public function __construct( Cache_Path $cache_path ) { |
| 36 |
$this->cache_path = $cache_path; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* {@inheritdoc} |
| 41 |
*/ |
| 42 |
public function get_path(): string { |
| 43 |
return '/page/cache-count'; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* {@inheritdoc} |
| 48 |
*/ |
| 49 |
public function get_methods() { |
| 50 |
return WP_REST_Server::READABLE; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* {@inheritdoc} |
| 55 |
*/ |
| 56 |
public function callback( WP_REST_Request $request ) { |
| 57 |
return new WP_REST_Response( |
| 58 |
[ |
| 59 |
'count' => $this->cache_path->count(), |
| 60 |
] |
| 61 |
); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* {@inheritdoc} |
| 66 |
*/ |
| 67 |
public function schema_callback(): array { |
| 68 |
return [ |
| 69 |
'$schema' => 'http://json-schema.org/draft-04/schema#', |
| 70 |
'title' => 'cache count', |
| 71 |
'type' => 'object', |
| 72 |
'properties' => [ |
| 73 |
'count' => [ |
| 74 |
'description' => esc_html__( 'How many cached pages this site has across all compression types', 'solid-performance' ), |
| 75 |
'type' => 'int', |
| 76 |
'readonly' => true, |
| 77 |
], |
| 78 |
], |
| 79 |
]; |
| 80 |
} |
| 81 |
} |
| 82 |
|