From 39f03e02bf9b0f0b8bbf64b393e044ca35329d5c Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Thu, 8 Feb 2018 14:58:43 +0200 Subject: [PATCH] Added provider interfaces. --- src/Bootable_Provider_Interface.php | 10 ++++++++ src/Events/Events_Provider_Interface.php | 8 ++++++ src/Laps.php | 31 +++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/Bootable_Provider_Interface.php create mode 100644 src/Events/Events_Provider_Interface.php diff --git a/src/Bootable_Provider_Interface.php b/src/Bootable_Provider_Interface.php new file mode 100644 index 0000000..e9e9374 --- /dev/null +++ b/src/Bootable_Provider_Interface.php @@ -0,0 +1,10 @@ +providers[] = $provider; + + parent::register( $provider, $values ); + + return $this; + } + /** * Start Stopwatch and timing plugin load immediately, then set up core events and needed hooks. */ @@ -50,6 +63,13 @@ class Laps extends Container { $events = new Core_Events(); $this->add_events( $events->get() ); + foreach ( $this->providers as $provider ) { + + if ( $provider instanceof Bootable_Provider_Interface ) { + $provider->boot( $this ); + } + } + add_action( 'pre_update_option_active_plugins', array( $this, 'pre_update_option_active_plugins' ) ); add_action( 'pre_update_site_option_active_sitewide_plugins', array( $this, 'pre_update_option_active_plugins' ) ); add_action( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); @@ -248,7 +268,16 @@ class Laps extends Container { $stopwatch->stop( 'Toolbar' ); } - $events = $stopwatch->getSectionEvents( '__root__' ); + $events = []; + + foreach ( $this->providers as $provider ) { + + if ( $provider instanceof Events_Provider_Interface ) { + $events[] = $provider->get_events(); + } + } + + $events = array_merge(...$events); $start = $timestart * 1000; $end = microtime( true ) * 1000; $total = $end - $start;