Esempio n. 1
0
 /**
  * Adds an event listener for the given input type.
  * 
  * @param          $type
  * @param callable $listener
  */
 public function on($type, callable $listener)
 {
     $args = array_slice(func_get_args(), 2);
     $this->emitter->addListener($type, function (EventInterface $event, Input\Input $input, Reply\Handler $replyHandler) use($args, $listener) {
         call_user_func_array($listener, array_merge([$input, $replyHandler], $args));
     });
 }
Esempio n. 2
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;
 }
 /**
  * @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());
         }
     });
 }
Esempio 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.');
 }
 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_addListener(EmitterInterface $emitter, ListenerInterface $listener)
 {
     $emitter->addListener('test', $listener, 0)->shouldBeCalled();
     $this->addListener('test', $listener, 0);
 }
 /**
  * {@inheritdoc}
  */
 public function addListener($event, $listener, $priority = self::P_NORMAL)
 {
     $this->emitter->addListener($event, $listener, $priority);
     return $this;
 }
Esempio n. 8
0
 /**
  * Add an event listener.
  *
  * @param mixed $event
  * @param mixed $listener
  * @return $this
  */
 public function listen($event, $listener)
 {
     return $this->emitter->addListener($event, $listener);
 }