class ConsoleOutput (View source)

A wrapper for Symfony ConsoleOutput and related helpers

Properties

protected ConsoleOutput $output
protected StringInput $input
protected QuestionHelper $questionHelper
protected ProgressBar $progressBar
protected Table $table

Methods

__construct()

Creates and initializes the SymfonyConsoleOutput instance

int
getMaximumLineLength()

Returns the desired maximum line length for console output.

void
output(string $text, array $arguments = [])

Outputs specified text to the console window You can specify arguments that will be passed to the text via sprintf

void
outputLine(string $text = '', array $arguments = [])

Outputs specified text to the console window and appends a line break

void
outputFormatted(string $text = '', array $arguments = [], int $leftPadding = 0)

Formats the given text to fit into the maximum line length and outputs it to the console window

void
outputTable(array $rows, array $headers = null, string $headerTitle = null)

Renders a table like output of the given $rows

int|string|array
select(string|array $question, array $choices, mixed|null $default = null, bool $multiSelect = false, int $attempts = null)

Asks the user to select a value

mixed
ask(string|array $question, string $default = null)

Asks a question to the user

mixed
askQuestion(Question $question)

Asks a question to the user

bool
askConfirmation(string|array $question, bool $default = true)

Asks a confirmation to the user.

mixed
askHiddenResponse(string|array $question, bool $fallback = true)

Asks a question to the user, the response is hidden

mixed
askAndValidate(string|array $question, callable $validator, int $attempts = null, string $default = null)

Asks for a value and validates the response

mixed
askHiddenResponseAndValidate(string|array $question, callable $validator, int $attempts = null, bool $fallback = true)

Asks for a value, hide and validates the response

void
progressStart(int $max = null)

Starts the progress output

void
progressAdvance(int $step = 1)

Advances the progress output X steps

void
progressSet(int $current)

Sets the current progress

void
progressFinish()

Finishes the progress output

void
setOutput(OutputInterface $output)

No description

OutputInterface
getOutput()

No description

void
setInput(InputInterface $input)

No description

InputInterface
getInput()

No description

QuestionHelper
getQuestionHelper()

Returns or initializes the symfony/console QuestionHelper

string
combineQuestion(string|array $question)

If question is an array, split it into multi-line string

ProgressBar
getProgressBar()

Returns or initializes the symfony/console ProgressHelper

Table
getTable()

Returns or initializes the symfony/console Table

Details

__construct()

Creates and initializes the SymfonyConsoleOutput instance

int getMaximumLineLength()

Returns the desired maximum line length for console output.

Return Value

int

void output(string $text, array $arguments = [])

Outputs specified text to the console window You can specify arguments that will be passed to the text via sprintf

Parameters

string $text

Text to output

array $arguments

Optional arguments to use for sprintf

Return Value

void

See also

http://www.php.net/sprintf

void outputLine(string $text = '', array $arguments = [])

Outputs specified text to the console window and appends a line break

Parameters

string $text

Text to output

array $arguments

Optional arguments to use for sprintf

Return Value

void

See also

output()
outputLines()

void outputFormatted(string $text = '', array $arguments = [], int $leftPadding = 0)

Formats the given text to fit into the maximum line length and outputs it to the console window

Parameters

string $text

Text to output

array $arguments

Optional arguments to use for sprintf

int $leftPadding

The number of spaces to use for indentation

Return Value

void

See also

outputLine()

void outputTable(array $rows, array $headers = null, string $headerTitle = null)

Renders a table like output of the given $rows

Parameters

array $rows
array $headers
string $headerTitle

Return Value

void

int|string|array select(string|array $question, array $choices, mixed|null $default = null, bool $multiSelect = false, int $attempts = null)

Asks the user to select a value

Parameters

string|array $question

The question to ask. If an array each array item is turned into one line of a multi-line question

array $choices

List of choices to pick from

mixed|null $default

The default answer if the user enters nothing

bool $multiSelect

If true the result will be an array with the selected options. Multiple options can be given separated by commas

int $attempts

