/**
  * Handles a CreateUserCommand
  *
  * @param  CreateUserCommand $command
  */
 public function handleCreateUserCommand(CreateUserCommand $command)
 {
     $user = null;
     $originalUser = $command->getOriginalUser();
     ContextContainer::setContext($command->getContext());
     try {
         $user = $this->createUser($command->getId(), $originalUser, $command->getPreferredLanguage());
         $this->userManager->save($user);
         $this->logger->info('User Created');
     } catch (\Exception $e) {
         $this->logger->error('Error creating the user');
         $this->errorHandler->handle(new UnableToCreateUserEvent($command->getId(), new UndefinedApplicationUser($this->accountFactory->build($originalUser))), $command->getContext());
     }
     ContextContainer::reset();
 }
 /**
  * @test
  */
 public function itShouldEnrichMetadataWithContext()
 {
     $context = \Mockery::mock(Context::class);
     ContextContainer::setContext($context);
     $metadata = \Mockery::mock(Metadata::class, function ($metadata) use($context) {
         $metadata->shouldReceive('merge')->with(\Mockery::on(function ($m) use($context) {
             $this->assertInstanceOf(Metadata::class, $m);
             $this->assertEquals(['context' => $context], $m->serialize());
             return true;
         }))->andReturn($metadata)->once();
     });
     $enricher = new ContextEnricher();
     $return = $enricher->enrich($metadata);
     $this->assertEquals($metadata, $return);
 }
 /**
  * Handles a GameMoveCommand
  *
  * @param  GameMoveCommand $command
  * @return void
  */
 public function handleGameMoveCommand(GameMoveCommand $command)
 {
     ContextContainer::setContext($command->getContext());
     try {
         $miniGame = $this->gameManager->load($command->getGameId());
         $miniGame->play($command->getPlayerId(), $command->getMove());
         $this->gameManager->save($miniGame);
     } catch (\Exception $e) {
         $this->errorHandler->handle(new MiniGameAppErrorEvent($command->getGameId(), $command->getPlayerId(), $e->getMessage()), $command->getContext());
     }
     ContextContainer::reset();
 }
 /**
  * Add the context info to the Metadata
  *
  * @param  Metadata $metadata
  *
  * @return Metadata
  */
 public function enrich(Metadata $metadata)
 {
     return $metadata->merge(new Metadata([static::CONTEXT => ContextContainer::getContext()]));
 }