| 1 |
<?php |
| 2 |
/** |
| 3 |
* Diagnostics payload for support. |
| 4 |
* |
| 5 |
* @package EasyFonts |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace EasyFonts\Admin; |
| 9 |
|
| 10 |
use EasyFonts\Database\Migrator; |
| 11 |
use EasyFonts\Fonts\Registry; |
| 12 |
use EasyFonts\Fonts\Storage; |
| 13 |
use EasyFonts\Settings; |
| 14 |
|
| 15 |
defined( 'ABSPATH' ) || exit; |
| 16 |
|
| 17 |
/** |
| 18 |
* Builds an at-a-glance diagnostics report. |
| 19 |
*/ |
| 20 |
class Diagnostics { |
| 21 |
|
| 22 |
/** |
| 23 |
* Collect diagnostics. |
| 24 |
* |
| 25 |
* @return array<string,mixed> |
| 26 |
*/ |
| 27 |
public static function collect(): array { |
| 28 |
global $wp_version; |
| 29 |
|
| 30 |
$registry = new Registry(); |
| 31 |
$storage = new Storage(); |
| 32 |
$stats = $registry->stats(); |
| 33 |
$migrator = new Migrator(); |
| 34 |
|
| 35 |
return array( |
| 36 |
'plugin' => array( |
| 37 |
'version' => EASYFONTS_VERSION, |
| 38 |
'db_version' => get_option( 'easyfonts_db_version', '' ), |
| 39 |
'cache_dir' => EASYFONTS_CACHE_DIR, |
| 40 |
'cache_writable' => is_writable( dirname( EASYFONTS_CACHE_DIR ) ), |
| 41 |
), |
| 42 |
'environment' => array( |
| 43 |
'wp' => $wp_version, |
| 44 |
'php' => PHP_VERSION, |
| 45 |
'has_html_api' => class_exists( 'WP_HTML_Tag_Processor' ), |
| 46 |
'brotli' => function_exists( 'brotli_uncompress' ), |
| 47 |
'is_multisite' => is_multisite(), |
| 48 |
'ssl' => is_ssl(), |
| 49 |
), |
| 50 |
'tables' => $migrator->status(), |
| 51 |
'tables_ok' => $migrator->tables_ok(), |
| 52 |
'last_db_error' => Registry::last_error(), |
| 53 |
'settings' => Settings::all(), |
| 54 |
'detectors' => array( |
| 55 |
'learned' => (array) Settings::get( 'detectors', array() ), |
| 56 |
), |
| 57 |
'cache' => array( |
| 58 |
'families' => $stats['families'], |
| 59 |
'variants' => $stats['variants'], |
| 60 |
'hosted_kb' => (int) round( $stats['bytes'] / 1024 ), |
| 61 |
'total_kb' => (int) round( $storage->total_size() / 1024 ), |
| 62 |
), |
| 63 |
'generated' => current_time( 'mysql' ), |
| 64 |
); |
| 65 |
} |
| 66 |
} |
| 67 |
|