Added provider interfaces.

This commit is contained in:
Andrey Savchenko committed 2018-02-08 14:58:43 +02:00
1 parent 6fc8a648ad
commit 39f03e02bf
3 files changed
+48 -1

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Rarst\Laps;
use Rarst\Laps\Laps;
interface Bootable_Provider_Interface {
public function boot( Laps $laps );
}
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace Rarst\Laps\Events;
interface Events_Provider_Interface {
public function get_events();
}
+30 -1
View File
@@ -5,6 +5,8 @@ namespace Rarst\Laps;
use Pimple\Container;
use Rarst\Laps\Events\Core_Events;
use Rarst\Laps\Events\Laps_Events;
use Pimple\ServiceProviderInterface;
use Rarst\Laps\Events\Events_Provider_Interface;
use Symfony\Component\Stopwatch\Stopwatch;
/**
@@ -15,6 +17,8 @@ class Laps extends Container {
public $events = array();
public $query_starts = array();
protected $providers = [];
public function __construct( array $values = [] ) {
parent::__construct();
@@ -37,6 +41,15 @@ class Laps extends Container {
}
}
public function register( ServiceProviderInterface $provider, array $values = [] ) {
$this->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;