Added proper providers to handle registration and boot.

This commit is contained in:
Andrey Savchenko committed 2018-02-13 11:37:54 +02:00
1 parent 48b3383e06
commit 06e3bb4657
10 files changed
+95 -97

No files matched your search

@@ -0,0 +1,10 @@
<?php
namespace Rarst\Laps\Provider;
use Rarst\Laps\Laps;
interface Bootable_Provider_Interface {
public function boot( Laps $laps );
}
+28
View File
@@ -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'];
}
}
+46
View File
@@ -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'];
}
}