/**
  * Consumes a message
  *
  * @param  string $message
  * @return void
  */
 public function consume($message)
 {
     $message = json_decode($message, true);
     if ($this->deserializer) {
         $message = $this->deserializer->deserialize($message);
     }
     $this->emitter->emit($message);
 }
 function it_should_not_emit_event_when_rollbacking(EmitterInterface $emitter, EventInterface $event)
 {
     $this->beginTransaction();
     $this->emit($event);
     $emitter->emit($event)->shouldNotBeCalled();
     $this->rollback();
 }
 /**
  * {@inheritdoc}
  */
 public function commit()
 {
     foreach ($this->events as $event) {
         $this->emitter->emit($event);
     }
     $this->events = [];
     $this->running = false;
 }
Beispiel #4
0
 public function run($params, $input, Reply\Handler $replyHandler = null)
 {
     if (!$replyHandler) {
         $replyHandler = new Reply\DirectHandler();
     }
     // Handle the debug parameter.
     if (isset($params['echostr'])) {
         $replyHandler->sendEchoString($params['echostr']);
         return;
     }
     // @todo: implement request signing.
     // Extract input.
     try {
         $xml = new SimpleXMLElement($input);
     } catch (\Exception $e) {
         throw new Exception\BadInputException($e->getMessage(), $input);
     }
     // Build the input object.
     $input = (new Builder())->build($xml);
     // Set the recipient and sender.
     $replyHandler = $replyHandler->withSender($input->getRecipient())->withRecipient($input->getSender());
     // Emit the event.
     $this->emitter->emit($input->getEmittedType(), $input, $replyHandler);
 }
 /**
  * Consumes a message
  *
  * @param  string $message
  * @return void
  */
 public function consume($message)
 {
     $message = $this->deserializer->deserialize($message);
     $this->emitter->emit($message);
 }
 /**
  * @uses TakePaymentCommandHandler::_handle()
  */
 function it_should_emit_a_failure_event_if_not_ok(PaymentRepositoryInterface $repository, Gateway $gateway, TakePaymentCommand $command, EmitterInterface $emitter)
 {
     $this->setRepositoryMethodExpectations($repository);
     $this->clearRepositoryMarkAsPaidExpectation($repository);
     $gatewayException = new PaymentFailedException('Failed to process payment with the Stripe payment gateway');
     /** @noinspection PhpUndefinedMethodInspection */
     $gateway->purchase(Argument::any())->willThrow($gatewayException);
     /** @noinspection PhpUndefinedMethodInspection */
     $this->shouldThrow($gatewayException)->during('handle', [$command]);
     /** @noinspection PhpUndefinedMethodInspection */
     $emitter->emit(Argument::type(TakePaymentFailureEvent::class))->shouldHaveBeenCalled();
 }
 /**
  * @uses AbstractCommandHandler::handle()
  */
 function it_should_emit_an_event_on_failure(TestCorrectCommand $command, ValidatorInterface $validator, EmitterInterface $emitter)
 {
     $this->beConstructedThrough('createToFail', [$validator, $emitter]);
     // This tests check that this thrown exception matches the one thrown in
     // \CubicMushroom\Hexagonal\Command\TestAbstractCommandHandler::_handle() below
     /** @noinspection PhpUndefinedMethodInspection */
     $this->shouldThrow(new \Exception('I am supposed to fail for this test'))->during('handle', [$command]);
     /** @noinspection PhpUndefinedMethodInspection */
     $emitter->emit(Argument::type(TestAbstractCommandHandlerFailedEvent::class))->shouldHaveBeenCalled();
 }
Beispiel #8
0
 /**
  * Fire an event.
  *
  * @param mixed $event
  * @param array $data
  * @return \League\Event\EventInterface
  */
 public function emit($event, array $data = [])
 {
     return $this->emitter->emit($event, $data);
 }
Beispiel #9
0
 /**
  * Handles notifications for shutting down when drained
  */
 public function drained()
 {
     $this->emitter->emit(static::QUEUE_DRAINED);
     $this->logger->notice('Drained - Shutting down');
 }