Prooph\ServiceBus\Plugin\Guard\RouteGuard::attach PHP Method

attach() public method

public attach ( Prooph\Common\Event\ActionEventEmitter $events ) : void
$events Prooph\Common\Event\ActionEventEmitter
return void
    public function attach(ActionEventEmitter $events)
    {
        $this->trackHandler($events->attachListener(MessageBus::EVENT_ROUTE, [$this, "onRoute"], 1000));
    }

Usage Example

 /**
  * @test
  */
 public function it_attaches_to_action_event_emitter()
 {
     $listenerHandler = $this->prophesize(ListenerHandler::class);
     $authorizationService = $this->prophesize(AuthorizationService::class);
     $routeGuard = new RouteGuard($authorizationService->reveal());
     $actionEventEmitter = $this->prophesize(ActionEventEmitter::class);
     $actionEventEmitter->attachListener(MessageBus::EVENT_ROUTE, [$routeGuard, 'onRoute'], 1000)->willReturn($listenerHandler->reveal());
     $routeGuard->attach($actionEventEmitter->reveal());
 }