Added proper providers to handle registration and boot.
This commit is contained in:
1 parent
48b3383e06
commit
06e3bb4657
10 files changed
+95
-97
No files matched your search
+5
-32
@@ -4,14 +4,9 @@ namespace Rarst\Laps;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Record\Record_Collector_Interface;
|
||||
use Rarst\Laps\Record\Hook_Record_Collector;
|
||||
use Rarst\Laps\Record\Http_Record_Collector;
|
||||
use Rarst\Laps\Record\Sql_Record_Collector;
|
||||
use Rarst\Laps\Manager\Asset_Manager;
|
||||
use Rarst\Laps\Manager\Load_Order_Manager;
|
||||
use Rarst\Laps\Manager\Toolbar_Manager;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Rarst\Laps\Provider\Bootable_Provider_Interface;
|
||||
use Rarst\Laps\Provider\Manager_Provider;
|
||||
use Rarst\Laps\Provider\Record_Provider;
|
||||
|
||||
/**
|
||||
* Main plugin's class.
|
||||
@@ -33,30 +28,8 @@ class Laps extends Container {
|
||||
] );
|
||||
};
|
||||
|
||||
$laps['stopwatch'] = $laps->factory( function () {
|
||||
return new Stopwatch();
|
||||
} );
|
||||
|
||||
$laps['records'] = function() {
|
||||
|
||||
$records = [];
|
||||
|
||||
foreach ( $this->providers as $provider ) {
|
||||
if ( $provider instanceof Record_Collector_Interface ) {
|
||||
$records[] = $provider->get_records();
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge( ...$records );
|
||||
};
|
||||
|
||||
$laps->register( new Load_Order_Manager() );
|
||||
$laps->register( new Asset_Manager() );
|
||||
$laps->register( new Toolbar_Manager() );
|
||||
|
||||
$laps->register( new Hook_Record_Collector() );
|
||||
$laps->register( new Http_Record_Collector() );
|
||||
$laps->register( new Sql_Record_Collector() );
|
||||
$laps->register( new Manager_Provider() );
|
||||
$laps->register( new Record_Provider() );
|
||||
|
||||
foreach ( $values as $key => $value ) {
|
||||
$this->offsetSet( $key, $value );
|
||||
|
||||
@@ -2,18 +2,10 @@
|
||||
|
||||
namespace Rarst\Laps\Manager;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Bootable_Provider_Interface;
|
||||
use Rarst\Laps\Laps;
|
||||
class Asset_Manager {
|
||||
|
||||
class Asset_Manager implements ServiceProviderInterface, Bootable_Provider_Interface {
|
||||
public function __construct() {
|
||||
|
||||
public function register( Container $pimple ) {
|
||||
|
||||
}
|
||||
|
||||
public function boot( Laps $laps ) {
|
||||
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
|
||||
}
|
||||
|
||||
@@ -2,21 +2,12 @@
|
||||
|
||||
namespace Rarst\Laps\Manager;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Bootable_Provider_Interface;
|
||||
use Rarst\Laps\Laps;
|
||||
|
||||
/**
|
||||
* Reorders
|
||||
* Reorders plugin load to put Laps first and time this core boot stage.
|
||||
*/
|
||||
class Load_Order_Manager implements ServiceProviderInterface, Bootable_Provider_Interface {
|
||||
class Load_Order_Manager {
|
||||
|
||||
public function register( Container $pimple ) {
|
||||
|
||||
}
|
||||
|
||||
public function boot( Laps $laps ) {
|
||||
public function __construct() {
|
||||
|
||||
add_action( 'pre_update_option_active_plugins', [ $this, 'pre_update_option_active_plugins' ] );
|
||||
add_action( 'pre_update_site_option_active_sitewide_plugins', [ $this, 'pre_update_option_active_plugins' ] );
|
||||
|
||||
@@ -2,23 +2,16 @@
|
||||
|
||||
namespace Rarst\Laps\Manager;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Bootable_Provider_Interface;
|
||||
use Rarst\Laps\Record\Recursive_Record_Iterator;
|
||||
use Rarst\Laps\Laps;
|
||||
use Rarst\Laps\Timeline_Iterator;
|
||||
|
||||
class Toolbar_Manager implements ServiceProviderInterface, Bootable_Provider_Interface {
|
||||
class Toolbar_Manager {
|
||||
|
||||
/** @var Laps $laps */
|
||||
protected $laps;
|
||||
|
||||
public function register( Container $pimple ) {
|
||||
|
||||
}
|
||||
|
||||
public function boot( Laps $laps ) {
|
||||
public function __construct( Laps $laps ) {
|
||||
|
||||
$this->laps = $laps;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rarst\Laps;
|
||||
namespace Rarst\Laps\Provider;
|
||||
|
||||
use Rarst\Laps\Laps;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Rarst\Laps\Provider;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Laps;
|
||||
use Rarst\Laps\Manager\Asset_Manager;
|
||||
use Rarst\Laps\Manager\Load_Order_Manager;
|
||||
use Rarst\Laps\Manager\Toolbar_Manager;
|
||||
|
||||
class Manager_Provider implements ServiceProviderInterface, Bootable_Provider_Interface {
|
||||
|
||||
public function register( Container $pimple ) {
|
||||
|
||||
$pimple['managers'] = function ( Laps $laps ) {
|
||||
return [
|
||||
new Load_Order_Manager(),
|
||||
new Asset_Manager(),
|
||||
new Toolbar_Manager( $laps ),
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
public function boot( Laps $laps ) {
|
||||
$laps['managers'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Rarst\Laps\Provider;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Laps;
|
||||
use Rarst\Laps\Record\Hook_Record_Collector;
|
||||
use Rarst\Laps\Record\Http_Record_Collector;
|
||||
use Rarst\Laps\Record\Record_Collector_Interface;
|
||||
use Rarst\Laps\Record\Sql_Record_Collector;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Interface {
|
||||
|
||||
public function register( Container $pimple ) {
|
||||
|
||||
$pimple['stopwatch'] = $pimple->factory( function () {
|
||||
return new Stopwatch();
|
||||
} );
|
||||
|
||||
$pimple['collectors'] = function ( Laps $laps ) {
|
||||
return [
|
||||
new Hook_Record_Collector( $laps['stopwatch'] ),
|
||||
new Http_Record_Collector( $laps['stopwatch'] ),
|
||||
new Sql_Record_Collector(),
|
||||
];
|
||||
};
|
||||
|
||||
$pimple['records'] = function ( Laps $laps ) {
|
||||
|
||||
$records = [];
|
||||
|
||||
/** @var Record_Collector_Interface $collector */
|
||||
foreach ( $laps['collectors'] as $collector ) {
|
||||
$records[] = $collector->get_records();
|
||||
}
|
||||
|
||||
return array_merge( ...$records );
|
||||
};
|
||||
}
|
||||
|
||||
public function boot( Laps $laps ) {
|
||||
$laps['collectors'];
|
||||
}
|
||||
}
|
||||
@@ -2,29 +2,21 @@
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Bootable_Provider_Interface;
|
||||
use Rarst\Laps\Events\Core_Events;
|
||||
use Rarst\Laps\Events\Laps_Events;
|
||||
use Rarst\Laps\Laps;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||
|
||||
class Hook_Record_Collector implements ServiceProviderInterface, Bootable_Provider_Interface, Record_Collector_Interface {
|
||||
class Hook_Record_Collector implements Record_Collector_Interface {
|
||||
|
||||
/** @var Stopwatch $stopwatch */
|
||||
protected $stopwatch;
|
||||
|
||||
protected $events = [];
|
||||
|
||||
public function register( Container $pimple ) {
|
||||
public function __construct( Stopwatch $stopwatch ) {
|
||||
|
||||
}
|
||||
|
||||
public function boot( Laps $laps ) {
|
||||
|
||||
$this->stopwatch = $laps['stopwatch'];
|
||||
$this->stopwatch = $stopwatch;
|
||||
|
||||
$this->stopwatch->start( 'Plugins Load', 'plugin' );
|
||||
|
||||
|
||||
@@ -2,25 +2,17 @@
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Bootable_Provider_Interface;
|
||||
use Rarst\Laps\Laps;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||
|
||||
class Http_Record_Collector implements ServiceProviderInterface, Bootable_Provider_Interface, Record_Collector_Interface {
|
||||
class Http_Record_Collector implements Record_Collector_Interface {
|
||||
|
||||
/** @var Stopwatch $stopwatch */
|
||||
protected $stopwatch;
|
||||
|
||||
public function register( Container $pimple ) {
|
||||
public function __construct( Stopwatch $stopwatch ) {
|
||||
|
||||
}
|
||||
|
||||
public function boot( Laps $laps ) {
|
||||
|
||||
$this->stopwatch = $laps['stopwatch'];
|
||||
$this->stopwatch = $stopwatch;
|
||||
|
||||
add_action( 'pre_http_request', [ $this, 'pre_http_request' ], 10, 3 );
|
||||
add_action( 'http_api_debug', [ $this, 'http_api_debug' ], 10, 5 );
|
||||
|
||||
@@ -2,20 +2,11 @@
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Rarst\Laps\Bootable_Provider_Interface;
|
||||
use Rarst\Laps\Laps;
|
||||
|
||||
class Sql_Record_Collector implements ServiceProviderInterface, Bootable_Provider_Interface, Record_Collector_Interface {
|
||||
class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
|
||||
protected $query_starts = [];
|
||||
|
||||
public function register( Container $pimple ) {
|
||||
|
||||
}
|
||||
|
||||
public function boot( Laps $laps ) {
|
||||
public function __construct() {
|
||||
|
||||
if ( $this->is_savequeries() ) {
|
||||
add_filter( 'query', [ $this, 'query' ], 20 );
|
||||
|
||||
Reference in new issue
Block a user