예제 #1
0
 /**
  * @param EventSubscriberInterface $subscriber
  *
  * @return $this
  */
 public function addEventSubscriber(EventSubscriberInterface $subscriber)
 {
     if ($this->eventBus === null) {
         throw new \RuntimeException('The event bus should not be null');
     }
     $this->eventBus->addSubscriber($subscriber);
     return $this;
 }
예제 #2
0
 /**
  * @param DomainEventSubscriberInterface $subscriber
  */
 protected function addSubscriber(DomainEventSubscriberInterface $subscriber)
 {
     $this->eventBus->addSubscriber($subscriber);
 }
예제 #3
0
 /**
  * @param callable|ApplicationConfig $config
  *
  * @return ConsoleApplication
  */
 protected function createApplication($config)
 {
     $commandBus = CommandBus::create();
     $eventBus = EventBus::create();
     $postService = new PostService($eventBus);
     $commandBus->addHandler(CreateBlogCommand::class, new BlogService($eventBus));
     $commandBus->addHandler(CreatePostCommand::class, $postService);
     $commandBus->addHandler(ChangePostTitleCommand::class, $postService);
     return new ConsoleApplication($config, $commandBus, $eventBus);
 }
예제 #4
0
 /**
  * @param ChangePostTitleCommand $command
  */
 public function changePostTitle(ChangePostTitleCommand $command)
 {
     $this->eventBus->dispatch(new PostTitleWasChanged($command->title()));
 }
예제 #5
0
 /**
  * Test RemoveSubscriber method.
  */
 public function testRemoveSubscriber()
 {
     $this->given($eventBus = EventBus::create())->and($subscriber = new UserEventSubscriber())->and($eventBus->addSubscriber($subscriber))->then()->boolean($eventBus->hasEventListeners(UserEventSubscriber::FOO_EVENT))->isTrue()->boolean($eventBus->hasEventListeners(UserEventSubscriber::BAR_EVENT))->isTrue()->boolean($eventBus->hasEventListeners(UserEventSubscriber::USER_LOGIN))->isTrue()->and()->when($eventBus->removeSubscriber($subscriber))->then()->boolean($eventBus->hasEventListeners(UserEventSubscriber::FOO_EVENT))->isFalse()->boolean($eventBus->hasEventListeners(UserEventSubscriber::BAR_EVENT))->isFalse()->boolean($eventBus->hasEventListeners(UserEventSubscriber::USER_LOGIN))->isFalse();
 }
예제 #6
0
 /**
  * Test eventBus method.
  */
 public function testEventBus()
 {
     $this->given($eventBus = EventBus::create())->when(DomainEventPublisher::set($eventBus))->then()->object(DomainEventPublisher::eventBus())->isEqualTo($eventBus);
 }