Created
July 24, 2016 11:33
-
-
Save acairns/8a5610a62c7b7fc5af30b7fcc0c58f2e to your computer and use it in GitHub Desktop.
Reflection-based Event Emitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class WarpDriveEngaged | |
{ | |
private $speed; | |
public function __construct($speed) | |
{ | |
$this->speed = $speed; | |
} | |
public function getSpeed() | |
{ | |
return $this->speed; | |
} | |
} | |
final class DisableTransporters | |
{ | |
public function whenWarpDriveIsEngaged(WarpDriveEngaged $event) | |
{ | |
var_dump($event); | |
echo "Disabling Transporters!\n"; | |
} | |
} | |
final class NewInstanceListenerLocator implements \Cairns\Radiate\Locator\ListenerLocator { | |
public function locate($fqcn) { | |
return new $fqcn; | |
} | |
} | |
$registry = new \Cairns\Radiate\Registry\TypehintedClassRegistry; | |
$registry->register(DisableTransporters::class); | |
$invoker = new \Cairns\Radiate\Middleware\InvokeListenerMiddleware( | |
$registry, | |
new NewInstanceListenerLocator, | |
new \Cairns\Radiate\Inflector\TypehintMethodInflector | |
); | |
$emitter = new \Cairns\Radiate\Emitter([ | |
$invoker | |
]); | |
$emitter->emit(new WarpDriveEngaged(9)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment