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. |
Details
at line 68
public
__construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
Constructor.
at line 95
public integer
run(InputInterface $input = null, OutputInterface $output = null)
Runs the current application.
at line 142
public integer
doRun(InputInterface $input, OutputInterface $output)
Runs the current application.
at line 206
public
setHelperSet(HelperSet $helperSet)
Set a helper set to be used with the command.
at line 218
public HelperSet
getHelperSet()
Get the helper set associated with the command.
at line 228
public InputDefinition
getDefinition()
Gets the InputDefinition related to this Application.
at line 238
public string
getHelp()
Gets the help message.
at line 266
public
setCatchExceptions(Boolean $boolean)
Sets whether to catch exceptions or not during commands execution.
at line 278
public
setAutoExit(Boolean $boolean)
Sets whether to automatically exit after a command execution or not.
at line 290
public string
getName()
Gets the name of the application.
at line 302
public
setName(string $name)
Sets the application name.
at line 314
public string
getVersion()
Gets the application version.
at line 326
public
setVersion(string $version)
Sets the application version.
at line 338
public string
getLongVersion()
Returns the long version of the application.
at line 356
public Command
register(string $name)
Registers a new command.
at line 368
public
addCommands(array $commands)
Adds an array of command objects.
at line 386
public Command
add(Command $command)
Adds a command object.
If a command with the same name already exists, it will be overridden.
at line 416
public Command
get(string $name)
Returns a registered command by name or alias.
at line 445
public Boolean
has(string $name)
Returns true if the command exists, false otherwise.
at line 457
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.
at line 480
public string
findNamespace(string $namespace)
Finds a registered namespace by a name or an abbreviation.
at line 535
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.
at line 608
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.
at line 631
static public array
getAbbreviations(array $names)
Returns an array of possible abbreviations given a set of names.
at line 661
public string
asText(string $namespace = null, boolean $raw = false)
Returns a text representation of the Application.
at line 711
public string|DOMDocument
asXml(string $namespace = null, Boolean $asDom = false)
Returns an XML representation of the Application.
at line 763
public
renderException(Exception $e, OutputInterface $output)
Renders a caught exception.