Ejemplo n.º 1
0
 /**
  * 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);
 }
 /**
  * @param EmitterInterface $emitter
  */
 public function registerEventListeners(EmitterInterface $emitter)
 {
     $run = $this->whoopsRun;
     $emitter->addListener(Engine::EXCEPTION_THROWN_EVENT, function (ExceptionThrownEvent $event) use($run, $emitter) {
         if (count($emitter->getListeners(Engine::EXCEPTION_THROWN_EVENT)) === 1) {
             $run->handleException($event->getException());
         }
     });
 }
Ejemplo n.º 3
0
 public function addConverter(ConverterInterface $converter)
 {
     foreach ($converter->getSubscribedEvents() as $tag => $event) {
         $eventName = stripos($tag, 'convert.') === 0 ? $tag : "convert.{$tag}";
         if (is_string($event)) {
             $event = [$event];
         }
         $event = array_values($event);
         list($callbackName, $priority) = count($event) > 1 ? [$event[0], $event[1]] : [$event[0], EmitterInterface::P_NORMAL];
         $this->eventEmitter->addListener($eventName, [$converter, $callbackName], $priority);
     }
     return $this;
 }
Ejemplo n.º 4
0
 public function initialize()
 {
     if ($this->initialized) {
         throw new \LogicException('Application is already initialized');
     }
     $this->initialized = true;
     // create the main application component
     $this->component = $this->newComponent('/', $this->appNamespace);
     // create the environment for this application
     $this->environment = $this->factory->createEnvironmentContainer($this->name, $this->environmentName, $this);
     // create the log instance for this application
     $this->log = $this->factory->createLogInstance('fuel');
     // load the log config
     $log = $this->getConfig()->load('log', true);
     // a log customizer defined?
     if (isset($log['customize']) and $log['customize'] instanceof \Closure) {
         $log['customize']($this, $this->log);
     }
     // setup the event container
     $this->event = $this->factory->createEventInstance();
     $shutdown = new Event\Shutdown($this);
     // setup a global shutdown event for this event container
     register_shutdown_function(function ($event, $shutdown) {
         $event->emit($shutdown);
     }, $this->event, $shutdown);
     // setup a shutdown event for writing cookies
     $this->event->addListener('shutdown', function ($shutdown) {
         $shutdown->getApp()->getRootComponent()->getInput()->getCookie()->send();
     });
     // load the session config
     $session = $this->getConfig()->load('session', true);
     // do we need to auto-start one?
     if (isset($session['auto_initialize']) and $session['auto_initialize']) {
         // create a session instance
         $this->session = $this->factory->createSessionInstance();
     }
     // create the view manager instance for this application
     $this->viewManager = $this->factory->createViewmanagerInstance();
     // load the view config
     $this->getConfig()->load('view', true);
     // get the defined view parsers
     $parsers = $this->getConfig()->get('view.parsers', []);
     // and register them to the View Manager
     foreach ($parsers as $extension => $parser) {
         if (is_numeric($extension)) {
             $extension = $parser;
             $parser = 'parser.' . $extension;
         }
         $this->viewManager->registerParser($extension, $this->factory->createViewParserInstance($parser));
     }
     // log we're alive!
     $this->log->info('Application initialized.');
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
0
 protected function setupListeners(EmitterInterface $emitter, OutputInterface $output)
 {
     if (!$output->isVerbose()) {
         return;
     }
     $emitter->addListener('git_remote.repository_discovery', function ($event) use($output) {
         /** @var GitRepositoryEvent $event */
         $output->writeln(sprintf('Discovered repository <info>%s</info> at <comment>%s</comment>', $event->getRepository()->getName(), $event->getRepository()->getAnonymousUri()));
         if ($output->isVeryVerbose()) {
             $data = $event->getData();
             $output->writeln(sprintf('Repository definition: %s', json_encode($data['definition'], JSON_PRETTY_PRINT)));
         }
     });
     $emitter->addListener('git_guardian.pre_clone_repository', function ($event) use($output) {
         /** @var GitRepositoryEvent $event */
         $data = $event->getData();
         $output->write(sprintf('Cloning <info>%s</info> into <comment>%s</comment> ', $event->getRepository()->getName(), $data['path']));
     });
     $emitter->addListener('git_guardian.create_git', function ($event) use($output) {
         /** @var GitRepositoryEvent $event */
         $output->write(sprintf('Preparing Git for <info>%s</info> in <comment>%s</comment> ', $event->getRepository()->getName(), $event->getGit()->getPath()));
     });
     $emitter->addListener('git_guardian.exception_repository', function ($event) use($output) {
         /** @var GitRepositoryEvent $event */
         $data = $event->getData();
         $output->writeln(sprintf('[<error>Errored: %s</error>]', $data['exception']->getMessage()));
     });
     $emitter->addListener('git_guardian.config_skip_repository', function () use($output) {
         /** @var GitRepositoryEvent $event */
         $output->writeln('[<info>Skipped</info>]');
     });
     $emitter->addListener('git_guardian.post_fetch_repository', function () use($output) {
         /** @var GitRepositoryEvent $event */
         $output->writeln('[<info>Fetched</info>]');
     });
 }
 function it_should_proxy_addOneTimeListener(EmitterInterface $emitter, ListenerInterface $listener)
 {
     $emitter->addOneTimeListener('test', $listener, 0)->shouldBeCalled();
     $this->addOneTimeListener('test', $listener, 0);
 }
Ejemplo n.º 8
0
 /**
  * Consumes a message
  *
  * @param  string $message
  * @return void
  */
 public function consume($message)
 {
     $message = $this->deserializer->deserialize($message);
     $this->emitter->emit($message);
 }
Ejemplo n.º 9
0
 public function testDrained()
 {
     $this->emitter->expects($this->once())->method('emit')->with(Event::QUEUE_DRAINED);
     $this->event->drained();
 }
 /**
  * @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();
 }
 /**
  * {@inheritdoc}
  */
 public function addOneTimeListener($event, $listener, $priority = self::P_NORMAL)
 {
     $this->emitter->addOneTimeListener($event, $listener, $priority);
     return $this;
 }
Ejemplo n.º 13
0
 /**
  * Add an event listener.
  *
  * @param mixed $event
  * @param mixed $listener
  * @return $this
  */
 public function listen($event, $listener)
 {
     return $this->emitter->addListener($event, $listener);
 }
Ejemplo n.º 14
0
 /**
  * Handles notifications for shutting down when drained
  */
 public function drained()
 {
     $this->emitter->emit(static::QUEUE_DRAINED);
     $this->logger->notice('Drained - Shutting down');
 }