Application

class Application extends Application

Methods

__construct(KernelInterface $kernel)
setDispatcher(EventDispatcherInterface $dispatcher) from Application
int run(InputInterface $input = null, OutputInterface $output = null)

Runs the current application.

from Application
int doRun(InputInterface $input, OutputInterface $output)

Runs the current application.

setHelperSet(HelperSet $helperSet) from Application
HelperSet getHelperSet()

Get the helper set associated with the command.

from Application
setDefinition(InputDefinition $definition) from Application
InputDefinition getDefinition()

Gets the InputDefinition related to this Application.

from Application
string getHelp()

Gets the help message.

from Application
setCatchExceptions(bool $boolean)

Sets whether to catch exceptions or not during commands execution.

from Application
setAutoExit(bool $boolean)

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

from Application
string getName()

Gets the name of the application.

from Application
setName(string $name)

Sets the application name.

from Application
string getVersion()

Gets the application version.

from Application
setVersion(string $version)

Sets the application version.

from Application
string getLongVersion()

Returns the long version of the application.

from Application
Command register(string $name)

Registers a new command.

from Application
addCommands(array $commands)

Adds an array of command objects.

from Application
Command|null add(Command $command)

Adds a command object.

Command get(string $name)

Returns a registered command by name or alias.

bool has(string $name)

Returns true if the command exists, false otherwise.

from Application
string[] getNamespaces()

Returns an array of all unique namespaces used by currently registered commands.

from Application
string findNamespace(string $namespace)

Finds a registered namespace by a name or an abbreviation.

from Application
Command find(string $name)

Finds a command by name or alias.

Command[] all(string $namespace = null)

Gets the commands (registered in the given namespace if provided).

static array getAbbreviations(array $names)

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

from Application
string asText(string $namespace = null, bool $raw = false) deprecated

Returns a text representation of the Application.

from Application
string|DOMDocument asXml(string $namespace = null, bool $asDom = false) deprecated

Returns an XML representation of the Application.

from Application
renderException($e, $output)

Renders a caught exception.

from Application
array getTerminalDimensions()

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

from Application
$this setTerminalDimensions(int $width, int $height)

Sets terminal dimensions.

from Application
string extractNamespace(string $name, string $limit = null)

Returns the namespace part of the command name.

from Application
setDefaultCommand(string $commandName)

Sets the default Command name.

from Application
KernelInterface getKernel()

Gets the Kernel associated with this Console.

Details

__construct(KernelInterface $kernel)

Parameters

KernelInterface $kernel

setDispatcher(EventDispatcherInterface $dispatcher)

Parameters

EventDispatcherInterface $dispatcher

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

Runs the current application.

Parameters

InputInterface $input
OutputInterface $output

Return Value

int 0 if everything went fine, or an error code

Exceptions

Exception When running fails. Bypass this when {@link setCatchExceptions()}.

int doRun(InputInterface $input, OutputInterface $output)

Runs the current application.

Parameters

InputInterface $input
OutputInterface $output

Return Value

int 0 if everything went fine, or an error code

setHelperSet(HelperSet $helperSet)

Parameters

HelperSet $helperSet

HelperSet getHelperSet()

Get the helper set associated with the command.

Return Value

HelperSet The HelperSet instance associated with this command

setDefinition(InputDefinition $definition)

Parameters

InputDefinition $definition

InputDefinition getDefinition()

Gets the InputDefinition related to this Application.

Return Value

InputDefinition The InputDefinition instance

string getHelp()

Gets the help message.

Return Value

string A help message

setCatchExceptions(bool $boolean)

Sets whether to catch exceptions or not during commands execution.

Parameters

bool $boolean Whether to catch exceptions or not during commands execution

setAutoExit(bool $boolean)

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

Parameters

bool $boolean Whether to automatically exit after a command execution or not

string getName()

Gets the name of the application.

Return Value

string The application name

setName(string $name)

Sets the application name.

Parameters

string $name The application name

string getVersion()

Gets the application version.

Return Value

string The application version

setVersion(string $version)

Sets the application version.

Parameters

string $version The application version

string getLongVersion()

Returns the long version of the application.

Return Value

string The long application version

Command register(string $name)

Registers a new command.

Parameters

string $name The command name

Return Value

Command The newly created command

addCommands(array $commands)

Adds an array of command objects.

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

Parameters

array $commands An array of commands

Command|null add(Command $command)

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 $command

Return Value

Command|null The registered command if enabled or null

Command get(string $name)

Returns a registered command by name or alias.

Parameters

string $name The command name or alias

Return Value

Command A Command object

Exceptions

InvalidArgumentException When given command name does not exist

bool has(string $name)

Returns true if the command exists, false otherwise.

Parameters

string $name The command name or alias

Return Value

bool true if the command exists, false otherwise

string[] getNamespaces()

Returns an array of all unique namespaces used by currently registered commands.

It does not return the global namespace which always exists.

Return Value

string[] An array of namespaces

string findNamespace(string $namespace)

Finds a registered namespace by a name or an abbreviation.

Parameters

string $namespace A namespace or abbreviation to search for

Return Value

string A registered namespace

Exceptions

InvalidArgumentException When namespace is incorrect or ambiguous

Command find(string $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 $name A command name or a command alias

Return Value

Command A Command instance

Exceptions

InvalidArgumentException When command name is incorrect or ambiguous

Command[] all(string $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 $namespace A namespace name

Return Value

Command[] An array of Command instances

static array getAbbreviations(array $names)

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

Parameters

array $names An array of names

Return Value

array An array of abbreviations

string asText(string $namespace = null, bool $raw = false) deprecated

deprecated

since version 2.3, to be removed in 3.0.

Returns a text representation of the Application.

Parameters

string $namespace An optional namespace name
bool $raw Whether to return raw command list

Return Value

string A string representing the Application

string|DOMDocument asXml(string $namespace = null, bool $asDom = false) deprecated

deprecated

since version 2.3, to be removed in 3.0.

Returns an XML representation of the Application.

Parameters

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

Return Value

string|DOMDocument An XML string representing the Application

renderException($e, $output)

Renders a caught exception.

Parameters

$e
$output

array getTerminalDimensions()

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

Return Value

array Array containing width and height

$this setTerminalDimensions(int $width, int $height)

Sets terminal dimensions.

Can be useful to force terminal dimensions for functional tests.

Parameters

int $width The width
int $height The height

Return Value

$this

string extractNamespace(string $name, string $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 $name The full name of the command
string $limit The maximum number of parts of the namespace

Return Value

string The namespace of the command

setDefaultCommand(string $commandName)

Sets the default Command name.

Parameters

string $commandName The Command name

KernelInterface getKernel()

Gets the Kernel associated with this Console.

Return Value

KernelInterface A KernelInterface instance

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.7/Symfony/Bundle/FrameworkBundle/Console/Application.html