abstract class Command extends Command (View source)

base command class Large swaths of this class have been copied from illuminate/config 5.2 and 5.5 so you may refer to their documentation for some things.

Constants

deprecated RETURN_CODE_ON_SUCCESS

deprecated RETURN_CODE_ON_FAILURE

INVALID

Concrete requires symfony/console ^5.2, and the INVALID constant has been introduced in symfony/console 5.3.0

ALLOWASROOT_OPTION

The name of the CLI option that allows running CLI commands as root without confirmation.

ALLOWASROOT_ENV

The name of the environment variable that allows running CLI commands as root without confirmation.

Properties

protected InputInterface $input
protected OutputStyle $output
protected string $name
protected string $description
protected bool $hidden
protected string $signature

The command signature.

protected bool $canRunAsRoot

Can this command be executed as root? If set to false, the command can be executed if one of these conditions is satisfied:

  • the users is not root
  • the --allow-as-root option is set
  • the C5_CLI_ALLOW_AS_ROOT environment variable is set
  • the console is interactive and the user explicitly confirm the operation.

Methods

__construct($name = null)

No description

run(InputInterface $input, OutputInterface $output)

{@inheritdoc}

int
call(string $command, array $arguments = [])

Call another console command.

int
callSilent(string $command, array $arguments = [])

Call another console command silently.

bool
hasArgument(string|int $name)

Determine if the given argument is present.

string|array
argument(string|null $key = null)

Get the value of a command argument.

array
arguments()

Get all of the arguments passed to the command.

bool
hasOption(string $name)

Determine if the given option is present.

string|array
option(string $key = null)

Get the value of a command option.

array
options()

Get all of the options passed to the command.

bool
confirm(string $question, bool $default = false)

Confirm a question with the user.

string
ask(string $question, string $default = null)

Prompt the user for input.

string
askWithCompletion(string $question, array $choices, string $default = null, null $attempts = null, null $strict = null)

Prompt the user for input with auto completion.

string
secret(string $question, bool $fallback = true)

Prompt the user for input but hide the answer from the console.

string
choice(string $question, array $choices, string $default = null, mixed $attempts = null, bool $multiple = null)

Give the user a single choice from an array of answers.

void
table(array $headers, array $rows, string $tableStyle = 'default', array $columnStyles = [])

Format input to textual table.

Application|Application
getApplication()

{@inheritdoc}

void
configureUsingFluentDefinition()

Configure the console command using a fluent definition.

void
specifyParameters()

Specify the arguments and options on the command.

array
getArguments()

Get the arguments for this command.

array
getOptions()

Get the options for this command.

initialize(InputInterface $input, OutputInterface $output)

{@inheritdoc}

writeError(OutputInterface $output, Exception|Throwable $error) deprecated

Write an exception.

addEnvOption()

Add the "env" option to the command options.

$this
setCanRunAsRoot(bool $canRunAsRoot)

Allow/disallow running this command as root without confirmation.

bool|null
isRunningAsRoot()

Is the current user root?

confirmRunningAsRoot(InputInterface $input, OutputInterface $output)

No description

int
execute(InputInterface $input, OutputInterface $output)

This method is overridden to pipe execution to the handle method hiding input and output.

Details

__construct($name = null)

No description

Parameters

$name

run(InputInterface $input, OutputInterface $output)

{@inheritdoc}

Parameters

InputInterface $input
OutputInterface $output

int call(string $command, array $arguments = [])

Call another console command.

Parameters

string $command
array $arguments

Return Value

int

int callSilent(string $command, array $arguments = [])

Call another console command silently.

Parameters

string $command
array $arguments

Return Value

int

bool hasArgument(string|int $name)

Determine if the given argument is present.

Parameters

string|int $name

Return Value

bool

string|array argument(string|null $key = null)

Get the value of a command argument.

Parameters

string|null $key

Return Value

string|array

array arguments()

Get all of the arguments passed to the command.

Return Value

array

bool hasOption(string $name)

Determine if the given option is present.

Parameters

string $name

Return Value

bool

string|array option(string $key = null)

Get the value of a command option.

Parameters

string $key

Return Value

string|array

array options()

Get all of the options passed to the command.

Return Value

array

bool confirm(string $question, bool $default = false)

Confirm a question with the user.

Parameters

string $question
bool $default

Return Value

bool

string ask(string $question, string $default = null)

Prompt the user for input.

Parameters

string $question
string $default

Return Value

string

string askWithCompletion(string $question, array $choices, string $default = null, null $attempts = null, null $strict = null)

Prompt the user for input with auto completion.

Parameters

string $question
array $choices
string $default
null $attempts
null $strict

Return Value

string

string secret(string $question, bool $fallback = true)

Prompt the user for input but hide the answer from the console.

Parameters

string $question
bool $fallback

Return Value

string

string choice(string $question, array $choices, string $default = null, mixed $attempts = null, bool $multiple = null)

Give the user a single choice from an array of answers.

Parameters

string $question
array $choices
string $default
mixed $attempts
bool $multiple

Return Value

string

void table(array $headers, array $rows, string $tableStyle = 'default', array $columnStyles = [])

Format input to textual table.

Parameters

array $headers
array $rows
string $tableStyle
array $columnStyles

Return Value

void

Application|Application getApplication()

{@inheritdoc}

Return Value

Application|Application

protected void configureUsingFluentDefinition()

Configure the console command using a fluent definition.

Return Value

void

protected void specifyParameters()

Specify the arguments and options on the command.

Return Value

void

protected array getArguments()

Get the arguments for this command.

If $this->signature is specified, this method has no effect.

Return Value

array

[[$name, $mode = null, $description = '', $default = null], ...]

protected array getOptions()

Get the options for this command.

If $this->signature is specified, this method has no effect.

Return Value

array

[[$name, $shortcut = null, $mode = null, $description = '', $default = null], ...]

protected initialize(InputInterface $input, OutputInterface $output)

{@inheritdoc}

Parameters

InputInterface $input
OutputInterface $output

See also

\Symfony\Component\Console\Command\Command::initialize()

protected writeError(OutputInterface $output, Exception|Throwable $error) deprecated

deprecated Use $this->output to manage your output

Write an exception.

Parameters

OutputInterface $output
Exception|Throwable $error

See also

\Concrete\Core\Console\OutputStyle::error()

protected Command addEnvOption()

Add the "env" option to the command options.

Return Value

Command

protected $this setCanRunAsRoot(bool $canRunAsRoot)

Allow/disallow running this command as root without confirmation.

Parameters

bool $canRunAsRoot

if false the command can be executed if one of these conditions is satisfied:

  • the users is not root
  • the --allow-as-root option is set
  • the C5_CLI_ALLOW_AS_ROOT environment variable is set
  • the console is interactive and the user explicitly confirm the operation

Return Value

$this

protected bool|null isRunningAsRoot()

Is the current user root?

Return Value

bool|null

NULL if unknown, or boolean if determined

protected confirmRunningAsRoot(InputInterface $input, OutputInterface $output)

No description

Parameters

InputInterface $input
OutputInterface $output

Exceptions

UserMessageException

protected int execute(InputInterface $input, OutputInterface $output)

This method is overridden to pipe execution to the handle method hiding input and output.

Parameters

InputInterface $input
OutputInterface $output

Return Value

int

See also

\Symfony\Component\Console\Command\Command::execute()