Skip to content

Commit

Permalink
more event updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Sprayberry committed Aug 17, 2015
1 parent afb8bb3 commit ff59cc7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand All @@ -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!';
});
}
Expand Down
4 changes: 2 additions & 2 deletions app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
16 changes: 8 additions & 8 deletions src/Cspray/Labrador/CoreEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,35 @@ 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;
}

/**
* @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;
}

/**
* @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;
}

/**
* @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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cspray/Labrador/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Cspray/Labrador/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ff59cc7

Please sign in to comment.