Renamed main class to Plugin for more clear role.

This commit is contained in:
Andrey Savchenko committed 2018-02-13 18:22:35 +02:00
1 parent a19e4fb019
commit d850fa1b02
6 files changed
+16 -16

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
<?php
namespace Rarst\Laps;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Rarst\Laps\Provider\Bootable_Provider_Interface;
use Rarst\Laps\Provider\Hook_Event_Provider;
use Rarst\Laps\Provider\Manager_Provider;
use Rarst\Laps\Provider\Record_Provider;
/**
* Main plugin's class.
*/
class Plugin extends Container {
protected $providers = [];
public function __construct( array $values = [] ) {
parent::__construct();
$laps = $this;
$laps['mustache'] = function () {
return new \Mustache_Engine( [
'loader' => new \Mustache_Loader_FilesystemLoader( dirname( __DIR__ ) . '/views' ),
'cache' => new Mustache_Cache_FrozenCache( dirname( __DIR__ ) . '/views/cache' ),
] );
};
$laps->register( new Manager_Provider() );
$laps->register( new Hook_Event_Provider() );
$laps->register( new Record_Provider() );
foreach ( $values as $key => $value ) {
$this->offsetSet( $key, $value );
}
}
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.
*/
public function run() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
foreach ( $this->providers as $provider ) {
if ( $provider instanceof Bootable_Provider_Interface ) {
$provider->boot( $this );
}
}
}
}