Last active
August 29, 2015 14:14
-
-
Save jjbubudi/c1a3a5fcc3a04e9cbb57 to your computer and use it in GitHub Desktop.
Guava clone
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
$subscriberClass = new \ReflectionClass(TestSubscriber::class); | |
$annotationReader = new AnnotationReader(); | |
$mappings = []; | |
// Registry | |
foreach ($subscriberClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { | |
$annotation = $annotationReader->getMethodAnnotation($method, Subscribe::class); | |
$parameters = $method->getParameters(); | |
if (!$annotation || empty($parameters)) { | |
continue; | |
} | |
$eventClass = $parameters[0]->getClass()->getName(); | |
if (!isset($mappings[$eventClass])) { | |
$mappings[$eventClass] = []; | |
} | |
$mappings[$eventClass][] = $method; | |
} | |
// Fire | |
foreach ($mappings as $eventClass => $methods) { | |
/** @var \ReflectionMethod $method */ | |
foreach ($methods as $method) { | |
$declaringClass = $method->getDeclaringClass()->getName(); | |
$method->invoke(new $declaringClass, new $eventClass); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment