/**
  * Subscribe the given array of command handlers on the command bus
  * @param array $handlers
  */
 public function subscribe($handlers)
 {
     $handlers = $this->isTraversable($handlers) ? $handlers : [$handlers];
     foreach ($handlers as $commandHandler) {
         $this->commandBus->subscribe($commandHandler);
     }
 }
 public function destroy(Request $request)
 {
     $partId = PartId::fromString($request->get('partId'));
     $command = new RemovePartCommand($partId);
     $this->commandBus->dispatch($command);
     return Redirect::route('parts.index')->with('success', 'Part successfully deleted.');
 }
 public function testDoNotRetryGenericException()
 {
     $this->setExpectedException('Exception');
     $command = new stdClass();
     $this->commandBus->expects($this->at(0))->method('dispatch')->with($this->identicalTo($command))->will($this->throwException(new Exception('Generic')));
     $gateway = $this->createGateway();
     $gateway->send($command);
 }
 function it_creates_a_new_expense_list(CommandBusInterface $commandBus)
 {
     $createExpenseList = new CreateExpenseList();
     $createExpenseList->name = 'Home';
     $commandBus->dispatch(Argument::type(CreateExpenseListCommand::class))->shouldBeCalled();
     /** @var Response $response */
     $response = $this->createAction($createExpenseList);
     $response->getStatusCode()->shouldBe(201);
 }
 /**
  * @Route("/", methods={"POST"})
  * @param CreateExpenseList $createExpenseList
  * @return JsonResponse|Response
  */
 public function createAction(CreateExpenseList $createExpenseList)
 {
     $violations = $this->validator->validate($createExpenseList);
     if (count($violations) > 0) {
         return new Response(null, Response::HTTP_BAD_REQUEST);
     }
     $id = (string) Uuid::uuid4();
     $this->commandBus->dispatch(new CreateExpenseListCommand($id, $createExpenseList->name, $this->accountId));
     return new JsonResponse(['id' => $id], Response::HTTP_CREATED);
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function send($command, Callback $callback = null)
 {
     $retry = new RetryCallback($this->commandBus, $command, $this->scheduler, $callback);
     try {
         $this->commandBus->dispatch($command);
     } catch (Exception $e) {
         return $retry->onFailure($e);
     }
     return $retry->onSuccess();
 }
Esempio n. 7
0
 /**
  * Applies a web command to the domain
  *
  * @param CommandInterface $web_command
  * @throws \LogicException
  * @throws CannotApplyWebCommand
  */
 public function apply(CommandInterface $web_command)
 {
     if (!$web_command instanceof WebCommandInterface) {
         throw new \LogicException('Given command must implement WebCommandInterface');
     }
     try {
         $domainCommand = $this->toDomainCommand($web_command);
         $this->commandBus->dispatch($domainCommand);
     } catch (DomainException $exception) {
         throw new CannotApplyWebCommand($exception->getMessage());
     }
 }
Esempio n. 8
0
 /**
  * @param $command
  */
 private function handleCommand($command)
 {
     try {
         $this->commandBus->dispatch($command);
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage());
     }
 }
 /**
  * @param $command
  */
 private function handleCommand($command)
 {
     try {
         $this->commandBus->dispatch($command);
     } catch (\Exception $e) {
         throw new \Exception("Municipality config could not be found or created");
     }
 }