PHP Class Symfony\Component\Console\Application

Show file Open project: symfony/symfony Class Usage Examples

Public Methods

Method Description
__construct ( string $name = 'UNKNOWN', string $version = 'UNKNOWN' )
add ( Command $command ) : Command | null Adds a command object.
addCommands ( array $commands ) Adds an array of command objects.
all ( string $namespace = null ) : Command[] Gets the commands (registered in the given namespace if provided).
areExceptionsCaught ( ) : boolean Gets whether to catch exceptions or not during commands execution.
doRun ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer Runs the current application.
extractNamespace ( string $name, string $limit = null ) : string Returns the namespace part of the command name.
find ( string $name ) : Command Finds a command by name or alias.
findNamespace ( string $namespace ) : string Finds a registered namespace by a name or an abbreviation.
get ( string $name ) : Command Returns a registered command by name or alias.
getAbbreviations ( array $names ) : array Returns an array of possible abbreviations given a set of names.
getDefinition ( ) : Symfony\Component\Console\Input\InputDefinition Gets the InputDefinition related to this Application.
getHelp ( ) : string Gets the help message.
getHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet Get the helper set associated with the command.
getLongVersion ( ) : string Returns the long version of the application.
getName ( ) : string Gets the name of the application.
getNamespaces ( ) : string[] Returns an array of all unique namespaces used by currently registered commands.
getTerminalDimensions ( ) : array Tries to figure out the terminal dimensions based on the current environment.
getVersion ( ) : string Gets the application version.
has ( string $name ) : boolean Returns true if the command exists, false otherwise.
isAutoExitEnabled ( ) : boolean Gets whether to automatically exit after a command execution or not.
register ( string $name ) : Command Registers a new command.
renderException ( Exception $e, Symfony\Component\Console\Output\OutputInterface $output ) Renders a caught exception.
run ( Symfony\Component\Console\Input\InputInterface $input = null, Symfony\Component\Console\Output\OutputInterface $output = null ) : integer Runs the current application.
setAutoExit ( boolean $boolean ) Sets whether to automatically exit after a command execution or not.
setCatchExceptions ( boolean $boolean ) Sets whether to catch exceptions or not during commands execution.
setDefaultCommand ( string $commandName, boolean $isSingleCommand = false ) : self Sets the default Command name.
setDefinition ( Symfony\Component\Console\Input\InputDefinition $definition ) Set an input definition to be used with this application.
setDispatcher ( Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher )
setHelperSet ( Symfony\Component\Console\Helper\HelperSet $helperSet ) Set a helper set to be used with the command.
setName ( string $name ) Sets the application name.
setTerminalDimensions ( integer $width, integer $height ) : Application Sets terminal dimensions.
setVersion ( string $version ) Sets the application version.

Protected Methods

Method Description
configureIO ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) Configures the input and output instances based on the user arguments and options.
doRunCommand ( Command $command, Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer Runs the current command.
getCommandName ( Symfony\Component\Console\Input\InputInterface $input ) : string Gets the name of the command based on input.
getDefaultCommands ( ) : Command[] Gets the default commands that should always be available.
getDefaultHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet Gets the default helper set with the helpers that should always be available.
getDefaultInputDefinition ( ) : Symfony\Component\Console\Input\InputDefinition Gets the default input definition.
getTerminalHeight ( ) : integer | null Tries to figure out the terminal height in which this application runs.
getTerminalWidth ( ) : integer | null Tries to figure out the terminal width in which this application runs.

Private Methods

Method Description
extractAllNamespaces ( string $name ) : string[] Returns all namespaces of the command name.
findAlternatives ( string $name, array | Traversable $collection ) : string[] Finds alternative of $name among $collection, if nothing is found in $collection, try in $abbrevs.
getAbbreviationSuggestions ( array $abbrevs ) : string Returns abbreviated suggestions in string format.
splitStringByWidth ( $string, $width )
stringWidth ( $string )

Method Details

__construct() public method

public __construct ( string $name = 'UNKNOWN', string $version = 'UNKNOWN' )
$name string The name of the application
$version string The version of the application

add() public method

If a command with the same name already exists, it will be overridden. If the command is not enabled it will not be added.
public add ( Command $command ) : Command | null
$command Symfony\Component\Console\Command\Command A Command object
return Symfony\Component\Console\Command\Command | null The registered command if enabled or null

addCommands() public method

If a Command is not enabled it will not be added.
public addCommands ( array $commands )
$commands array An array of commands

all() public method

The array keys are the full names and the values the command instances.
public all ( string $namespace = null ) : Command[]
$namespace string A namespace name
return Symfony\Component\Console\Command\Command[] An array of Command instances

areExceptionsCaught() public method

Gets whether to catch exceptions or not during commands execution.
public areExceptionsCaught ( ) : boolean
return boolean Whether to catch exceptions or not during commands execution

configureIO() protected method

Configures the input and output instances based on the user arguments and options.
protected configureIO ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface An InputInterface instance
$output Symfony\Component\Console\Output\OutputInterface An OutputInterface instance

doRun() public method

Runs the current application.
public doRun ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer
$input Symfony\Component\Console\Input\InputInterface An Input instance
$output Symfony\Component\Console\Output\OutputInterface An Output instance
return integer 0 if everything went fine, or an error code

doRunCommand() protected method

If an event dispatcher has been attached to the application, events are also dispatched during the life-cycle of the command.
protected doRunCommand ( Command $command, Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer
$command Symfony\Component\Console\Command\Command A Command instance
$input Symfony\Component\Console\Input\InputInterface An Input instance
$output Symfony\Component\Console\Output\OutputInterface An Output instance
return integer 0 if everything went fine, or an error code

extractNamespace() public method

This method is not part of public API and should not be used directly.
public extractNamespace ( string $name, string $limit = null ) : string
$name string The full name of the command
$limit string The maximum number of parts of the namespace
return string The namespace of the command

find() public method

Contrary to get, this command tries to find the best match if you give it an abbreviation of a name or alias.
public find ( string $name ) : Command
$name string A command name or a command alias
return Symfony\Component\Console\Command\Command A Command instance

findNamespace() public method

Finds a registered namespace by a name or an abbreviation.
public findNamespace ( string $namespace ) : string
$namespace string A namespace or abbreviation to search for
return string A registered namespace

get() public method

Returns a registered command by name or alias.
public get ( string $name ) : Command
$name string The command name or alias
return Symfony\Component\Console\Command\Command A Command object

getAbbreviations() public static method

Returns an array of possible abbreviations given a set of names.
public static getAbbreviations ( array $names ) : array
$names array An array of names
return array An array of abbreviations

getCommandName() protected method

Gets the name of the command based on input.
protected getCommandName ( Symfony\Component\Console\Input\InputInterface $input ) : string
$input Symfony\Component\Console\Input\InputInterface The input interface
return string The command name

getDefaultCommands() protected method

Gets the default commands that should always be available.
protected getDefaultCommands ( ) : Command[]
return Symfony\Component\Console\Command\Command[] An array of default Command instances

getDefaultHelperSet() protected method

Gets the default helper set with the helpers that should always be available.
protected getDefaultHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet
return Symfony\Component\Console\Helper\HelperSet A HelperSet instance

getDefaultInputDefinition() protected method

Gets the default input definition.
protected getDefaultInputDefinition ( ) : Symfony\Component\Console\Input\InputDefinition
return Symfony\Component\Console\Input\InputDefinition An InputDefinition instance

getDefinition() public method

Gets the InputDefinition related to this Application.
public getDefinition ( ) : Symfony\Component\Console\Input\InputDefinition
return Symfony\Component\Console\Input\InputDefinition The InputDefinition instance

getHelp() public method

Gets the help message.
public getHelp ( ) : string
return string A help message

getHelperSet() public method

Get the helper set associated with the command.
public getHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet
return Symfony\Component\Console\Helper\HelperSet The HelperSet instance associated with this command

getLongVersion() public method

Returns the long version of the application.
public getLongVersion ( ) : string
return string The long application version

getName() public method

Gets the name of the application.
public getName ( ) : string
return string The application name

getNamespaces() public method

It does not return the global namespace which always exists.
public getNamespaces ( ) : string[]
return string[] An array of namespaces

getTerminalDimensions() public method

Tries to figure out the terminal dimensions based on the current environment.
Deprecation: since version 3.2, to be removed in 4.0. Create a Terminal instance instead.
public getTerminalDimensions ( ) : array
return array Array containing width and height

getTerminalHeight() protected method

Tries to figure out the terminal height in which this application runs.
Deprecation: since version 3.2, to be removed in 4.0. Create a Terminal instance instead.
protected getTerminalHeight ( ) : integer | null
return integer | null

getTerminalWidth() protected method

Tries to figure out the terminal width in which this application runs.
Deprecation: since version 3.2, to be removed in 4.0. Create a Terminal instance instead.
protected getTerminalWidth ( ) : integer | null
return integer | null

getVersion() public method

Gets the application version.
public getVersion ( ) : string
return string The application version

has() public method

Returns true if the command exists, false otherwise.
public has ( string $name ) : boolean
$name string The command name or alias
return boolean true if the command exists, false otherwise

isAutoExitEnabled() public method

Gets whether to automatically exit after a command execution or not.
public isAutoExitEnabled ( ) : boolean
return boolean Whether to automatically exit after a command execution or not

register() public method

Registers a new command.
public register ( string $name ) : Command
$name string The command name
return Symfony\Component\Console\Command\Command The newly created command

renderException() public method

Renders a caught exception.
public renderException ( Exception $e, Symfony\Component\Console\Output\OutputInterface $output )
$e Exception An exception instance
$output Symfony\Component\Console\Output\OutputInterface An OutputInterface instance

run() public method

Runs the current application.
public run ( Symfony\Component\Console\Input\InputInterface $input = null, Symfony\Component\Console\Output\OutputInterface $output = null ) : integer
$input Symfony\Component\Console\Input\InputInterface An Input instance
$output Symfony\Component\Console\Output\OutputInterface An Output instance
return integer 0 if everything went fine, or an error code

setAutoExit() public method

Sets whether to automatically exit after a command execution or not.
public setAutoExit ( boolean $boolean )
$boolean boolean Whether to automatically exit after a command execution or not

setCatchExceptions() public method

Sets whether to catch exceptions or not during commands execution.
public setCatchExceptions ( boolean $boolean )
$boolean boolean Whether to catch exceptions or not during commands execution

setDefaultCommand() public method

Sets the default Command name.
public setDefaultCommand ( string $commandName, boolean $isSingleCommand = false ) : self
$commandName string The Command name
$isSingleCommand boolean Set to true if there is only one command in this application
return self

setDefinition() public method

Set an input definition to be used with this application.
public setDefinition ( Symfony\Component\Console\Input\InputDefinition $definition )
$definition Symfony\Component\Console\Input\InputDefinition The input definition

setDispatcher() public method

public setDispatcher ( Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher )
$dispatcher Symfony\Component\EventDispatcher\EventDispatcherInterface

setHelperSet() public method

Set a helper set to be used with the command.
public setHelperSet ( Symfony\Component\Console\Helper\HelperSet $helperSet )
$helperSet Symfony\Component\Console\Helper\HelperSet The helper set

setName() public method

Sets the application name.
public setName ( string $name )
$name string The application name

setTerminalDimensions() public method

Can be useful to force terminal dimensions for functional tests.
Deprecation: since version 3.2, to be removed in 4.0. Set the COLUMNS and LINES env vars instead.
public setTerminalDimensions ( integer $width, integer $height ) : Application
$width integer The width
$height integer The height
return Application The current application

setVersion() public method

Sets the application version.
public setVersion ( string $version )
$version string The application version