Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion query-monitor/assets/build/query-monitor.css

Large diffs are not rendered by default.

60 changes: 29 additions & 31 deletions query-monitor/assets/build/query-monitor.js

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions query-monitor/classes/ArrayAccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php declare(strict_types = 1);
/**
* Array access trait for data transfer objects.
*
* Provides backwards compatibility for third party code that accesses
* QM data objects using array syntax.
*/

/**
* @implements \ArrayAccess<string,mixed>
*/
trait QM_ArrayAccess {
/**
* @param mixed $offset
* @param mixed $value
* @return void
*/
#[ReturnTypeWillChange]
final public function offsetSet( $offset, $value ) {
if ( is_string( $offset ) ) {
$this->$offset = $value;
}
}

/**
* @param mixed $offset
* @return bool
*/
#[ReturnTypeWillChange]
final public function offsetExists( $offset ) {
return is_string( $offset ) && isset( $this->$offset );
}

/**
* @param mixed $offset
* @return void
*/
#[ReturnTypeWillChange]
final public function offsetUnset( $offset ) {
if ( is_string( $offset ) ) {
unset( $this->$offset );
}
}

/**
* @param mixed $offset
* @return mixed
*/
#[ReturnTypeWillChange]
final public function &offsetGet( $offset ) {
if ( is_string( $offset ) ) {
return $this->$offset;
}
$null = null;
return $null;
}
}
2 changes: 1 addition & 1 deletion query-monitor/classes/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function set_up() {}
* @return string
*/
final public function id() {
return $this->id;
return "qm-{$this->id}";
}

