创建版本
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?php namespace App\Support;
|
||||
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
class Hook
|
||||
{
|
||||
public static function listen($tag, $class)
|
||||
{
|
||||
$object = with(new $class);
|
||||
$methods = get_class_methods($object);
|
||||
foreach ($methods as $method) {
|
||||
app('dispatcher')->addListener($tag.'.'.$method, [$object, $method]);
|
||||
}
|
||||
unset($object);
|
||||
}
|
||||
|
||||
public static function fire($tag, $data = [])
|
||||
{
|
||||
$event = new GenericEvent();
|
||||
$event->setArguments($data);
|
||||
$event = app('dispatcher')->dispatch($event, $tag);
|
||||
return $event->getArguments();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user