-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #74 `$_SERVER`, `$_GET`, `$_POST`
- Loading branch information
Showing
4 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types=1); | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
/** | ||
* @extends QM_DataCollector<QMX_Data_Globals> | ||
*/ | ||
class QMX_Collector_Globals extends QM_DataCollector { | ||
|
||
public $id = 'globals'; | ||
|
||
public function name() : string { | ||
return __( 'SERVER, GET, POST', 'query-monitor-extend' ); | ||
} | ||
|
||
public function get_storage(): QM_Data { | ||
require_once 'qmx-globals-data.php'; | ||
return new QMX_Data_Globals(); | ||
} | ||
|
||
public function process() : void { | ||
if ( did_action( 'qm/cease' ) ) { | ||
return; | ||
} | ||
|
||
$this->data['server'] = $_SERVER; | ||
|
||
if ( ! empty( $_GET ) ) { | ||
$this->data['get'] = $_GET; | ||
} | ||
|
||
if ( ! empty( $_POST ) ) { | ||
$this->data['post'] = $_POST; | ||
} | ||
} | ||
|
||
} | ||
|
||
add_filter( 'qm/collectors', static function ( array $collectors ) : array { | ||
$collectors['globals'] = new QMX_Collector_Globals; | ||
return $collectors; | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
class QMX_Data_Globals extends QM_Data { | ||
|
||
/** | ||
* @var array<string, scalar> | ||
*/ | ||
public $server; | ||
|
||
/** | ||
* @var array<string, scalar> | ||
*/ | ||
public $get; | ||
|
||
/** | ||
* @var array<string, scalar> | ||
*/ | ||
public $post; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
<?php declare(strict_types=1); | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
/** | ||
* @property-read QMX_Collector_Globals $collector | ||
*/ | ||
class QMX_Output_Html_Globals extends QM_Output_Html { | ||
|
||
public function __construct( QM_Collector $collector ) { | ||
parent::__construct( $collector ); | ||
add_filter( 'qm/output/panel_menus', array( &$this, 'panel_menu' ), 60 ); | ||
} | ||
|
||
public function output() { | ||
$data = $this->collector->get_data(); | ||
|
||
if ( ! empty( $data->server ) ) { | ||
$rows = $data->server; | ||
|
||
echo '<div class="qm" id="qm-global-server">'; | ||
|
||
echo '<table class="qm-sortable">'; | ||
echo '<caption class="qm-screen-reader-text">$_SERVER</caption>'; | ||
echo '<thead>'; | ||
echo '<tr>'; | ||
|
||
echo '<th scope="col" class="qm-num qm-sorted-asc qm-sortable-column">'; | ||
echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); | ||
echo '</th>'; | ||
|
||
echo '<th scope="col" class="qm-sortable-column">'; | ||
echo $this->build_sorter( __( 'Key', 'query-monitor-extend' ) ); | ||
echo '</th>'; | ||
|
||
echo '<th scope="col" class="qm-ltr">'; | ||
echo __( 'Value', 'query-monitor-extend' ); | ||
echo '</th>'; | ||
|
||
echo '</tr>'; | ||
echo '</thead>'; | ||
|
||
echo '<tbody>'; | ||
|
||
$bools = array( true => 'true', false => 'false' ); | ||
$i = 1; | ||
|
||
foreach ( $rows as $key => $value ) { | ||
echo '<tr>'; | ||
echo '<td class="qm-num">' . $i++ . '</td>'; | ||
echo '<td class="qm-ltr" data-qm-sort-weight="' . strtolower( esc_attr( $key ) ) . '"><code style="user-select: all;">' . esc_html( $key ) . '</code></td>'; | ||
echo '<td ' . ( is_bool( $value ) ? ' class="qm-' . $bools[ $value ] . '"' : '' ) . '>' . esc_html( (string) QM_Util::display_variable( $value ) ) . '</td>'; | ||
echo '</tr>'; | ||
} | ||
|
||
echo '</tbody>'; | ||
|
||
echo '</table>'; | ||
|
||
echo '</div>'; | ||
|
||
} | ||
|
||
if ( ! empty( $data->get ) ) { | ||
$rows = $data->get; | ||
|
||
echo '<div class="qm" id="qm-global-get">'; | ||
|
||
echo '<table class="qm-sortable">'; | ||
echo '<caption class="qm-screen-reader-text">$_GET</caption>'; | ||
echo '<thead>'; | ||
echo '<tr>'; | ||
|
||
echo '<th scope="col" class="qm-num qm-sorted-asc qm-sortable-column">'; | ||
echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); | ||
echo '</th>'; | ||
|
||
echo '<th scope="col" class="qm-sortable-column">'; | ||
echo $this->build_sorter( __( 'Key', 'query-monitor-extend' ) ); | ||
echo '</th>'; | ||
|
||
echo '<th scope="col" class="qm-ltr">'; | ||
echo __( 'Value', 'query-monitor-extend' ); | ||
echo '</th>'; | ||
|
||
echo '</tr>'; | ||
echo '</thead>'; | ||
|
||
echo '<tbody>'; | ||
|
||
$bools = array( true => 'true', false => 'false' ); | ||
$i = 1; | ||
|
||
foreach ( $rows as $key => $value ) { | ||
echo '<tr>'; | ||
echo '<td class="qm-num">' . $i++ . '</td>'; | ||
echo '<td class="qm-ltr" data-qm-sort-weight="' . strtolower( esc_attr( $key ) ) . '"><code style="user-select: all;">' . esc_html( $key ) . '</code></td>'; | ||
echo '<td ' . ( is_bool( $value ) ? ' class="qm-' . $bools[ $value ] . '"' : '' ) . '>' . esc_html( (string) QM_Util::display_variable( $value ) ) . '</td>'; | ||
echo '</tr>'; | ||
} | ||
|
||
echo '</tbody>'; | ||
|
||
echo '</table>'; | ||
|
||
echo '</div>'; | ||
|
||
} | ||
|
||
if ( ! empty( $data->post ) ) { | ||
$rows = $data->post; | ||
|
||
echo '<div class="qm" id="qm-global-post">'; | ||
|
||
echo '<table class="qm-sortable">'; | ||
echo '<caption class="qm-screen-reader-text">$_POST</caption>'; | ||
echo '<thead>'; | ||
echo '<tr>'; | ||
|
||
echo '<th scope="col" class="qm-num qm-sorted-asc qm-sortable-column">'; | ||
echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); | ||
echo '</th>'; | ||
|
||
echo '<th scope="col" class="qm-sortable-column">'; | ||
echo $this->build_sorter( __( 'Key', 'query-monitor-extend' ) ); | ||
echo '</th>'; | ||
|
||
echo '<th scope="col" class="qm-ltr">'; | ||
echo __( 'Value', 'query-monitor-extend' ); | ||
echo '</th>'; | ||
|
||
echo '</tr>'; | ||
echo '</thead>'; | ||
|
||
echo '<tbody>'; | ||
|
||
$bools = array( true => 'true', false => 'false' ); | ||
$i = 1; | ||
|
||
foreach ( $rows as $key => $value ) { | ||
echo '<tr>'; | ||
echo '<td class="qm-num">' . $i++ . '</td>'; | ||
echo '<td class="qm-ltr" data-qm-sort-weight="' . strtolower( esc_attr( $key ) ) . '"><code style="user-select: all;">' . esc_html( $key ) . '</code></td>'; | ||
echo '<td ' . ( is_bool( $value ) ? ' class="qm-' . $bools[ $value ] . '"' : '' ) . '>' . esc_html( (string) QM_Util::display_variable( $value ) ) . '</td>'; | ||
echo '</tr>'; | ||
} | ||
|
||
echo '</tbody>'; | ||
|
||
echo '</table>'; | ||
|
||
echo '</div>'; | ||
|
||
} | ||
|
||
} | ||
|
||
/** | ||
* @param array<string, array<string, mixed>> $menu | ||
* @return array<string, array<string, mixed>> | ||
*/ | ||
public function panel_menu( array $menu ) { | ||
$data = $this->collector->get_data(); | ||
|
||
if ( ! empty( $data->server ) ) { | ||
$menu['global-server'] = $this->menu( array( | ||
'title' => '$_SERVER', | ||
'id' => 'query-monitor-extend-global-server', | ||
'href' => '#qm-global-server', | ||
) ); | ||
} | ||
|
||
if ( ! empty( $data->get ) ) { | ||
$menu['global-get'] = $this->menu( array( | ||
'title' => '$_GET', | ||
'id' => 'query-monitor-extend-global-get', | ||
'href' => '#qm-global-get', | ||
) ); | ||
} | ||
|
||
if ( ! empty( $data->post ) ) { | ||
$menu['global-post'] = $this->menu( array( | ||
'title' => '$_POST', | ||
'id' => 'query-monitor-extend-global-post', | ||
'href' => '#qm-global-post', | ||
) ); | ||
} | ||
|
||
return $menu; | ||
} | ||
|
||
} | ||
|
||
add_filter( 'qm/outputter/html', static function ( array $output ) : array { | ||
if ( $collector = QM_Collectors::get( 'globals' ) ) { | ||
$output['globals'] = new QMX_Output_Html_Globals( $collector ); | ||
} | ||
|
||
return $output; | ||
}, 70 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ | |
'acf', | ||
'constants', | ||
'files', | ||
'globals', | ||
'heartbeat', | ||
'image-sizes', | ||
'paths', | ||
|