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. | ||
setDispatcher(EventDispatcherInterface $dispatcher) | ||
int | run(InputInterface $input = null, OutputInterface $output = null) Runs the current application. | |
int | 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. | |
setDefinition(InputDefinition $definition) Set an input definition to be used with this application. | ||
InputDefinition | getDefinition() Gets the InputDefinition related to this Application. | |
string | getHelp() Gets the help message. | |
bool | areExceptionsCaught() Gets whether to catch exceptions or not during commands execution. | |
setCatchExceptions(bool $boolean) Sets whether to catch exceptions or not during commands execution. | ||
bool | isAutoExitEnabled() Gets whether to automatically exit after a command execution or not. | |
setAutoExit(bool $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|null | add(Command $command) Adds a command object. | |
Command | get(string $name) Returns a registered command by name or alias. | |
bool | has(string $name) Returns true if the command exists, false otherwise. | |
string[] | 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. | |
Command[] | 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. | |
renderException(Exception $e, OutputInterface $output) Renders a caught exception. | ||
array | getTerminalDimensions() Tries to figure out the terminal dimensions based on the current environment. | |
Application | setTerminalDimensions(int $width, int $height) Sets terminal dimensions. | |
string | extractNamespace(string $name, string $limit = null) Returns the namespace part of the command name. | |
setDefaultCommand(string $commandName) Sets the default Command name. |
Details
__construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
Constructor.
setDispatcher(EventDispatcherInterface $dispatcher)
int run(InputInterface $input = null, OutputInterface $output = null)
Runs the current application.
int 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.
setDefinition(InputDefinition $definition)
Set an input definition to be used with this application.
InputDefinition getDefinition()
Gets the InputDefinition related to this Application.
string getHelp()
Gets the help message.
bool areExceptionsCaught()
Gets whether to catch exceptions or not during commands execution.
setCatchExceptions(bool $boolean)
Sets whether to catch exceptions or not during commands execution.
bool isAutoExitEnabled()
Gets whether to automatically exit after a command execution or not.
setAutoExit(bool $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.
If a Command is not enabled it will not be added.
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.
Command get(string $name)
Returns a registered command by name or alias.
bool has(string $name)
Returns true if the command exists, false otherwise.
string[] getNamespaces()
Returns an array of all unique namespaces used by currently registered commands.
It does not return the global namespace which always exists.
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.
Contrary to get, this command tries to find the best match if you give it an abbreviation of a name or alias.
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.
static array getAbbreviations(array $names)
Returns an array of possible abbreviations given a set of names.
renderException(Exception $e, OutputInterface $output)
Renders a caught exception.
array getTerminalDimensions()
Tries to figure out the terminal dimensions based on the current environment.
Application setTerminalDimensions(int $width, int $height)
Sets terminal dimensions.
Can be useful to force terminal dimensions for functional tests.
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.
setDefaultCommand(string $commandName)
Sets the default Command name.
Please login to continue.