TYPO3  7.6
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Application Class Reference
Inheritance diagram for Application:
CustomApplication CustomDefaultCommandApplication DescriptorApplication1 DescriptorApplication2

Public Member Functions

 __construct ($name= 'UNKNOWN', $version= 'UNKNOWN')
 
 setDispatcher (EventDispatcherInterface $dispatcher)
 
 run (InputInterface $input=null, OutputInterface $output=null)
 
 doRun (InputInterface $input, OutputInterface $output)
 
 setHelperSet (HelperSet $helperSet)
 
 getHelperSet ()
 
 setDefinition (InputDefinition $definition)
 
 getDefinition ()
 
 getHelp ()
 
 setCatchExceptions ($boolean)
 
 setAutoExit ($boolean)
 
 getName ()
 
 setName ($name)
 
 getVersion ()
 
 setVersion ($version)
 
 getLongVersion ()
 
 register ($name)
 
 addCommands (array $commands)
 
 add (Command $command)
 
 get ($name)
 
 has ($name)
 
 getNamespaces ()
 
 findNamespace ($namespace)
 
 find ($name)
 
 all ($namespace=null)
 
 asText ($namespace=null, $raw=false)
 
 asXml ($namespace=null, $asDom=false)
 
 renderException ($e, $output)
 
 getTerminalDimensions ()
 
 setTerminalDimensions ($width, $height)
 
 extractNamespace ($name, $limit=null)
 
 setDefaultCommand ($commandName)
 

Static Public Member Functions

static getAbbreviations ($names)
 

Protected Member Functions

 getTerminalWidth ()
 
 getTerminalHeight ()
 
 configureIO (InputInterface $input, OutputInterface $output)
 
 doRunCommand (Command $command, InputInterface $input, OutputInterface $output)
 
 getCommandName (InputInterface $input)
 
 getDefaultInputDefinition ()
 
 getDefaultCommands ()
 
 getDefaultHelperSet ()
 

Private Member Functions

 getSttyColumns ()
 
 getConsoleMode ()
 
 getAbbreviationSuggestions ($abbrevs)
 
 findAlternatives ($name, $collection)
 
 stringWidth ($string)
 
 splitStringByWidth ($string, $width)
 
 extractAllNamespaces ($name)
 

Private Attributes

 $commands = array()
 
 $wantHelps = false
 
 $runningCommand
 
 $name
 
 $version
 
 $catchExceptions = true
 
 $autoExit = true
 
 $definition
 
 $helperSet
 
 $dispatcher
 
 $terminalDimensions
 
 $defaultCommand
 

Detailed Description

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();
Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 60 of file vendor/symfony/console/Application.php.

Constructor & Destructor Documentation

__construct (   $name = 'UNKNOWN',
  $version = 'UNKNOWN' 
)

Constructor.

Parameters
string$nameThe name of the application
string$versionThe version of the application

Definition at line 83 of file vendor/symfony/console/Application.php.

References Application\$name, Application\$version, Application\add(), Application\getDefaultCommands(), Application\getDefaultHelperSet(), and Application\getDefaultInputDefinition().

Member Function Documentation

add ( Command  $command)

Adds a command object.

If a command with the same name already exists, it will be overridden.

Parameters
Command$commandA Command object
Returns
Command The registered command

Definition at line 384 of file vendor/symfony/console/Application.php.

References Command\getAliases(), Command\getDefinition(), Command\getName(), Command\isEnabled(), and Command\setApplication().

Referenced by DescriptorApplication2\__construct(), Application\__construct(), CustomDefaultCommandApplication\__construct(), Application\addCommands(), and Application\register().

addCommands ( array  $commands)

Adds an array of command objects.

Parameters
Command[]$commands An array of commands

Definition at line 366 of file vendor/symfony/console/Application.php.

References Application\add().

