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
No description
Get the helper set associated with the command.
Gets the InputDefinition related to this Application.
Gets the help message.
Gets whether to catch exceptions or not during commands execution.
Sets whether to catch exceptions or not during commands execution.
Gets whether to automatically exit after a command execution or not.
Sets whether to automatically exit after a command execution or not.
Gets the name of the application.
Sets the application name.
Gets the application version.
Sets the application version.
Returns the long version of the application.
Adds an array of command objects.
Returns true if the command exists, false otherwise.
Returns an array of all unique namespaces used by currently registered commands.
Finds a registered namespace by a name or an abbreviation.
Gets the commands (registered in the given namespace if provided).
Returns an array of possible abbreviations given a set of names.
Returns the namespace part of the command name.
Sets the default Command name.
Details
at line line 83
__construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
at line line 91
setDispatcher(EventDispatcherInterface $dispatcher)
at line line 96
setCommandLoader(CommandLoaderInterface $commandLoader)
at line line 108
int
run(InputInterface $input = null, OutputInterface $output = null)
Runs the current application.
at line line 192
int
doRun(InputInterface $input, OutputInterface $output)
Runs the current application.
at line line 247
setHelperSet(HelperSet $helperSet)
at line line 257
HelperSet
getHelperSet()
Get the helper set associated with the command.
at line line 266
setDefinition(InputDefinition $definition)
at line line 276
InputDefinition
getDefinition()
Gets the InputDefinition related to this Application.
at line line 297
string
getHelp()
Gets the help message.
at line line 307
bool
areExceptionsCaught()
Gets whether to catch exceptions or not during commands execution.
at line line 317
setCatchExceptions(bool $boolean)
Sets whether to catch exceptions or not during commands execution.
at line line 327
bool
isAutoExitEnabled()
Gets whether to automatically exit after a command execution or not.
at line line 337
setAutoExit(bool $boolean)
Sets whether to automatically exit after a command execution or not.
at line line 347
string
getName()
Gets the name of the application.
at line line 357
setName(string $name)
Sets the application name.
at line line 367
string
getVersion()
Gets the application version.
at line line 377
setVersion(string $version)
Sets the application version.
at line line 387
string
getLongVersion()
Returns the long version of the application.
at line line 407
Command
register(string $name)
Registers a new command.
at line line 419
addCommands(array $commands)
Adds an array of command objects.
If a Command is not enabled it will not be added.
at line line 434
Command|null
add(Command $command)
Adds a command object.
If a command with the same name already exists, it will be overridden. If the command is not enabled it will not be added.
at line line 472
Command
get(string $name)
Returns a registered command by name or alias.
at line line 501
bool
has(string $name)
Returns true if the command exists, false otherwise.
at line line 515
string[]
getNamespaces()
Returns an array of all unique namespaces used by currently registered commands.
It does not return the global namespace which always exists.
at line line 538
string
findNamespace(string $namespace)
Finds a registered namespace by a name or an abbreviation.
at line line 580
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 line 658
Command[]
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 line 702
static array
getAbbreviations(array $names)
Returns an array of possible abbreviations given a set of names.
at line line 718
renderException(Exception $e, OutputInterface $output)
Renders a caught exception.
at line line 984
string
extractNamespace(string $name, string $limit = null)
Returns the namespace part of the command name.
This method is not part of public API and should not be used directly.
at line line 1051
Application
setDefaultCommand(string $commandName, bool $isSingleCommand = false)
Sets the default Command name.