Max number of times to ask before giving up (null by default, which means infinite)

Return Value

int|string|array

Either the value for indexed arrays, the key for associative arrays or an array for multiple selections

Exceptions

InvalidArgumentException

mixed ask(string|array $question, string $default = null)

Asks a question to the user

Parameters

string|array $question

The question to ask. If an array each array item is turned into one line of a multi-line question

string $default

The default answer if none is given by the user

Return Value

mixed

The user answer

Exceptions

RuntimeException

mixed askQuestion(Question $question)

Asks a question to the user

Parameters

Question $question

The question to ask as an Object.

Return Value

mixed

The user answer

Exceptions

RuntimeException

bool askConfirmation(string|array $question, bool $default = true)

Asks a confirmation to the user.

The question will be asked until the user answers by nothing, yes, or no.

Parameters

string|array $question

The question to ask. If an array each array item is turned into one line of a multi-line question

bool $default

The default answer if the user enters nothing

Return Value

bool

true if the user has confirmed, false otherwise

mixed askHiddenResponse(string|array $question, bool $fallback = true)

Asks a question to the user, the response is hidden

Parameters

string|array $question

The question. If an array each array item is turned into one line of a multi-line question

bool $fallback

In case the response can not be hidden, whether to fallback on non-hidden question or not

Return Value

mixed

The answer

Exceptions

RuntimeException

mixed askAndValidate(string|array $question, callable $validator, int $attempts = null, string $default = null)

Asks for a value and validates the response

The validator receives the data to validate. It must return the validated data when the data is valid and throw an exception otherwise.

Parameters

string|array $question

The question to ask. If an array each array item is turned into one line of a multi-line question

callable $validator

A PHP callback that gets a value and is expected to return the (transformed) value or throw an exception if it wasn't valid

int $attempts

Max number of times to ask before giving up (null by default, which means infinite)

string $default

The default answer if none is given by the user

Return Value

mixed

The response

Exceptions

Exception

See also

https://symfony.com/doc/current/components/console/helpers/questionhelper.html#validating-the-answer

mixed askHiddenResponseAndValidate(string|array $question, callable $validator, int $attempts = null, bool $fallback = true)

Asks for a value, hide and validates the response

The validator receives the data to validate. It must return the validated data when the data is valid and throw an exception otherwise.

Parameters

string|array $question

The question to ask. If an array each array item is turned into one line of a multi-line question

callable $validator

A PHP callback that gets a value and is expected to return the (transformed) value or throw an exception if it wasn't valid

int $attempts

Max number of times to ask before giving up (null by default, which means infinite)

bool $fallback

In case the response can not be hidden, whether to fallback on non-hidden question or not

Return Value

mixed

The response

Exceptions

Exception
RuntimeException

void progressStart(int $max = null)

Starts the progress output

Parameters

int $max

Maximum steps. If NULL an indeterminate progress bar is rendered

Return Value

void

void progressAdvance(int $step = 1)

Advances the progress output X steps

Parameters

int $step

Number of steps to advance

Return Value

void

Exceptions

LogicException

void progressSet(int $current)

Sets the current progress

Parameters

int $current

The current progress

Return Value

void

Exceptions

LogicException

void progressFinish()

Finishes the progress output

Return Value

void

void setOutput(OutputInterface $output)

No description

Parameters

OutputInterface $output

Return Value

void

OutputInterface getOutput()

No description

Return Value

OutputInterface

void setInput(InputInterface $input)

No description

Parameters

InputInterface $input

Return Value

void

InputInterface getInput()

No description

Return Value

InputInterface

QuestionHelper getQuestionHelper()

Returns or initializes the symfony/console QuestionHelper

Return Value

QuestionHelper

protected string combineQuestion(string|array $question)

If question is an array, split it into multi-line string

Parameters

string|array $question

Return Value

string

ProgressBar getProgressBar()

Returns or initializes the symfony/console ProgressHelper

Return Value

ProgressBar

protected Table getTable()

Returns or initializes the symfony/console Table

Return Value

Table