mirror of
https://github.com/felixfoertsch/wordpress-dev-env.git
synced 2026-04-18 15:28:44 +02:00
Initial commit
This commit is contained in:
58
wordpress_plugins/query-monitor/output/headers/overview.php
Normal file
58
wordpress_plugins/query-monitor/output/headers/overview.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* General overview output for HTTP headers.
|
||||
*
|
||||
* @package query-monitor
|
||||
*/
|
||||
|
||||
class QM_Output_Headers_Overview extends QM_Output_Headers {
|
||||
|
||||
/**
|
||||
* Collector instance.
|
||||
*
|
||||
* @var QM_Collector_Overview Collector.
|
||||
*/
|
||||
protected $collector;
|
||||
|
||||
public function get_output() {
|
||||
|
||||
$data = $this->collector->get_data();
|
||||
$headers = array();
|
||||
|
||||
$headers['time_taken'] = number_format_i18n( $data['time_taken'], 4 );
|
||||
$headers['time_usage'] = sprintf(
|
||||
/* translators: 1: Percentage of time limit used, 2: Time limit in seconds */
|
||||
__( '%1$s%% of %2$ss limit', 'query-monitor' ),
|
||||
number_format_i18n( $data['time_usage'], 1 ),
|
||||
number_format_i18n( $data['time_limit'] )
|
||||
);
|
||||
|
||||
if ( ! empty( $data['memory'] ) ) {
|
||||
$headers['memory'] = sprintf(
|
||||
/* translators: %s: Memory used in kilobytes */
|
||||
__( '%s kB', 'query-monitor' ),
|
||||
number_format_i18n( $data['memory'] / 1024 )
|
||||
);
|
||||
$headers['memory_usage'] = sprintf(
|
||||
/* translators: 1: Percentage of memory limit used, 2: Memory limit in kilobytes */
|
||||
__( '%1$s%% of %2$s kB limit', 'query-monitor' ),
|
||||
number_format_i18n( $data['memory_usage'], 1 ),
|
||||
number_format_i18n( $data['memory_limit'] / 1024 )
|
||||
);
|
||||
}
|
||||
|
||||
return $headers;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function register_qm_output_headers_overview( array $output, QM_Collectors $collectors ) {
|
||||
$collector = QM_Collectors::get( 'overview' );
|
||||
if ( $collector ) {
|
||||
$output['overview'] = new QM_Output_Headers_Overview( $collector );
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
add_filter( 'qm/outputter/headers', 'register_qm_output_headers_overview', 10, 2 );
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP error output for HTTP headers.
|
||||
*
|
||||
* @package query-monitor
|
||||
*/
|
||||
class QM_Output_Headers_PHP_Errors extends QM_Output_Headers {
|
||||
|
||||
/**
|
||||
* Collector instance.
|
||||
*
|
||||
* @var QM_Collector_PHP_Errors Collector.
|
||||
*/
|
||||
protected $collector;
|
||||
|
||||
public function get_output() {
|
||||
|
||||
$data = $this->collector->get_data();
|
||||
$headers = array();
|
||||
|
||||
if ( empty( $data['errors'] ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ( $data['errors'] as $type => $errors ) {
|
||||
|
||||
foreach ( $errors as $error_key => $error ) {
|
||||
|
||||
$count++;
|
||||
|
||||
# @TODO we should calculate the component during process() so we don't need to do it
|
||||
# separately in each output.
|
||||
if ( $error['trace'] ) {
|
||||
$component = $error['trace']->get_component()->name;
|
||||
$stack = $error['trace']->get_stack();
|
||||
} else {
|
||||
$component = __( 'Unknown', 'query-monitor' );
|
||||
$stack = array();
|
||||
}
|
||||
|
||||
$output_error = array(
|
||||
'key' => $error_key,
|
||||
'type' => $error['type'],
|
||||
'message' => $error['message'],
|
||||
'file' => QM_Util::standard_dir( $error['file'], '' ),
|
||||
'line' => $error['line'],
|
||||
'stack' => $stack,
|
||||
'component' => $component,
|
||||
);
|
||||
|
||||
$key = sprintf( 'error-%d', $count );
|
||||
$headers[ $key ] = json_encode( $output_error );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
array(
|
||||
'error-count' => $count,
|
||||
),
|
||||
$headers
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function register_qm_output_headers_php_errors( array $output, QM_Collectors $collectors ) {
|
||||
$collector = QM_Collectors::get( 'php_errors' );
|
||||
if ( $collector ) {
|
||||
$output['php_errors'] = new QM_Output_Headers_PHP_Errors( $collector );
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
add_filter( 'qm/outputter/headers', 'register_qm_output_headers_php_errors', 110, 2 );
|
||||
40
wordpress_plugins/query-monitor/output/headers/redirects.php
Normal file
40
wordpress_plugins/query-monitor/output/headers/redirects.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* HTTP redirects output for HTTP headers.
|
||||
*
|
||||
* @package query-monitor
|
||||
*/
|
||||
class QM_Output_Headers_Redirects extends QM_Output_Headers {
|
||||
|
||||
/**
|
||||
* Collector instance.
|
||||
*
|
||||
* @var QM_Collector_Redirects Collector.
|
||||
*/
|
||||
protected $collector;
|
||||
|
||||
public function get_output() {
|
||||
|
||||
$data = $this->collector->get_data();
|
||||
$headers = array();
|
||||
|
||||
if ( empty( $data['trace'] ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$headers['Redirect-Trace'] = implode( ', ', $data['trace']->get_stack() );
|
||||
return $headers;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function register_qm_output_headers_redirects( array $output, QM_Collectors $collectors ) {
|
||||
$collector = QM_Collectors::get( 'redirects' );
|
||||
if ( $collector ) {
|
||||
$output['redirects'] = new QM_Output_Headers_Redirects( $collector );
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
add_filter( 'qm/outputter/headers', 'register_qm_output_headers_redirects', 140, 2 );
|
||||
Reference in New Issue
Block a user