Exemple #1
0
 /**
  * Dispatch a command to its appropriate handler in the current process.
  *
  * @param  mixed  $command
  * @param  \Closure|null  $afterResolving
  * @return mixed
  */
 public function dispatchNow($command, Closure $afterResolving = null)
 {
     return $this->pipeline->send($command)->through($this->pipes)->then(function ($command) use($afterResolving) {
         if ($command instanceof SelfHandling) {
             return $this->container->call([$command, 'handle']);
         }
         $handler = $this->resolveHandler($command);
         if ($afterResolving) {
             call_user_func($afterResolving, $handler);
         }
         return call_user_func([$handler, $this->getHandlerMethod($command)], $command);
     });
 }
 /**
  * Dispatch a command to its appropriate handler in the current process.
  *
  * @param  mixed  $command
  * @param  mixed  $handler
  * @return mixed
  */
 public function dispatchNow($command, $handler = null)
 {
     if ($handler || ($handler = $this->getCommandHandler($command))) {
         $callback = function ($command) use($handler) {
             return $handler->handle($command);
         };
     } else {
         $callback = function ($command) {
             return $this->container->call([$command, 'handle']);
         };
     }
     return $this->pipeline->send($command)->through($this->pipes)->then($callback);
 }
Exemple #3
0
 /**
  * Get a Closure that represents a slice of the application onion.
  *
  * @return \Closure
  */
 protected function getSlice()
 {
     return function ($stack, $pipe) {
         return function ($passable) use($stack, $pipe) {
             try {
                 $slice = parent::getSlice();
                 return call_user_func($slice($stack, $pipe), $passable);
             } catch (Exception $e) {
                 return $this->handleException($passable, $e);
             } catch (Throwable $e) {
                 return $this->handleException($passable, new FatalThrowableError($e));
             }
         };
     };
 }
Exemple #4
0
 /**
  * Dispatch a command to its appropriate handler in the current process.
  *
  * @param mixed $command        	
  * @return mixed
  */
 public function dispatchNow($command)
 {
     return $this->pipeline->send($command)->through($this->pipes)->then(function ($command) {
         return $this->container->call([$command, 'handle']);
     });
 }
 /**
  * @param MiddlewareCollection $middlewaresConfiguration
  * @param                      $context
  * @param callable             $next
  *
  * @return mixed
  */
 public function dispatch(MiddlewareCollection $middlewaresConfiguration, $context, callable $next)
 {
     $pipeline = new Pipeline($this->container);
     return $pipeline->send($context)->through($middlewaresConfiguration->getMiddlewares())->then($next);
 }