| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Stats\Rest; |
| 4 |
|
| 5 |
use ImageOptimization\Modules\Stats\Classes\{ |
| 6 |
Route_Base, |
| 7 |
Stats |
| 8 |
}; |
| 9 |
use Throwable; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly. |
| 13 |
} |
| 14 |
|
| 15 |
class Get_Stats extends Route_Base { |
| 16 |
protected string $path = ''; |
| 17 |
|
| 18 |
public function get_name(): string { |
| 19 |
return 'get-stats'; |
| 20 |
} |
| 21 |
|
| 22 |
public function get_methods(): array { |
| 23 |
return [ 'GET' ]; |
| 24 |
} |
| 25 |
|
| 26 |
public function GET() { |
| 27 |
try { |
| 28 |
return $this->respond_success_json( Stats::calculate_global_stats() ); |
| 29 |
} catch ( Throwable $t ) { |
| 30 |
return $this->respond_error_json([ |
| 31 |
'message' => $t->getMessage(), |
| 32 |
'code' => 'internal_server_error', |
| 33 |
]); |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
|