0, 'free' => 0, 'index' => 0, 'rows' => 0 ); public function __construct() { $this->_tables = Prepare::instance()->get_tables_status(); foreach ( $this->_tables as $table ) { $this->_totals['size'] += $table['size']; $this->_totals['free'] += $table['free']; $this->_totals['index'] += $table['index']; $this->_totals['rows'] += $table['rows']; } } public static function instance() : Database { static $instance = null; if ( is_null( $instance ) ) { $instance = new Database(); } return $instance; } public function total( string $name = '' ) { return $this->_totals[ $name ] ?? $this->_totals; } public function table( $name ) : array { $name = strtolower( $name ); return $this->_tables[ $name ] ?? $this->_empty_stats( $name ); } public function calculate( string $value, array $tables ) : int { $size = 0; if ( empty( $tables ) ) { foreach ( $this->_tables as $obj ) { $size += $obj[ $value ]; } } else { foreach ( $tables as $table ) { $name = Prepare::instance()->wpdb()->$table ?? ''; if ( ! empty( $name ) ) { $obj = $this->table( $name ); $size += $obj[ $value ]; } } } return $size; } private function _empty_stats( $name ) : array { return array( 'table' => $name, 'engine' => '', 'size' => 0, 'free' => 0, 'index' => 0, 'rows' => 0, 'average_row_size' => 0, 'auto_increment' => 0, 'created' => '', 'updated' => '', 'fragment' => 0 ); } }