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 summary
public
|
#
__construct( string $name = 'UNKNOWN', string $version = 'UNKNOWN' )
Constructor.
Parameters
- $name
string $name The name of the application
- $version
string $version The version of the application
Api
|
public
integer
|
|
public
integer
|
|
public
|
|
public
Symfony\Component\Console\Helper\HelperSet
|
#
getHelperSet( )
Get the helper set associated with the command.
Get the helper set associated with the command.
Returns
Api
|
public
Symfony\Component\Console\Input\InputDefinition
|
#
getDefinition( )
Gets the InputDefinition related to this Application.
Gets the InputDefinition related to this Application.
Returns
|
public
string
|
#
getHelp( )
Gets the help message.
Returns
string A help message.
|
public
|
#
setCatchExceptions( Boolean $boolean )
Sets whether to catch exceptions or not during commands execution.
Sets whether to catch exceptions or not during commands execution.
Parameters
- $boolean
Boolean $boolean Whether to catch exceptions or not during commands execution
Api
|
public
|
#
setAutoExit( Boolean $boolean )
Sets whether to automatically exit after a command execution or not.
Sets whether to automatically exit after a command execution or not.
Parameters
- $boolean
Boolean $boolean Whether to automatically exit after a command execution or not
Api
|
public
string
|
#
getName( )
Gets the name of the application.
Gets the name of the application.
Returns
string The application name
Api
|
public
|
#
setName( string $name )
Sets the application name.
Sets the application name.
Parameters
- $name
string $name The application name
Api
|
public
string
|
#
getVersion( )
Gets the application version.
Gets the application version.
Returns
string The application version
Api
|
public
|
#
setVersion( string $version )
Sets the application version.
Sets the application version.
Parameters
- $version
string $version The application version
Api
|
public
string
|
#
getLongVersion( )
Returns the long version of the application.
Returns the long version of the application.
Returns
string The long application version
Api
|
public
Symfony\Component\Console\Command\Command
|
#
register( string $name )
Registers a new command.
Parameters
- $name
string $name The command name
Returns
Api
|
public
|
#
addCommands( array $commands )
Adds an array of command objects.
Adds an array of command objects.
Parameters
Api
|
public
Symfony\Component\Console\Command\Command
|
|
public
Symfony\Component\Console\Command\Command
|
#
get( string $name )
Returns a registered command by name or alias.
Returns a registered command by name or alias.
Parameters
- $name
string $name The command name or alias
Returns
Throws
Api
|
public
Boolean
|
#
has( string $name )
Returns true if the command exists, false otherwise.
Returns true if the command exists, false otherwise.
Parameters
- $name
string $name The command name or alias
Returns
Boolean true if the command exists, false otherwise
Api
|
public
array
|
#
getNamespaces( )
Returns an array of all unique namespaces used by currently registered
commands.
Returns an array of all unique namespaces used by currently registered
commands.
It does not returns the global namespace which always exists.
Returns
array An array of namespaces
|
public
string
|
#
findNamespace( string $namespace )
Finds a registered namespace by a name or an abbreviation.
Finds a registered namespace by a name or an abbreviation.
Parameters
- $namespace
string $namespace A namespace or abbreviation to search for
Returns
string A registered namespace
Throws
|
public
Symfony\Component\Console\Command\Command
|
#
find( string $name )
Finds a command by name or alias.
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
- $name
string $name A command name or a command alias
Returns
Throws
Api
|
public
array
|
#
all( string $namespace = null )
Gets the commands (registered in the given namespace if provided).
Gets the commands (registered in the given namespace if provided).
The array keys are the full names and the values the command instances.
Parameters
- $namespace
string $namespace A namespace name
Returns
array An array of Command instances
Api
|
public static
array
|
#
getAbbreviations( array $names )
Returns an array of possible abbreviations given a set of names.
Returns an array of possible abbreviations given a set of names.
Parameters
- $names
array $names An array of names
Returns
array An array of abbreviations
|
public
string
|
#
asText( string $namespace = null, boolean $raw = false )
Returns a text representation of the Application.
Returns a text representation of the Application.
Parameters
- $namespace
string $namespace An optional namespace name
- $raw
boolean $raw Whether to return raw command list
Returns
string A string representing the Application
|
public
string|DOMDocument
|
#
asXml( string $namespace = null, Boolean $asDom = false )
Returns an XML representation of the Application.
Returns an XML representation of the Application.
Parameters
- $namespace
string $namespace An optional namespace name
- $asDom
Boolean $asDom Whether to return a DOM or an XML string
Returns
string|DOMDocument An XML string representing the Application
|
public
|
|
protected
string
|
|
protected
Symfony\Component\Console\Input\InputDefinition
|
|
protected
array
|
#
getDefaultCommands( )
Gets the default commands that should always be available.
Gets the default commands that should always be available.
Returns
array An array of default Command instances
|
protected
Symfony\Component\Console\Helper\HelperSet
|
#
getDefaultHelperSet( )
Gets the default helper set with the helpers that should always be
available.
Gets the default helper set with the helpers that should always be
available.
Returns
|
private
array
|
#
sortCommands( array $commands )
Sorts commands in alphabetical order.
Sorts commands in alphabetical order.
Parameters
- $commands
array $commands An associative array of commands to sort
Returns
array A sorted array of commands
|
private
string
|
#
getAbbreviationSuggestions( array $abbrevs )
Returns abbreviated suggestions in string format.
Returns abbreviated suggestions in string format.
Parameters
- $abbrevs
array $abbrevs Abbreviated suggestions to convert
Returns
string A formatted string of abbreviated suggestions
|
private
array
|
#
findAlternativeCommands( string $name, array $abbrevs )
Finds alternative commands of $name
Finds alternative commands of $name
Parameters
- $name
string $name The full name of the command
- $abbrevs
array $abbrevs The abbreviations
Returns
array A sorted array of similar commands
|
private
array
|
#
findAlternativeNamespace( string $name, array $abbrevs )
Finds alternative namespace of $name
Finds alternative namespace of $name
Parameters
- $name
string $name The full name of the namespace
- $abbrevs
array $abbrevs The abbreviations
Returns
array A sorted array of similar namespace
|
private
array
|
#
findAlternatives( string $name, array|Traversable $collection, array $abbrevs, Closure |string|array $callback = null )
Finds alternative of $name among $collection, if nothing is found in
$collection, try in $abbrevs
Finds alternative of $name among $collection, if nothing is found in
$collection, try in $abbrevs
Parameters
- $name
string $name The string
- $collection
array|Traversable $collection The collecion
- $abbrevs
array $abbrevs The abbreviations
- $callback
Closure |string|array
$callback The callable to transform collection item before comparison
Returns
array A sorted array of similar string
|