public function command($expression, $callable, array $aliases = [])
    {
        $this->assertCallableIsValid($callable);

        $commandFunction = function (InputInterface $input, OutputInterface $output) use ($callable) {
            $parameters = array_merge(
                [
                    // Injection by parameter name
                    'input' => $input,
                    'output' => $output,
                    // Injections by type-hint
                    InputInterface::class => $input,
                    OutputInterface::class => $output,
                    Input::class => $input,
                    Output::class => $output,
                    SymfonyStyle::class => new SymfonyStyle($input, $output),
                ],
                // Arguments and options are injected by parameter names
                $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;
    }
public function command($expression, $callable, array $aliases = [])
    {
        $this->assertCallableIsValid($callable);

        $commandFunction = function (InputInterface $input, OutputInterface $output) use ($callable) {
            $parameters = array_merge(
                [
                    // Injection by parameter name
                    'input' => $input,
                    'output' => $output,
                    // Injections by type-hint
                    InputInterface::class => $input,
                    OutputInterface::class => $output,
                    Input::class => $input,
                    Output::class => $output,
                    SymfonyStyle::class => new SymfonyStyle($input, $output),
                ],
                // Arguments and options are injected by parameter names
                $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;
    }
public function command ( $ expression , $ callable , array $ aliases = [ ] ) { $ this -> assertCallableIsValid ( $ callable ) ; $ commandFunction = function ( InputInterface $ input , OutputInterface $ output ) use ( $ callable ) { $ parameters = array_merge ( [ // Injection by parameter name 'input' => $ input , 'output' => $ output , // Injections by type-hint InputInterface :: class => $ input , OutputInterface :: class => $ output , Input :: class => $ input , Output :: class => $ output , SymfonyStyle :: class => new SymfonyStyle ( $ input , $ output ) , ] , // Arguments and options are injected by parameter names $ 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 ; }
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
Define a CLI command using a string expression and a callable .