示例#1
0
 /**
  * Invoke a route callable.
  *
  * @param callable               $callable       The callable to invoke using the strategy.
  * @param ServerRequestInterface $request        The request object.
  * @param ResponseInterface      $response       The response object.
  * @param array                  $routeArguments The route's placeholder arguments
  *
  * @return ResponseInterface|string The response from the callable.
  */
 public function __invoke(callable $callable, ServerRequestInterface $request, ResponseInterface $response, array $routeArguments)
 {
     // Inject the request and response by parameter name
     $parameters = ['request' => $request, 'response' => $response];
     // Inject the route arguments by name
     $parameters += $routeArguments;
     return $this->invoker->call($callable, $parameters);
 }
示例#2
0
 /**
  * Define a CLI command using a string expression and a callable.
  *
  * @param string                $expression Defines the arguments and options of the command.
  * @param callable|string|array $callable   Called when the command is called.
  *                                          When using a container, this can be a "pseudo-callable"
  *                                          i.e. the name of the container entry to invoke.
  *
  * @return Command
  */
 public function command($expression, $callable)
 {
     $commandFunction = function (InputInterface $input, OutputInterface $output) use($callable) {
         $parameters = array_merge(['input' => $input, 'output' => $output], $input->getArguments(), $input->getOptions());
         try {
             $this->invoker->call($callable, $parameters);
         } catch (InvocationException $e) {
             throw new \RuntimeException(sprintf("Impossible to call the '%s' command: %s", $input->getFirstArgument(), $e->getMessage()), 0, $e);
         }
     };
     $command = $this->createCommand($expression, $commandFunction);
     $this->add($command);
     return $command;
 }
示例#3
0
 /**
  * Define a CLI command using a string expression and a callable.
  *
  * @param string $expression Defines the arguments and options of the command.
  * @param callable|string|array $callable Called when the command is called.
  *                                          When using a container, this can be a "pseudo-callable"
  *                                          i.e. the name of the container entry to invoke.
  *
  * @param array $aliases An array of aliases for the command.
  *
  * @return Command
  */
 public function command($expression, $callable, array $aliases = [])
 {
     $this->assertCallableIsValid($callable);
     $commandFunction = function (InputInterface $input, OutputInterface $output) use($callable) {
         $parameters = array_merge(['input' => $input, 'output' => $output], $input->getArguments(), $input->getOptions());
         if ($callable instanceof \Closure) {
             $callable = $callable->bindTo($this, $this);
         }
         try {
             return $this->invoker->call($callable, $parameters);
         } catch (InvocationException $e) {
             throw new \RuntimeException(sprintf("Impossible to call the '%s' command: %s", $input->getFirstArgument(), $e->getMessage()), 0, $e);
         }
     };
     $command = $this->createCommand($expression, $commandFunction);
     $command->setAliases($aliases);
     $command->defaults($this->defaultsViaReflection($command, $callable));
     $this->add($command);
     return $command;
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function call($callable, array $parameters = [])
 {
     $this->getInvoker();
     return $this->invoker->call($callable, $parameters);
 }