<html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><?php declare(strict_types = 1);
/**
 * Raw HTTP API request output.
 *
 * @package query-monitor
 */

class QM_Output_Raw_HTTP extends QM_Output_Raw {

	/**
	 * Collector instance.
	 *
	 * @var QM_Collector_HTTP Collector.
	 */
	protected $collector;

	/**
	 * @return string
	 */
	public function name() {
		return __( 'HTTP API Calls', 'query-monitor' );
	}

	/**
	 * @return array<string, mixed>
	 */
	public function get_output() {
		$output = array();
		/** @var QM_Data_HTTP $data */
		$data = $this->collector->get_data();

		if ( empty( $data->http ) ) {
			return $output;
		}

		$requests = array();

		foreach ( $data->http as $http ) {
			$stack = array();

			foreach ( $http['filtered_trace'] as $item ) {
				$stack[] = $item['display'];
			}

			$requests[] = array(
				'url' => $http['url'],
				'method' => $http['args']['method'],
				'response' => ( $http['response'] instanceof WP_Error ) ? $http['response']->get_error_message() : $http['response']['response'],
				'time' => round( $http['ltime'], 4 ),
				'stack' => $stack,
			);
		}

		$output['total'] = count( $requests );
		$output['time'] = round( $data->ltime, 4 );
		$output['requests'] = $requests;

		return $output;
	}
}

/**
 * @param array<string, 