/**
Expand Down
8 changes: 4 additions & 4 deletions query-monitor/classes/Collector_Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
*/
abstract class QM_Collector_Assets extends QM_DataCollector {
/**
* @var array<int, string>
* @var ?array<int, string>
*/
protected $header = array();
protected $header = null;

/**
* @var array<int, string>
Expand Down Expand Up @@ -106,7 +106,7 @@ public function action_head() {
* @return void
*/
public function action_print_footer_scripts() {
if ( empty( $this->header ) ) {
if ( null === $this->header ) {
return;
}

Expand All @@ -129,7 +129,7 @@ public function process() {
$modules = self::get_script_modules();
}

if ( empty( $this->header ) && empty( $this->footer ) && empty( $modules ) ) {
if ( null === $this->header && empty( $this->footer ) && empty( $modules ) ) {
return;
}

Expand Down
48 changes: 2 additions & 46 deletions query-monitor/classes/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
#[AllowDynamicProperties]
abstract class QM_Data implements \ArrayAccess {
use QM_ArrayAccess;

/**
* @var array<string, mixed>
*/
Expand All @@ -22,50 +24,4 @@ abstract class QM_Data implements \ArrayAccess {
* @var ?array<mixed>
*/
public $concerned_actions = null;

/**
* @param mixed $offset
* @param mixed $value
* @return void
*/
#[ReturnTypeWillChange]
final public function offsetSet( $offset, $value ) {
if ( is_string( $offset ) ) {
$this->$offset = $value;
}
}

/**
* @param mixed $offset
* @return bool
*/
#[ReturnTypeWillChange]
final public function offsetExists( $offset ) {
return is_string( $offset ) && isset( $this->$offset );
}

/**
* @param mixed $offset
* @return void
*/
#[ReturnTypeWillChange]
final public function offsetUnset( $offset ) {
// @TODO might be able to no-op this
if ( is_string( $offset ) ) {
unset( $this->$offset );
}
}

/**
* @param mixed $offset
* @return mixed
*/
#[ReturnTypeWillChange]
final public function &offsetGet( $offset ) {
if ( is_string( $offset ) ) {
return $this->$offset;
}
$null = null;
return $null;
}
}
4 changes: 2 additions & 2 deletions query-monitor/classes/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,15 @@ public static function shorten_fqn( $fqn ) {
/**
* Helper function for JSON encoding data and formatting it in a consistent manner.
*
* @deprecated Use json_encode() directly with the appropriate options instead.
* @deprecated Use wp_json_encode() directly with the appropriate options instead.
*
* @param mixed $data The data to be JSON encoded.
* @return string The JSON encoded data.
*/
public static function json_format( $data ) {
$json_options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES;

$json = json_encode( $data, $json_options );
$json = wp_json_encode( $data, $json_options );

if ( false === $json ) {
return '';
Expand Down
7 changes: 6 additions & 1 deletion query-monitor/data/block_editor/post_block.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* @package query-monitor
*/

class QM_Data_Post_Block {
/**
* @implements \ArrayAccess<string,mixed>
*/
class QM_Data_Post_Block implements \ArrayAccess {
use QM_ArrayAccess;

/**
* @var string|null
*/
Expand Down
7 changes: 6 additions & 1 deletion query-monitor/data/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* @package query-monitor
*/

class QM_Data_Callback {
/**
* @implements \ArrayAccess<string,mixed>
*/
class QM_Data_Callback implements \ArrayAccess {
use QM_ArrayAccess;

/**
* @var 'function'|'method'|'static_method'|'closure'|'invokable'|'lambda'|'unknown'|'unknown_closure'
*/
Expand Down
7 changes: 6 additions & 1 deletion query-monitor/data/callsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* @package query-monitor
*/

class QM_Data_Callsite {
/**
* @implements \ArrayAccess<string,mixed>
*/
class QM_Data_Callsite implements \ArrayAccess {
use QM_ArrayAccess;

/**
* @var string
*/
Expand Down
7 changes: 6 additions & 1 deletion query-monitor/data/frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* @package query-monitor
*/

class QM_Data_Stack_Frame {
/**
* @implements \ArrayAccess<string,mixed>
*/
class QM_Data_Stack_Frame implements \ArrayAccess {
use QM_ArrayAccess;

/**
* @var string
*/
Expand Down
7 changes: 6 additions & 1 deletion query-monitor/data/http/http_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* @package query-monitor
*/

class QM_Data_HTTP_Request {
/**
* @implements \ArrayAccess<string,mixed>
*/
class QM_Data_HTTP_Request implements \ArrayAccess {
use QM_ArrayAccess;

/**
* @phpstan-var array{
* method: string,
Expand Down
7 changes: 6 additions & 1 deletion query-monitor/data/http/http_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* @package query-monitor
*/

class QM_Data_HTTP_Response {
/**
* @implements \ArrayAccess<string,mixed>
*/
class QM_Data_HTTP_Response implements \ArrayAccess {
use QM_ArrayAccess;

/**
* @var int
*/
Expand Down
7 changes: 6 additions & 1 deletion query-monitor/data/php_error.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* @package query-monitor
*/

class QM_Data_PHP_Error {
/**
* @implements \ArrayAccess<string,mixed>
*/
class QM_Data_PHP_Error implements \ArrayAccess {
use QM_ArrayAccess;

/**
* @var int
*/
Expand Down
1 change: 0 additions & 1 deletion query-monitor/dispatchers/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public function output_fatal( $message, array $e ): void {
header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
}

// @TODO
echo wp_json_encode(
array(
'code' => 'qm_fatal',
Expand Down
30 changes: 20 additions & 10 deletions query-monitor/dispatchers/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,15 @@ public function dispatch() {

$this->before_output();

// Output non-client-side rendered panels outside the React container
// Output server-side rendered panels outside the React container.
// All outputters get a fallback container so that third-party plugins
// which extend a client-side rendered base class (e.g. QM_Output_Html_Logger)
// still have their PHP output available for the PhpPanelFallback component.
echo '<div id="query-monitor-fallbacks">';
foreach ( $this->outputters as $id => $output ) {
if ( ! $output::$client_side_rendered ) {
$html = $output->get_output();

if ( '' !== $html ) {
printf(
"\n" . '<!-- Begin %1$s output -->' . "\n",
esc_html( $id )
Expand All @@ -244,7 +249,7 @@ public function dispatch() {
"\n" . '<div class="qm-panel-container" id="qm-%1$s-container">' . "\n",
esc_html( $id )
);
$output->output();
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo "\n" . '</div>' . "\n";

printf(
Expand Down Expand Up @@ -328,11 +333,11 @@ protected function before_output() {
);
}

if ( ( ! empty( $collector->concerned_filters ) || ! empty( $collector->concerned_actions ) ) && isset( $this->panel_menu[ $output_id ] ) ) {
if ( ( ! empty( $collector->concerned_filters ) || ! empty( $collector->concerned_actions ) ) && isset( $this->panel_menu[ $collector->id() ] ) ) {
$count = count( $collector->concerned_filters ) + count( $collector->concerned_actions );
$this->panel_menu[ $output_id ]['children'][ $output_id . '-concerned_hooks' ] = array(
'id' => $collector->id() . '-concerned_hooks',
'panel' => $collector->id() . '-concerned_hooks',
$this->panel_menu[ $collector->id() ]['children'][ $collector->id . '-concerned_hooks' ] = array(
'id' => $collector->id . '-concerned_hooks',
'panel' => $collector->id . '-concerned_hooks',
'title' => __( 'Hooks in Use', 'query-monitor' ),
'count' => $count,
);
Expand Down Expand Up @@ -403,16 +408,21 @@ protected function before_output() {
'abspath' => QM_Util::normalize_path( ABSPATH ),
'contentpath' => QM_Util::normalize_path( dirname( WP_CONTENT_DIR ) . '/' ),
],
'number_format' => $wp_locale->number_format,
'number_format' => array(
'thousands_sep' => html_entity_decode( $wp_locale->number_format['thousands_sep'] ),
'decimal_point' => html_entity_decode( $wp_locale->number_format['decimal_point'] ),
),
'locale_data' => self::get_script_locale_data(),
);

$this->output_assets();

$encoded = wp_json_encode( $json, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG );

wp_print_inline_script_tag(
sprintf(
'var QueryMonitorData = %s;',
json_encode( $json, JSON_UNESCAPED_SLASHES )
false !== $encoded ? $encoded : 'false'
),
array(
'id' => 'query-monitor-inline-data',
Expand Down Expand Up @@ -642,7 +652,7 @@ public function output_fatal( $error, array $e ): void {

printf(
'<li>%s</li>',
QM_Output_Html::output_filename( $name, $frame['file'], $frame['line'] )
QM_Output_Html::output_filename( $name, $frame['file'] ?? '', $frame['line'] ?? 0 )
); // WPCS: XSS ok.
}
echo '</ol>';
Expand Down
2 changes: 1 addition & 1 deletion query-monitor/dispatchers/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function output_fatal( $message, array $e ): void {
header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
}

echo json_encode(
echo wp_json_encode(
array(
'code' => 'qm_fatal',
'message' => $message,
Expand Down
2 changes: 1 addition & 1 deletion query-monitor/output/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function output() {

foreach ( $this->get_output() as $key => $value ) {
if ( ! is_scalar( $value ) ) {
$value = json_encode( $value );
$value = wp_json_encode( $value );
}

# Remove illegal characters (Header value may not contain NUL bytes)
Expand Down
2 changes: 1 addition & 1 deletion query-monitor/output/headers/php_errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function get_output() {
);

$key = sprintf( 'error-%d', $count );
$headers[ $key ] = json_encode( $output_error );
$headers[ $key ] = wp_json_encode( $output_error );
}

return array_merge(
Expand Down
4 changes: 0 additions & 4 deletions query-monitor/output/html/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public function admin_menu( array $menu ) {
/** @var QM_Data_Assets $data */
$data = $this->collector->get_data();

if ( empty( $data->assets ) ) {
return $menu;
}

$type_label = $this->get_type_labels();

$args = array(
Expand Down
Loading
Loading