all (   $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.

Parameters
string$namespaceA namespace name
Returns
Command[] An array of Command instances

Definition at line 583 of file vendor/symfony/console/Application.php.

References Application\$commands, Application\$name, and Application\extractNamespace().

Referenced by ApplicationTest\ensureStaticCommandHelp(), and AbstractDescriptorTest\testDescribeApplication().

asText (   $namespace = null,
  $raw = false 
)

Returns a text representation of the Application.

Parameters
string$namespaceAn optional namespace name
bool$rawWhether to return raw command list
Returns
string A string representing the Application
Deprecated:
since version 2.3, to be removed in 3.0.

Definition at line 629 of file vendor/symfony/console/Application.php.

References OutputInterface\VERBOSITY_NORMAL.

asXml (   $namespace = null,
  $asDom = false 
)

Returns an XML representation of the Application.

Parameters
string$namespaceAn optional namespace name
bool$asDomWhether to return a DOM or an XML string
Returns
string| An XML string representing the Application
Deprecated:
since version 2.3, to be removed in 3.0.

Definition at line 650 of file vendor/symfony/console/Application.php.

configureIO ( InputInterface  $input,
OutputInterface  $output 
)
protected

Configures the input and output instances based on the user arguments and options.

Parameters
InputInterface$inputAn InputInterface instance
OutputInterface$outputAn OutputInterface instance

Definition at line 825 of file vendor/symfony/console/Application.php.

References elseif, Application\getHelperSet(), InputInterface\getParameterOption(), Application\has(), InputInterface\hasParameterOption(), OutputInterface\setDecorated(), InputInterface\setInteractive(), OutputInterface\setVerbosity(), OutputInterface\VERBOSITY_DEBUG, OutputInterface\VERBOSITY_QUIET, OutputInterface\VERBOSITY_VERBOSE, and OutputInterface\VERBOSITY_VERY_VERBOSE.

Referenced by Application\run().

doRun ( InputInterface  $input,
OutputInterface  $output 
)

Runs the current application.

Parameters
InputInterface$inputAn Input instance
OutputInterface$outputAn Output instance
Returns
int 0 if everything went fine, or an error code

Definition at line 168 of file vendor/symfony/console/Application.php.

References Application\$defaultCommand, Application\$name, Application\doRunCommand(), Application\find(), Application\getCommandName(), Application\getLongVersion(), InputInterface\hasParameterOption(), and OutputInterface\writeln().

Referenced by Application\run().

doRunCommand ( Command  $command,
InputInterface  $input,
OutputInterface  $output 
)
protected

Runs the current command.

If an event dispatcher has been attached to the application, events are also dispatched during the life-cycle of the command.

Parameters
Command$commandA Command instance
InputInterface$inputAn Input instance
OutputInterface$outputAn Output instance
Returns
int 0 if everything went fine, or an error code
Exceptions
\Exceptionwhen the command being run threw an exception

Definition at line 869 of file vendor/symfony/console/Application.php.

References ConsoleEvents\COMMAND, ConsoleEvents\EXCEPTION, ConsoleExceptionEvent\getException(), Command\getHelperSet(), ConsoleCommandEvent\RETURN_CODE_DISABLED, Command\run(), and ConsoleEvents\TERMINATE.

Referenced by Application\doRun().

extractAllNamespaces (   $name)
private

Returns all namespaces of the command name.

Parameters
string$nameThe full name of the command
Returns
array The namespaces of the command

Definition at line 1161 of file vendor/symfony/console/Application.php.

References Application\$name.

Referenced by Application\getNamespaces().

extractNamespace (   $name,
  $limit = null 
)

Returns the namespace part of the command name.

This method is not part of public API and should not be used directly.

Parameters
string$nameThe full name of the command
string$limitThe maximum number of parts of the namespace
Returns
string The namespace of the command

Definition at line 1036 of file vendor/symfony/console/Application.php.

References Application\$name.

Referenced by Application\all().

find (   $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.

Parameters
string$nameA command name or a command alias
Returns
Command A Command instance
Exceptions
\InvalidArgumentExceptionWhen command name is incorrect or ambiguous

Definition at line 526 of file vendor/symfony/console/Application.php.

References Application\$commands, Application\$name, Application\findAlternatives(), Application\findNamespace(), and Application\getAbbreviationSuggestions().

Referenced by Application\doRun().

findAlternatives (   $name,
  $collection 
)
private

Finds alternative of $name among $collection, if nothing is found in $collection, try in $abbrevs.

Parameters
string$nameThe string
array | \Traversable$collectionThe collection
Returns
array A sorted array of similar string

Definition at line 1053 of file vendor/symfony/console/Application.php.

References Application\$name, and elseif.

Referenced by Application\find(), and Application\findNamespace().

findNamespace (   $namespace)

Finds a registered namespace by a name or an abbreviation.

Parameters
string$namespaceA namespace or abbreviation to search for
Returns
string A registered namespace
Exceptions
\InvalidArgumentExceptionWhen namespace is incorrect or ambiguous

Definition at line 482 of file vendor/symfony/console/Application.php.

References Application\findAlternatives(), Application\getAbbreviationSuggestions(), and Application\getNamespaces().

Referenced by Application\find().

get (   $name)

Returns a registered command by name or alias.

Parameters
string$nameThe command name or alias
Returns
Command A Command object
Exceptions
\InvalidArgumentExceptionWhen command name given does not exist

Definition at line 418 of file vendor/symfony/console/Application.php.

References Application\$name.

static getAbbreviations (   $names)
static

Returns an array of possible abbreviations given a set of names.

Parameters
array$namesAn array of names
Returns
array An array of abbreviations

Definition at line 606 of file vendor/symfony/console/Application.php.

References Application\$name.

getAbbreviationSuggestions (   $abbrevs)
private

Returns abbreviated suggestions in string format.

Parameters
array$abbrevsAbbreviated suggestions to convert
Returns
string A formatted string of abbreviated suggestions

Definition at line 1021 of file vendor/symfony/console/Application.php.

Referenced by Application\find(), and Application\findNamespace().

getCommandName ( InputInterface  $input)
protected

Gets the name of the command based on input.

Parameters
InputInterface$inputThe input interface
Returns
string The command name

Definition at line 913 of file vendor/symfony/console/Application.php.

References InputInterface\getFirstArgument().

Referenced by Application\doRun().

getConsoleMode ( )
private

Runs and parses mode CON if it's available, suppressing any error output.

Returns
string <width>x<height> or null if it could not be parsed

Definition at line 994 of file vendor/symfony/console/Application.php.

Referenced by Application\getTerminalDimensions().

getDefaultCommands ( )
protected

Gets the default commands that should always be available.

Returns
Command[] An array of default Command instances

Definition at line 943 of file vendor/symfony/console/Application.php.

Referenced by Application\__construct().

getDefaultHelperSet ( )
protected

Gets the default helper set with the helpers that should always be available.

Returns
HelperSet A HelperSet instance

Definition at line 953 of file vendor/symfony/console/Application.php.

Referenced by Application\__construct().

getDefaultInputDefinition ( )
protected

Gets the default input definition.

Returns
InputDefinition An InputDefinition instance

Definition at line 923 of file vendor/symfony/console/Application.php.

References InputArgument\REQUIRED, and InputOption\VALUE_NONE.

Referenced by Application\__construct().

getDefinition ( )

Gets the InputDefinition related to this Application.

Returns
InputDefinition The InputDefinition instance

Definition at line 242 of file vendor/symfony/console/Application.php.

References Application\$definition.

Referenced by TextDescriptor\describeApplication().

getHelp ( )

Gets the help message.

Returns
string A help message.

Definition at line 252 of file vendor/symfony/console/Application.php.

References Application\getLongVersion().

Referenced by TextDescriptor\describeApplication().

getHelperSet ( )

Get the helper set associated with the command.

Returns
HelperSet The HelperSet instance associated with this command

Definition at line 220 of file vendor/symfony/console/Application.php.

References Application\$helperSet.

Referenced by Application\configureIO().

getLongVersion ( )

Returns the long version of the application.

Returns
string The long application version

Definition at line 336 of file vendor/symfony/console/Application.php.

References Application\getName(), and Application\getVersion().

Referenced by Application\doRun(), and Application\getHelp().

getName ( )
getNamespaces ( )

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

Definition at line 459 of file vendor/symfony/console/Application.php.

References Application\extractAllNamespaces().

Referenced by Application\findNamespace().

getSttyColumns ( )
private

Runs and parses stty -a if it's available, suppressing any error output.

Returns
string

Definition at line 971 of file vendor/symfony/console/Application.php.

Referenced by Application\getTerminalDimensions().

getTerminalDimensions ( )

Tries to figure out the terminal dimensions based on the current environment.

Returns
array Array containing width and height

Definition at line 771 of file vendor/symfony/console/Application.php.

References Application\$terminalDimensions, Application\getConsoleMode(), and Application\getSttyColumns().

Referenced by Application\getTerminalHeight(), and Application\getTerminalWidth().

getTerminalHeight ( )
protected

Tries to figure out the terminal height in which this application runs.

Returns
int|null

Definition at line 759 of file vendor/symfony/console/Application.php.

References Application\getTerminalDimensions().

getTerminalWidth ( )
protected

Tries to figure out the terminal width in which this application runs.

Returns
int|null

Definition at line 747 of file vendor/symfony/console/Application.php.

References Application\getTerminalDimensions().

Referenced by Application\renderException().

getVersion ( )

Gets the application version.

Returns
string The application version

Definition at line 312 of file vendor/symfony/console/Application.php.

References Application\$version.

Referenced by XmlDescriptor\getApplicationDocument(), and Application\getLongVersion().

has (   $name)

Returns true if the command exists, false otherwise.

Parameters
string$nameThe command name or alias
Returns
bool true if the command exists, false otherwise

Definition at line 447 of file vendor/symfony/console/Application.php.

References Application\$name.

Referenced by Application\configureIO().

register (   $name)

Registers a new command.

Parameters
string$nameThe command name
Returns
Command The newly created command

Definition at line 354 of file vendor/symfony/console/Application.php.

References Application\$name, and Application\add().

renderException (   $e,
  $output 
)

Renders a caught exception.

Parameters
\Exception$eAn exception instance
OutputInterface$outputAn OutputInterface instance

Definition at line 672 of file vendor/symfony/console/Application.php.

References Application\getName(), Application\getTerminalWidth(), OutputInterface\OUTPUT_RAW, Application\splitStringByWidth(), and Application\stringWidth().

Referenced by Application\run().

run ( InputInterface  $input = null,
OutputInterface  $output = null 
)

Runs the current application.

Parameters
InputInterface$inputAn Input instance
OutputInterface$outputAn Output instance
Returns
int 0 if everything went fine, or an error code
Exceptions
\ExceptionWhen doRun returns Exception

Definition at line 113 of file vendor/symfony/console/Application.php.

References Application\configureIO(), Application\doRun(), and Application\renderException().

setAutoExit (   $boolean)

Sets whether to automatically exit after a command execution or not.

Parameters
bool$booleanWhether to automatically exit after a command execution or not

Definition at line 276 of file vendor/symfony/console/Application.php.

setCatchExceptions (   $boolean)

Sets whether to catch exceptions or not during commands execution.

Parameters
bool$booleanWhether to catch exceptions or not during commands execution

Definition at line 264 of file vendor/symfony/console/Application.php.

setDefaultCommand (   $commandName)

Sets the default Command name.

Parameters
string$commandNameThe Command name

Definition at line 1100 of file vendor/symfony/console/Application.php.

Referenced by CustomDefaultCommandApplication\__construct().

setDefinition ( InputDefinition  $definition)

Set an input definition set to be used with this application.

Parameters
InputDefinition$definitionThe input definition

Definition at line 232 of file vendor/symfony/console/Application.php.

References Application\$definition.

setDispatcher ( EventDispatcherInterface  $dispatcher)

Definition at line 96 of file vendor/symfony/console/Application.php.

References Application\$dispatcher.

setHelperSet ( HelperSet  $helperSet)

Set a helper set to be used with the command.

Parameters
HelperSet$helperSetThe helper set

Definition at line 208 of file vendor/symfony/console/Application.php.

References Application\$helperSet.

setName (   $name)

Sets the application name.

Parameters
string$nameThe application name

Definition at line 300 of file vendor/symfony/console/Application.php.

References Application\$name.

setTerminalDimensions (   $width,
  $height 
)

Sets terminal dimensions.

Can be useful to force terminal dimensions for functional tests.

Parameters
int$widthThe width
int$heightThe height
Returns
Application The current application

Definition at line 812 of file vendor/symfony/console/Application.php.

setVersion (   $version)

Sets the application version.

Parameters
string$versionThe application version

Definition at line 324 of file vendor/symfony/console/Application.php.

References Application\$version.

splitStringByWidth (   $string,
  $width 
)
private
stringWidth (   $string)
private

Member Data Documentation

$autoExit = true
private

Definition at line 68 of file vendor/symfony/console/Application.php.

$catchExceptions = true
private

Definition at line 67 of file vendor/symfony/console/Application.php.

$commands = array()
private

Definition at line 62 of file vendor/symfony/console/Application.php.

Referenced by Application\all(), and Application\find().

$defaultCommand
private

Definition at line 73 of file vendor/symfony/console/Application.php.

Referenced by Application\doRun().

$definition
private
$dispatcher
private

Definition at line 71 of file vendor/symfony/console/Application.php.

Referenced by Application\setDispatcher().

$helperSet
private
$name
private
$runningCommand
private

Definition at line 64 of file vendor/symfony/console/Application.php.

$terminalDimensions
private
$version
private
$wantHelps = false
private

Definition at line 63 of file vendor/symfony/console/Application.php.