Overview

Namespaces

  • Evenement
  • None
  • Peridot
    • Console
    • Core
    • Reporter
    • Runner
    • Scope
    • Test
  • Symfony
    • Component
      • Console
        • Command
        • Descriptor
        • Event
        • Exception
        • Formatter
        • Helper
        • Input
        • Logger
        • Output
        • Question
        • Style
        • Tester
        • Tests
          • Command
          • Descriptor
          • Fixtures
          • Formatter
          • Helper
          • Input
          • Logger
          • Output
          • Style
          • Tester

Classes

  • Application
  • ConsoleEvents
  • Shell
  • Overview
  • Namespace
  • Class

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();

Direct known subclasses

Peridot\Console\Application, Symfony\Component\Console\Tests\CustomApplication, Symfony\Component\Console\Tests\CustomDefaultCommandApplication, Symfony\Component\Console\Tests\Fixtures\DescriptorApplication1, Symfony\Component\Console\Tests\Fixtures\DescriptorApplication2
Namespace: Symfony\Component\Console
Author: Fabien Potencier fabien@symfony.com
Located at Application.php
Methods summary
public
# __construct( string $name = 'UNKNOWN', string $version = 'UNKNOWN' )

Constructor.

Constructor.

Parameters

$name
The name of the application
$version
The version of the application
public
# setDispatcher( Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher )
public integer
# run( Symfony\Component\Console\Input\InputInterface $input = null, Symfony\Component\Console\Output\OutputInterface $output = null )

Runs the current application.

Runs the current application.

Parameters

$input
An Input instance
$output
An Output instance

Returns

integer
0 if everything went fine, or an error code

Throws

Exception
When doRun returns Exception
public integer
# doRun( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )

Runs the current application.

Runs the current application.

Parameters

$input
An Input instance
$output
An Output instance

Returns

integer
0 if everything went fine, or an error code
public
# setHelperSet( Symfony\Component\Console\Helper\HelperSet $helperSet )

Set a helper set to be used with the command.

Set a helper set to be used with the command.

Parameters

$helperSet
The helper set
public Symfony\Component\Console\Helper\HelperSet
# getHelperSet( )

Get the helper set associated with the command.

Get the helper set associated with the command.

Returns

Symfony\Component\Console\Helper\HelperSet
The HelperSet instance associated with this command
public
# setDefinition( Symfony\Component\Console\Input\InputDefinition $definition )

Set an input definition to be used with this application.

Set an input definition to be used with this application.

Parameters

$definition
The input definition
public Symfony\Component\Console\Input\InputDefinition
# getDefinition( )

Gets the InputDefinition related to this Application.

Gets the InputDefinition related to this Application.

Returns

Symfony\Component\Console\Input\InputDefinition
The InputDefinition instance
public string
# getHelp( )

Gets the help message.

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
Whether to catch exceptions or not during commands execution
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
Whether to automatically exit after a command execution or not
public string
# getName( )

Gets the name of the application.

Gets the name of the application.

Returns

string
The application name
public
# setName( string $name )

Sets the application name.

Sets the application name.

Parameters

$name
The application name
public string
# getVersion( )

Gets the application version.

Gets the application version.

Returns

string
The application version
public
# setVersion( string $version )

Sets the application version.

Sets the application version.

Parameters

$version
The application version
public string
# getLongVersion( )

Returns the long version of the application.

Returns the long version of the application.

Returns

string
The long application version
public Symfony\Component\Console\Command\Command
# register( string $name )

Registers a new command.

Registers a new command.

Parameters

$name
The command name

Returns

Symfony\Component\Console\Command\Command
The newly created command
public
# addCommands( array $commands )

Adds an array of command objects.

Adds an array of command objects.

If a Command is not enabled it will not be added.

Parameters

$commands
An array of commands
public Symfony\Component\Console\Command\Command|null
# add( Symfony\Component\Console\Command\Command $command )

Adds a command object.

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.

Parameters

$command
A Command object

Returns

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

Returns

Symfony\Component\Console\Command\Command
A Command object

Throws

Symfony\Component\Console\Exception\CommandNotFoundException
When command name given does not exist
public boolean
# has( string $name )

Returns true if the command exists, false otherwise.

Returns true if the command exists, false otherwise.

Parameters

$name
The command name or alias

Returns

boolean
true if the command exists, false otherwise
public string[]
# 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 return the global namespace which always exists.

Returns

string[]
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
A namespace or abbreviation to search for

Returns

string
A registered namespace

Throws

Symfony\Component\Console\Exception\CommandNotFoundException
When namespace is incorrect or ambiguous
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
A command name or a command alias

Returns

Symfony\Component\Console\Command\Command
A Command instance

Throws

Symfony\Component\Console\Exception\CommandNotFoundException
When command name is incorrect or ambiguous
public Symfony\Component\Console\Command\Command[]
# 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
A namespace name

Returns

Symfony\Component\Console\Command\Command[]
An array of Command instances
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
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.

Deprecated

since version 2.3, to be removed in 3.0.

Parameters

$namespace
An optional namespace name
$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.

Deprecated

since version 2.3, to be removed in 3.0.

Parameters

$namespace
An optional namespace name
$asDom
Whether to return a DOM or an XML string

Returns

string|DOMDocument
An XML string representing the Application
public
# renderException( Exception $e, Symfony\Component\Console\Output\OutputInterface $output )

Renders a caught exception.

Renders a caught exception.

Parameters

$e
An exception instance
$output
An OutputInterface instance
protected integer|null
# getTerminalWidth( )

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

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

Returns

integer|null
protected integer|null
# getTerminalHeight( )

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

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

Returns

integer|null
public array
# getTerminalDimensions( )

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

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

Returns

array
Array containing width and height
public Symfony\Component\Console\Application
# setTerminalDimensions( integer $width, integer $height )

Sets terminal dimensions.

Sets terminal dimensions.

Can be useful to force terminal dimensions for functional tests.

Parameters

$width
The width
$height
The height

Returns

Symfony\Component\Console\Application
The current application
protected
# 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.

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

Parameters

$input
An InputInterface instance
$output
An OutputInterface instance
protected integer
# doRunCommand( Symfony\Component\Console\Command\Command $command, Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )

Runs the current command.

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
A Command instance
$input
An Input instance
$output
An Output instance

Returns

integer
0 if everything went fine, or an error code

Throws

Exception
when the command being run threw an exception
protected string
# getCommandName( Symfony\Component\Console\Input\InputInterface $input )

Gets the name of the command based on input.

Gets the name of the command based on input.

Parameters

$input
The input interface

Returns

string
The command name
protected Symfony\Component\Console\Input\InputDefinition
# getDefaultInputDefinition( )

Gets the default input definition.

Gets the default input definition.

Returns

Symfony\Component\Console\Input\InputDefinition
An InputDefinition instance
protected Symfony\Component\Console\Command\Command[]
# getDefaultCommands( )

Gets the default commands that should always be available.

Gets the default commands that should always be available.

Returns

Symfony\Component\Console\Command\Command[]
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

Symfony\Component\Console\Helper\HelperSet
A HelperSet instance
public string
# extractNamespace( string $name, string $limit = null )

Returns the namespace part of the command name.

Returns the namespace part of the command name.

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

Parameters

$name
The full name of the command
$limit
The maximum number of parts of the namespace

Returns

string
The namespace of the command
public
# setDefaultCommand( string $commandName )

Sets the default Command name.

Sets the default Command name.

Parameters

$commandName
The Command name
Peridot API documentation generated by ApiGen