Skip to content

Commit

Permalink
Merge pull request #60 from cspray/replace-evenement
Browse files Browse the repository at this point in the history
refactor to use league/event
  • Loading branch information
cspray committed Aug 17, 2015
2 parents cd2a597 + 13defaf commit 3e0c580
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 280 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require": {
"php": "~7.0",
"rdlowrey/auryn": "~1.0",
"evenement/evenement": "~2.0",
"league/event": "~2.1",
"morrisonlevi/ardent": "dev-master",
"cspray/telluris": "dev-master",
"filp/whoops": "~1.1"
Expand Down
96 changes: 50 additions & 46 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 13 additions & 23 deletions src/Cspray/Labrador/CoreEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
StandardEventFactory
};
use Cspray\Labrador\Plugin\Plugin;
use Evenement\EventEmitterInterface;
use League\Event\EmitterInterface;
use Telluris\Environment;

class CoreEngine implements Engine {
Expand All @@ -33,13 +33,13 @@ class CoreEngine implements Engine {
/**
* @param Environment $environment
* @param PluginManager $pluginManager
* @param EventEmitterInterface $emitter
* @param EmitterInterface $emitter
* @param EventFactory $eventFactory
*/
public function __construct(
Environment $environment,
PluginManager $pluginManager,
EventEmitterInterface $emitter,
EmitterInterface $emitter,
EventFactory $eventFactory = null
) {
$this->environment = $environment;
Expand All @@ -48,26 +48,16 @@ public function __construct(
$this->eventFactory = $eventFactory ?? new StandardEventFactory();
}

/**
* @return string
*/
public function getName() : string {
return 'labrador-core';
}

/**
* @return string
*/
public function getVersion() : string {
return '0.1.0-alpha';
public function getEmitter() : EmitterInterface {
return $this->emitter;
}

public function getEnvironment() : Environment {
return $this->environment;
}

public function onEnvironmentInitialize(callable $cb) : self {
$this->emitter->on(self::ENVIRONMENT_INITIALIZE_EVENT, $cb);
$this->emitter->addListener(self::ENVIRONMENT_INITIALIZE_EVENT, $cb);
return $this;
}

Expand All @@ -76,7 +66,7 @@ public function onEnvironmentInitialize(callable $cb) : self {
* @return $this
*/
public function onAppExecute(callable $cb) : self {
$this->emitter->on(self::APP_EXECUTE_EVENT, $cb);
$this->emitter->addListener(self::APP_EXECUTE_EVENT, $cb);
return $this;
}

Expand All @@ -85,7 +75,7 @@ public function onAppExecute(callable $cb) : self {
* @return $this
*/
public function onAppCleanup(callable $cb) : self {
$this->emitter->on(self::APP_CLEANUP_EVENT, $cb);
$this->emitter->addListener(self::APP_CLEANUP_EVENT, $cb);
return $this;
}

Expand All @@ -94,7 +84,7 @@ public function onAppCleanup(callable $cb) : self {
* @return $this
*/
public function onExceptionThrown(callable $cb) : self {
$this->emitter->on(self::EXCEPTION_THROWN_EVENT, $cb);
$this->emitter->addListener(self::EXCEPTION_THROWN_EVENT, $cb);
return $this;
}

Expand All @@ -106,16 +96,16 @@ public function onExceptionThrown(callable $cb) : self {
public function run() {
try {
$envInitEvent = $this->eventFactory->create(self::ENVIRONMENT_INITIALIZE_EVENT, $this->environment);
$this->emitter->emit(self::ENVIRONMENT_INITIALIZE_EVENT, [$envInitEvent, $this]);
$this->emitter->emit($envInitEvent, $this);

$appExecuteEvent = $this->eventFactory->create(self::APP_EXECUTE_EVENT);
$this->emitter->emit(self::APP_EXECUTE_EVENT, [$appExecuteEvent, $this]);
$this->emitter->emit($appExecuteEvent, $this);
} catch (\Exception $exception) {
$exceptionEvent = $this->eventFactory->create(self::EXCEPTION_THROWN_EVENT, $exception);
$this->emitter->emit(self::EXCEPTION_THROWN_EVENT, [$exceptionEvent, $this]);
$this->emitter->emit($exceptionEvent, $this);
} finally {
$appCleanupEvent = $this->eventFactory->create(self::APP_CLEANUP_EVENT);
$this->emitter->emit(self::APP_CLEANUP_EVENT, [$appCleanupEvent, $this]);
$this->emitter->emit($appCleanupEvent, $this);
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/Cspray/Labrador/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Cspray\Labrador;

use Cspray\Labrador\Plugin\Pluggable;
use League\Event\EmitterInterface;

interface Engine extends Pluggable {

Expand All @@ -22,18 +23,15 @@ interface Engine extends Pluggable {
const EXCEPTION_THROWN_EVENT = 'labrador.exception_thrown';

/**
* @return string
*/
public function getName() : string;

/**
* Return the version of the Engine; this should be in semver format.
* Return the event emitter that will emit the events for this Engine.
*
* @return string
* @return EmitterInterface
*/
public function getVersion() : string;
public function getEmitter() : EmitterInterface;

/**
* Perform whatever actions are necessary for this implementation.
*
* @return mixed
*/
public function run();
Expand Down
1 change: 1 addition & 0 deletions src/Cspray/Labrador/Event/AppCleanupEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Cspray\Labrador\Event;

use Cspray\Labrador\Engine;
use League\Event\Event;

class AppCleanupEvent extends Event {

Expand Down
1 change: 1 addition & 0 deletions src/Cspray/Labrador/Event/AppExecuteEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Cspray\Labrador\Event;

use Cspray\Labrador\Engine;
use League\Event\Event;

class AppExecuteEvent extends Event {

Expand Down
1 change: 1 addition & 0 deletions src/Cspray/Labrador/Event/EnvironmentInitializeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Cspray\Labrador\Engine;
use Telluris\Environment;
use League\Event\Event;

class EnvironmentInitializeEvent extends Event {

Expand Down
35 changes: 0 additions & 35 deletions src/Cspray/Labrador/Event/Event.php

This file was deleted.

4 changes: 3 additions & 1 deletion src/Cspray/Labrador/Event/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

namespace Cspray\Labrador\Event;

use League\Event\EventInterface;

interface EventFactory {

public function create(string $eventName, ...$args) : Event;
public function create(string $eventName, ...$args) : EventInterface;

}
1 change: 1 addition & 0 deletions src/Cspray/Labrador/Event/ExceptionThrownEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Cspray\Labrador\Event;

use Cspray\Labrador\Engine;
use League\Event\Event;
use Exception;

class ExceptionThrownEvent extends Event {
Expand Down
Loading

0 comments on commit 3e0c580

Please sign in to comment.