diff --git a/composer.json b/composer.json
index 4f1df50..9998d79 100644
--- a/composer.json
+++ b/composer.json
@@ -10,6 +10,7 @@
}
],
"autoload": {
+ "psr-4": {"Underpin\\Debug_Bar_Extension\\": "lib/"},
"files": [
"debug-bar.php"
]
diff --git a/debug-bar.php b/debug-bar.php
index 542160f..db5d147 100644
--- a/debug-bar.php
+++ b/debug-bar.php
@@ -1,63 +1,26 @@
get( $file, $class )->loaders()->add( 'debug_bars', [
- 'registry' => '\Underpin_Debug_Bar_Extension\Loaders\Debug_Bars',
- ] );
- } );
-}, 3, 2 );
-
-// When a logger instance is added, also add a debug bar instance.
-add_action( 'underpin/loader_registered', function ( $key, $value, $loader, $parent_id ) {
- add_action( 'plugins_loaded', function () use ( $parent_id, $loader, $key ) {
-
- if ( ! class_exists( 'Debug_Bar_Panel' ) ) {
- return;
- }
-
- if ( $loader === 'Underpin_Logger\Loaders\Logger' ) {
- $name = Underpin::get_by_id( $parent_id )->name;
-
- // Due to an irritating limitation in the debug bar plugin, all class names must be unique, and free of invalid
- //characters, including a / character.
- // This frustration forces us to use eval, as there is no other way to create a unique class name, without slashes
- // Without manually creating new classes every time.
- // IF you are reading this, and have an idea on how this can be done without eval, we'd love to hear it.
-
- // Malform the class into an MD5. This keeps anyone from running anything cute.
- $class = 'Underpin_Debug_Panel_Instance_' . md5( $key . '_' . $parent_id );
- eval( 'class ' . $class . ' extends Underpin_Debug_Bar_Panel_Logger_Instance{}' );
-
- Underpin::get_by_id( $parent_id )->debug_bars()->add( $key, [
- 'class' => $class,
- 'args' => [
- 'title' => "$name ${key}s",
- 'parent_id' => $parent_id,
- 'logger_key' => $key,
- ],
- ] );
-
- }
- } );
-}, 10, 4 );
-
-add_action( 'underpin/logger/after_logged_item', function ( \Underpin_Logger\Factories\Log_Item $logged_item, $logger ) {
- do_action( 'qm/' . $logger->psr_level, $logged_item->code . ':' . $logged_item->message . "\n" . json_encode( $logged_item->data, JSON_PRETTY_PRINT ) );
-}, 10, 2 );
\ No newline at end of file
+// Attach query monitor to logged events.
+Logger::instance()->attach( 'event:logged', new \Underpin\Factories\Observer( 'query_monitor', [
+ 'update' => function ( Logger $logger, \Underpin\Factories\Simple_Storage $storage ) {
+ /* @var \Underpin\Factories\Log_Item $event */
+ $event = $storage->event;
+ /* @var Event_Type $event_type */
+ $event_type = $storage->event_type;
+
+ $data = array_merge( [
+ 'volume' => $event_type->volume,
+ 'group' => $event_type->group,
+ 'type' => $event_type->type,
+ ], $event->data );
+
+ do_action( 'qm/' . $event_type->psr_level, $event->code . ':' . $event->message . "\n" . json_encode( $data, JSON_PRETTY_PRINT ) );
+ },
+] ) );
\ No newline at end of file
diff --git a/lib/factories/Debug_Bar_Panel_Instance.php b/lib/factories/Debug_Bar_Panel_Instance.php
deleted file mode 100644
index b39cc89..0000000
--- a/lib/factories/Debug_Bar_Panel_Instance.php
+++ /dev/null
@@ -1,27 +0,0 @@
-set_values( $args );
- }
-
- public function init() {
- return $this->set_callable( 'init_callback' );
- }
-
-}
\ No newline at end of file
diff --git a/lib/factories/Debug_Bar_Panel_Logger_Instance.php b/lib/factories/Debug_Bar_Panel_Logger_Instance.php
deleted file mode 100644
index c4b3a61..0000000
--- a/lib/factories/Debug_Bar_Panel_Logger_Instance.php
+++ /dev/null
@@ -1,54 +0,0 @@
-set_visible( count( $this->get_logger() ) > 0 );
- }
-
- public function get_logger() {
- return $this->parent()->logger()->get( $this->logger_key );
- }
-
- public function render() {
- echo $this->get_template( 'wrapper' );
- }
-
- function debug_bar_classes( $classes ) {
- if ( in_array( $this->get_logger()->psr_level, [ 'emergency', 'alert', 'critical', 'error' ] ) && count( $this->get_logger() ) > 0 ) {
- $classes[] = 'debug-bar-php-warning-summary';
- }
- return $classes;
- }
-
- public function get_templates() {
- return [
- 'wrapper' => [],
- ];
- }
-
- protected function get_template_group() {
- return 'events';
- }
-
- protected function get_template_root_path() {
- return UNDERPIN_DEBUG_BAR_EXTENSION_ROOT_DIR . 'templates';
- }
-
-}
\ No newline at end of file
diff --git a/lib/loaders/Debug_Bars.php b/lib/loaders/Debug_Bars.php
deleted file mode 100644
index 99447a4..0000000
--- a/lib/loaders/Debug_Bars.php
+++ /dev/null
@@ -1,60 +0,0 @@
-do_actions();
- }
-
- /**
- * Fetches a debug bar panel
- *
- * @param string $key The instance key.
- *
- * @return \Debug_Bar_Panel|\WP_Error The panel if it exists, or WP_Error if not.
- */
- public function get( $key ) {
- return parent::get( $key );
- }
-
- /**
- * Do actions to set up panels.
- */
- public function do_actions() {
- add_filter( 'debug_bar_panels', [ $this, 'add_panels' ] );
- }
-
- /**
- * Registers panels.
- *
- * @param $panels
- *
- * @return mixed
- */
- public function add_panels( $panels ) {
- foreach ( (array) $this as $key => $panel ) {
- $panel = $this->get( $key );
- if ( ! is_wp_error( $panel ) ) {
- $panels[] = $panel;
- }
- }
-
- return $panels;
- }
-
- protected function set_default_items() {}
-
-}
\ No newline at end of file
diff --git a/templates/events/wrapper.php b/templates/events/wrapper.php
deleted file mode 100644
index 986c4df..0000000
--- a/templates/events/wrapper.php
+++ /dev/null
@@ -1,23 +0,0 @@
-get_logger() as $value ): ?>
-
- Code: = var_export( $value->code ) ?>
- Message: = var_export( $value->message ) ?>
- Ref: = var_export( $value->ref ) ?>
- Context: = var_export( $value->context ) ?>
-
- data as $key => $datum ): ?>
- = ucfirst( $key ) ?>: = var_export( $datum ) ?>
-
-