Copied!

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();
CloneableInstantiable
Methods
public __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
public add(Symfony\Component\Console\Command\Command $command) : ?Symfony\Component\Console\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.

public addCommands(array $commands) : void
 

Adds an array of command objects.

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

  • param \Command[] $commands An array of commands
public all(?string $namespace = NULL) : array
 

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

The array keys are the full names and the values the command instances.

  • return \Command[]
public areExceptionsCaught() : bool
 

Gets whether to catch exceptions or not during commands execution.

public complete(Symfony\Component\Console\Completion\CompletionInput $input, Symfony\Component\Console\Completion\CompletionSuggestions $suggestions) : void
 

Adds suggestions to $suggestions for the current completion input (e.g. option or argument).

public doRun(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output) : int
 

Runs the current application.

  • return int 0 if everything went fine, or an error code
public extractNamespace(string $name, ?int $limit = NULL) : string
 

Returns the namespace part of the command name.

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

public find(string $name) : Symfony\Component\Console\Command\Command
 

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.

  • throws \CommandNotFoundException When command name is incorrect or ambiguous
public findNamespace(string $namespace) : string
 

Finds a registered namespace by a name or an abbreviation.

  • throws \NamespaceNotFoundException When namespace is incorrect or ambiguous
public get(string $name) : Symfony\Component\Console\Command\Command
 

Returns a registered command by name or alias.

  • throws \CommandNotFoundException When given command name does not exist
public static getAbbreviations(array $names) : array
 

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

  • return string[][]
public getDefinition() : Symfony\Component\Console\Input\InputDefinition
 

Gets the InputDefinition related to this Application.

public getHelp() : string
 

Gets the help message.

public getHelperSet() : Symfony\Component\Console\Helper\HelperSet
 

Get the helper set associated with the command.

public getLongVersion() : string
 

Returns the long version of the application.

public getName() : string
 

Gets the name of the application.

public getNamespaces() : array
 

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

It does not return the global namespace which always exists.

  • return string[]
public getSignalRegistry() : Symfony\Component\Console\SignalRegistry\SignalRegistry
public getVersion() : string
 

Gets the application version.

public has(string $name) : bool
 

Returns true if the command exists, false otherwise.

public isAutoExitEnabled() : bool
 

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

public isSingleCommand() : bool
 
  • internal
public register(string $name) : Symfony\Component\Console\Command\Command
 

Registers a new command.

public renderThrowable(Throwable $e, Symfony\Component\Console\Output\OutputInterface $output) : void
public reset() : void
public run(?Symfony\Component\Console\Input\InputInterface $input = NULL, ?Symfony\Component\Console\Output\OutputInterface $output = NULL) : int
 

Runs the current application.

  • return int 0 if everything went fine, or an error code
  • throws \Exception When running fails. Bypass this when {@link setCatchExceptions()}.
public setAutoExit(bool $boolean) : void
 

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

public setCatchErrors(bool $catchErrors = true) : void
 

Sets whether to catch errors or not during commands execution.

public setCatchExceptions(bool $boolean) : void
 

Sets whether to catch exceptions or not during commands execution.

public setCommandLoader(Symfony\Component\Console\CommandLoader\CommandLoaderInterface $commandLoader) : void
public setDefaultCommand(string $commandName, bool $isSingleCommand = false) : static
 

Sets the default Command name.

  • return $this
public setDefinition(Symfony\Component\Console\Input\InputDefinition $definition) : void
public setDispatcher(Symfony\Contracts\EventDispatcher\EventDispatcherInterface $dispatcher) : void
 
  • final
public setHelperSet(Symfony\Component\Console\Helper\HelperSet $helperSet) : void
public setName(string $name) : void
 

Sets the application name.

public setSignalsToDispatchEvent(int $signalsToDispatchEvent) : void
public setVersion(string $version) : void
 

Sets the application version.

Methods
protected configureIO(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output) : void
 

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

protected doRenderThrowable(Throwable $e, Symfony\Component\Console\Output\OutputInterface $output) : void
protected doRunCommand(Symfony\Component\Console\Command\Command $command, Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output) : int
 

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.

  • return int 0 if everything went fine, or an error code
protected getCommandName(Symfony\Component\Console\Input\InputInterface $input) : ?string
 

Gets the name of the command based on input.

protected getDefaultCommands() : array
 

Gets the default commands that should always be available.

  • return \Command[]
protected getDefaultHelperSet() : Symfony\Component\Console\Helper\HelperSet
 

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

protected getDefaultInputDefinition() : Symfony\Component\Console\Input\InputDefinition
 

Gets the default input definition.

Properties
private bool $autoExit = true
private bool $catchErrors = false
private bool $catchExceptions = true
private ?Symfony\Component\Console\CommandLoader\CommandLoaderInterface $commandLoader = NULL
private array $commands = []
private string $defaultCommand
private Symfony\Component\Console\Input\InputDefinition $definition
private ?Symfony\Contracts\EventDispatcher\EventDispatcherInterface $dispatcher = NULL
private Symfony\Component\Console\Helper\HelperSet $helperSet
private bool $initialized = false
private string $name
private ?Symfony\Component\Console\Command\Command $runningCommand = NULL
private ?Symfony\Component\Console\SignalRegistry\SignalRegistry $signalRegistry = NULL
private array $signalsToDispatchEvent = []
private bool $singleCommand = false
private Symfony\Component\Console\Terminal $terminal
private string $version
private bool $wantHelps = false
Methods
private extractAllNamespaces(string $name) : array
 

Returns all namespaces of the command name.

  • return string[]
private findAlternatives(string $name, iterable $collection) : array
 

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

  • return string[]
private getAbbreviationSuggestions(array $abbrevs) : string
 

Returns abbreviated suggestions in string format.

private init() : void
private splitStringByWidth(string $string, int $width) : array
Methods
public static getAbbreviations(array $names) : array
 

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

  • return string[][]
© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration