PHP Class Symfony\Component\Console\Application

Afficher le fichier Open project: symfony/symfony Class Usage Examples

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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

Méthode 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 méthode

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

add() public méthode

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
Résultat Symfony\Component\Console\Command\Command | null The registered command if enabled or null

addCommands() public méthode

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

all() public méthode

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

areExceptionsCaught() public méthode

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

configureIO() protected méthode

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 méthode

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
Résultat integer 0 if everything went fine, or an error code

doRunCommand() protected méthode

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
Résultat integer 0 if everything went fine, or an error code

extractNamespace() public méthode

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
Résultat string The namespace of the command

find() public méthode

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
Résultat Symfony\Component\Console\Command\Command A Command instance

findNamespace() public méthode

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

get() public méthode

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

getAbbreviations() public static méthode

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

getCommandName() protected méthode

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
Résultat string The command name

getDefaultCommands() protected méthode

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

getDefaultHelperSet() protected méthode

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

getDefaultInputDefinition() protected méthode

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

getDefinition() public méthode

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

getHelp() public méthode

Gets the help message.
public getHelp ( ) : string
Résultat string A help message

getHelperSet() public méthode

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

getLongVersion() public méthode

Returns the long version of the application.
public getLongVersion ( ) : string
Résultat string The long application version

getName() public méthode

Gets the name of the application.
public getName ( ) : string
Résultat string The application name

getNamespaces() public méthode

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

getTerminalDimensions() public méthode

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
Résultat array Array containing width and height

getTerminalHeight() protected méthode

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
Résultat integer | null

getTerminalWidth() protected méthode

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
Résultat integer | null

getVersion() public méthode

Gets the application version.
public getVersion ( ) : string
Résultat string The application version

has() public méthode

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

isAutoExitEnabled() public méthode

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

register() public méthode

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

renderException() public méthode

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 méthode

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
Résultat integer 0 if everything went fine, or an error code

setAutoExit() public méthode

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 méthode

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 méthode

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
Résultat self

setDefinition() public méthode

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 méthode

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

setHelperSet() public méthode

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 méthode

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

setTerminalDimensions() public méthode

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
Résultat Application The current application

setVersion() public méthode

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