Class

Symfony\Component\Console\Application

class Application

An Application is the container for a collection of commands.

It is the main entry point of a Console application.

This class is optimized for a standard CLI environment.

Usage:

$app = new Application('myapp', '1.0 (stable)');
$app->add(new SimpleCommand());
$app->run();

Methods

__construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')

Constructor.

integer run(InputInterface $input = null, OutputInterface $output = null)

Runs the current application.

integer doRun(InputInterface $input, OutputInterface $output)

Runs the current application.

setHelperSet(HelperSet $helperSet)

Set a helper set to be used with the command.

HelperSet getHelperSet()

Get the helper set associated with the command.

InputDefinition getDefinition()

Gets the InputDefinition related to this Application.

string getHelp()

Gets the help message.

setCatchExceptions(Boolean $boolean)

Sets whether to catch exceptions or not during commands execution.

setAutoExit(Boolean $boolean)

Sets whether to automatically exit after a command execution or not.

string getName()

Gets the name of the application.

setName(string $name)

Sets the application name.

string getVersion()

Gets the application version.

setVersion(string $version)

Sets the application version.

string getLongVersion()

Returns the long version of the application.

Command register(string $name)

Registers a new command.

addCommands(array $commands)

Adds an array of command objects.

Command add(Command $command)

Adds a command object.

Command get(string $name)

Returns a registered command by name or alias.

Boolean has(string $name)

Returns true if the command exists, false otherwise.

array getNamespaces()

Returns an array of all unique namespaces used by currently registered commands.

string findNamespace(string $namespace)

Finds a registered namespace by a name or an abbreviation.

Command find(string $name)

Finds a command by name or alias.

array all(string $namespace = null)

Gets the commands (registered in the given namespace if provided).

static array getAbbreviations(array $names)

Returns an array of possible abbreviations given a set of names.

string asText(string $namespace = null, boolean $raw = false)

Returns a text representation of the Application.

string|DOMDocument asXml(string $namespace = null, Boolean $asDom = false)

Returns an XML representation of the Application.

renderException(Exception $e, OutputInterface $output)

Renders a caught exception.

array getTerminalDimensions()

Tries to figure out the terminal dimensions based on the current environment

Details

at line 67
public __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')

Constructor.

Parameters

string $name The name of the application
string $version The version of the application

at line 94
public integer run(InputInterface $input = null, OutputInterface $output = null)

Runs the current application.

Parameters

InputInterface $input An Input instance
OutputInterface $output An Output instance

Return Value

integer 0 if everything went fine, or an error code

Exceptions

Exception When doRun returns Exception

at line 148
public integer doRun(InputInterface $input, OutputInterface $output)

Runs the current application.

Parameters

InputInterface $input An Input instance
OutputInterface $output An Output instance

Return Value

integer 0 if everything went fine, or an error code

at line 212
public setHelperSet(HelperSet $helperSet)

Set a helper set to be used with the command.

Parameters

HelperSet $helperSet The helper set

at line 224
public HelperSet getHelperSet()

Get the helper set associated with the command.

Return Value

HelperSet The HelperSet instance associated with this command

at line 234
public InputDefinition getDefinition()

Gets the InputDefinition related to this Application.

Return Value

InputDefinition The InputDefinition instance

at line 244
public string getHelp()

Gets the help message.

Return Value

string A help message.

at line 272
public setCatchExceptions(Boolean $boolean)

Sets whether to catch exceptions or not during commands execution.

Parameters

Boolean $boolean Whether to catch exceptions or not during commands execution

at line 284
public setAutoExit(Boolean $boolean)

Sets whether to automatically exit after a command execution or not.

Parameters

Boolean $boolean Whether to automatically exit after a command execution or not

at line 296
public string getName()

Gets the name of the application.

Return Value

string The application name

at line 308
public setName(string $name)

Sets the application name.

Parameters

string $name The application name

at line 320
public string getVersion()

Gets the application version.

Return Value

string The application version

at line 332
public setVersion(string $version)

Sets the application version.

Parameters

string $version The application version

at line 344
public string getLongVersion()

Returns the long version of the application.

Return Value

string The long application version

at line 362
public Command register(string $name)

Registers a new command.

Parameters

string $name The command name

Return Value

Command The newly created command

at line 374
public addCommands(array $commands)

Adds an array of command objects.

Parameters

array $commands An array of commands

at line 392
public Command add(Command $command)

Adds a command object.

If a command with the same name already exists, it will be overridden.

Parameters

Command $command A Command object

Return Value

Command The registered command

at line 422
public Command get(string $name)

Returns a registered command by name or alias.

Parameters

string $name The command name or alias

Return Value

Command A Command object

Exceptions

InvalidArgumentException When command name given does not exist

at line 451
public Boolean has(string $name)

Returns true if the command exists, false otherwise.

Parameters

string $name The command name or alias

Return Value

Boolean true if the command exists, false otherwise

at line 463
public array getNamespaces()

Returns an array of all unique namespaces used by currently registered commands.

It does not returns the global namespace which always exists.

Return Value

array An array of namespaces

at line 486
public string findNamespace(string $namespace)

Finds a registered namespace by a name or an abbreviation.

Parameters

string $namespace A namespace or abbreviation to search for

Return Value

string A registered namespace

Exceptions

InvalidArgumentException When namespace is incorrect or ambiguous

at line 550
public Command find(string $name)

Finds a command by name or alias.

Contrary to get, this command tries to find the best match if you give it an abbreviation of a name or alias.

Parameters

string $name A command name or a command alias

Return Value

Command A Command instance

Exceptions

InvalidArgumentException When command name is incorrect or ambiguous

at line 633
public array all(string $namespace = null)

Gets the commands (registered in the given namespace if provided).

The array keys are the full names and the values the command instances.

Parameters

string $namespace A namespace name

Return Value

array An array of Command instances

at line 656
static public array getAbbreviations(array $names)

Returns an array of possible abbreviations given a set of names.

Parameters

array $names An array of names

Return Value

array An array of abbreviations

at line 677
public string asText(string $namespace = null, boolean $raw = false)

Returns a text representation of the Application.

Parameters

string $namespace An optional namespace name
boolean $raw Whether to return raw command list

Return Value

string A string representing the Application

at line 727
public string|DOMDocument asXml(string $namespace = null, Boolean $asDom = false)

Returns an XML representation of the Application.

Parameters

string $namespace An optional namespace name
Boolean $asDom Whether to return a DOM or an XML string

Return Value

string|DOMDocument An XML string representing the Application

at line 779
public renderException(Exception $e, OutputInterface $output)

Renders a caught exception.

Parameters

Exception $e An exception instance
OutputInterface $output An OutputInterface instance

at line 884
public array getTerminalDimensions()

Tries to figure out the terminal dimensions based on the current environment

Return Value

array Array containing width and height