diff --git a/README.md b/README.md index 404edf6..1a032a0 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,12 @@ could use the library. require_once __DIR__ . '/vendor/autoload.php'; -use function Cspray\Labrador\engine; +use Cspray\Labrador\Engine; +use function Cspray\Labrador\bootstrap; -$engine = engine(); +$injector = bootstrap(); + +$engine = $injector->make(Engine::class); $engine->onAppExecute(function() { echo 'Hello World'; @@ -65,7 +68,7 @@ $engine->run(); require_once './vendor/autoload.php'; use Cspray\Labrador\CoreEngine; -use Evenement\EventEmitterInterface; +use League\Event\EmitterInterface; use function Cspray\Labrador\engine; class HelloWorldPlugin implements Plugin\EventAwarePlugin { @@ -78,8 +81,8 @@ class HelloWorldPlugin implements Plugin\EventAwarePlugin { // our app is too simple to do anything here but yours might not be } - public function registerEventListeners(EventEmitterInterface $emitter) { - $emitter->on(CoreEngine::APP_EXECUTE_EVENT, function() { + public function registerEventListeners(EmitterInterface $emitter) { + $emitter->addListener(CoreEngine::APP_EXECUTE_EVENT, function() { echo 'Hello world!'; }); } diff --git a/app.php b/app.php index 9d24fbe..7e1ad20 100644 --- a/app.php +++ b/app.php @@ -2,12 +2,12 @@ require_once __DIR__ . '/vendor/autoload.php'; -use Cspray\Labrador\CoreEngine; +use Cspray\Labrador\Engine; use function Cspray\Labrador\bootstrap; $injector = bootstrap(); -$engine = $injector->make(CoreEngine::class); +$engine = $injector->make(Engine::class); $engine->onAppExecute(function() { echo 'Hello World'; diff --git a/src/Cspray/Labrador/CoreEngine.php b/src/Cspray/Labrador/CoreEngine.php index d89c838..02a2113 100644 --- a/src/Cspray/Labrador/CoreEngine.php +++ b/src/Cspray/Labrador/CoreEngine.php @@ -56,8 +56,8 @@ public function getEnvironment() : Environment { return $this->environment; } - public function onEnvironmentInitialize(callable $cb) : self { - $this->emitter->addListener(self::ENVIRONMENT_INITIALIZE_EVENT, $cb); + public function onEnvironmentInitialize(callable $cb, int $priority = EmitterInterface::P_NORMAL) : self { + $this->emitter->addListener(self::ENVIRONMENT_INITIALIZE_EVENT, $cb, $priority); return $this; } @@ -65,8 +65,8 @@ public function onEnvironmentInitialize(callable $cb) : self { * @param callable $cb * @return $this */ - public function onAppExecute(callable $cb) : self { - $this->emitter->addListener(self::APP_EXECUTE_EVENT, $cb); + public function onAppExecute(callable $cb, int $priority = EmitterInterface::P_NORMAL) : self { + $this->emitter->addListener(self::APP_EXECUTE_EVENT, $cb, $priority); return $this; } @@ -74,8 +74,8 @@ public function onAppExecute(callable $cb) : self { * @param callable $cb * @return $this */ - public function onAppCleanup(callable $cb) : self { - $this->emitter->addListener(self::APP_CLEANUP_EVENT, $cb); + public function onAppCleanup(callable $cb, int $priority = EmitterInterface::P_NORMAL) : self { + $this->emitter->addListener(self::APP_CLEANUP_EVENT, $cb, $priority); return $this; } @@ -83,8 +83,8 @@ public function onAppCleanup(callable $cb) : self { * @param callable $cb * @return $this */ - public function onExceptionThrown(callable $cb) : self { - $this->emitter->addListener(self::EXCEPTION_THROWN_EVENT, $cb); + public function onExceptionThrown(callable $cb, int $priority = EmitterInterface::P_NORMAL) : self { + $this->emitter->addListener(self::EXCEPTION_THROWN_EVENT, $cb, $priority); return $this; } diff --git a/src/Cspray/Labrador/PluginManager.php b/src/Cspray/Labrador/PluginManager.php index c7897e1..8fe8fc0 100644 --- a/src/Cspray/Labrador/PluginManager.php +++ b/src/Cspray/Labrador/PluginManager.php @@ -41,7 +41,7 @@ private function registerBooter() { }; $cb = $cb->bindTo($this); - $this->emitter->addListener(Engine::ENVIRONMENT_INITIALIZE_EVENT, $cb); + $this->emitter->addListener(Engine::ENVIRONMENT_INITIALIZE_EVENT, $cb, EmitterInterface::P_HIGH); } public function registerPlugin(Plugin $plugin) { diff --git a/src/Cspray/Labrador/Services.php b/src/Cspray/Labrador/Services.php index f8d0e57..0e957de 100644 --- a/src/Cspray/Labrador/Services.php +++ b/src/Cspray/Labrador/Services.php @@ -49,7 +49,7 @@ public function createInjector() : Injector { $emitter = $injector->make(EmitterInterface::class); $emitter->addListener(Engine::ENVIRONMENT_INITIALIZE_EVENT, function(EnvironmentInitializeEvent $event) { $event->getEnvironment()->runInitializers(); - }); + }, EmitterInterface::P_HIGH); } return $injector;