PHP Class Webmozart\Console\Api\Config\ApplicationConfig

Since: 1.0
Author: Bernhard Schussek ([email protected])
Inheritance: extends Config
Mostrar archivo Open project: webmozart/console Class Usage Examples

Public Methods

Method Description
__construct ( string $name = null, string $version = null ) Creates a new console application.
addCommandConfig ( CommandConfig $config ) : static Adds a command configuration to the application.
addCommandConfigs ( array $configs ) : static Adds command configurations to the application.
addEventListener ( string $eventName, callable $listener, integer $priority ) : static Adds a listener for the given event name.
addEventSubscriber ( Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber ) : static Adds an event subscriber to the dispatcher.
addStyle ( Style $style ) : static Adds a style to the style set.
addStyles ( array $styles ) : static Adds multiple styles to the style set.
beginCommand ( string $name ) : CommandConfig Starts a configuration block for a command.
create ( string $name = null, string $version = null ) : static Creates a new console application.
editCommand ( string $name ) : CommandConfig Alias for {@link getCommandConfig()}.
getCommandConfig ( string $name ) : CommandConfig Returns the command configuration for a given name.
getCommandConfigs ( ) : CommandConfig[] Returns all registered command configurations.
getCommandResolver ( ) : Webmozart\Console\Api\Resolver\CommandResolver Returns the used command resolver.
getDisplayName ( ) : string Returns the application name as it is displayed in the help.
getEventDispatcher ( ) : Symfony\Component\EventDispatcher\EventDispatcherInterface Returns the event dispatcher used to dispatch the console events.
getHelp ( ) : string Returns the help text of the application.
getIOFactory ( ) : callable Returns the callable used to create {@link IO} instances.
getName ( ) : string Returns the name of the application.
getStyleSet ( ) : StyleSet Returns the configured style set.
getVersion ( ) : string Returns the version of the application.
hasCommandConfig ( string $name ) : boolean Returns whether the application has a command with a given name.
hasCommandConfigs ( ) : boolean Returns whether the application has any registered command configurations.
isDebug ( ) : boolean Returns whether the application is in debug mode.
isExceptionCaught ( ) : boolean Returns whether the application catches and displays exceptions thrown while running a command.
isTerminatedAfterRun ( ) : boolean Returns whether the PHP process is terminated after running a command.
removeEventListener ( string $eventName, callable $listener ) : static Removes an event listener for the given event name.
removeEventSubscriber ( Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber ) : static Removes an event subscriber from the dispatcher.
removeStyle ( string $tag ) : static Removes a style from the style set.
setCatchExceptions ( boolean $catch ) : static Sets whether the application catches and displays exceptions thrown while running a command.
setCommandConfigs ( array $configs ) : static Sets the command configurations of the application.
setCommandResolver ( Webmozart\Console\Api\Resolver\CommandResolver $commandResolver ) : static Sets the used command resolver.
setDebug ( boolean $debug ) : static Sets whether the application is in debug mode.
setDisplayName ( string $displayName ) : static Sets the application name as it is displayed in the help.
setEventDispatcher ( Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher = null ) : static Sets the event dispatcher for dispatching the console events.
setHelp ( string $help ) : static Sets the help text of the application.
setIOFactory ( callable $ioFactory ) : static Sets the callable used to create {@link IO} instances.
setName ( string $name ) : static Sets the name of the application.
setStyleSet ( StyleSet $styleSet ) : static Sets the used style set.
setTerminateAfterRun ( boolean $terminate ) : static Sets whether to terminate the PHP process after running a command.
setVersion ( string $version ) : static Sets the version of the application.

Protected Methods

Method Description
getDefaultDisplayName ( ) : string Returns the default display name used if no display name is set.

Method Details

__construct() public method

Creates a new console application.
public __construct ( string $name = null, string $version = null )
$name string The name of the application.
$version string The application version.

addCommandConfig() public method

Adds a command configuration to the application.
See also: beginCommand()
public addCommandConfig ( CommandConfig $config ) : static
$config CommandConfig The command configuration.
return static The current instance.

addCommandConfigs() public method

Adds command configurations to the application.
See also: beginCommand()
public addCommandConfigs ( array $configs ) : static
$configs array The command configurations.
return static The current instance.

addEventListener() public method

See {@link ConsoleEvents} for the supported event names.
See also: EventDispatcherInterface::addListener()
public addEventListener ( string $eventName, callable $listener, integer $priority ) : static
$eventName string The event to listen to.
$listener callable The callback to execute when the event is dispatched.
$priority integer The event priority.
return static The current instance.

addEventSubscriber() public method

Adds an event subscriber to the dispatcher.
See also: EventDispatcherInterface::addSubscriber()
public addEventSubscriber ( Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber ) : static
$subscriber Symfony\Component\EventDispatcher\EventSubscriberInterface The subscriber to add.
return static The current instance.

addStyle() public method

Adds a style to the style set.
See also: StyleSet::add()
public addStyle ( Style $style ) : static
$style Webmozart\Console\Api\Formatter\Style The style to add.
return static The current instance.

addStyles() public method

Adds multiple styles to the style set.
See also: StyleSet::merge()
public addStyles ( array $styles ) : static
$styles array The styles to add.
return static The current instance.

beginCommand() public method

The configuration of the command is returned by this method. You can use the fluent interface to configure the sub-command before jumping back to this configuration with {@link CommandConfig::end()}: php protected function configure() { $this ->setName('server') ->setDescription('List and manage servers') ->beginCommand('add') ->setDescription('Add a server') ->addArgument('host', Argument::REQUIRED) ->addOption('port', 'p', Option::VALUE_OPTIONAL, null, 80) ->end() ... ; }
See also: editCommand()
public beginCommand ( string $name ) : CommandConfig
$name string The name of the command.
return CommandConfig The command configuration.

create() public static method

Creates a new console application.
public static create ( string $name = null, string $version = null ) : static
$name string The name of the application.
$version string The application version.
return static The created instance.

editCommand() public method

This method can be used to nicely edit a command inherited from a parent configuration using the fluent API: php protected function configure() { parent::configure(); $this ->editCommand('add') ... ->end() ... ; }
See also: beginCommand()
public editCommand ( string $name ) : CommandConfig
$name string The name of the command to edit.
return CommandConfig The command configuration.

getCommandConfig() public method

Returns the command configuration for a given name.
See also: beginCommand()
public getCommandConfig ( string $name ) : CommandConfig
$name string The name of the command.
return CommandConfig The command configuration.

getCommandConfigs() public method

Returns all registered command configurations.
See also: beginCommand()
public getCommandConfigs ( ) : CommandConfig[]
return CommandConfig[] The command configurations.

getCommandResolver() public method

Returns the used command resolver.
See also: setCommandResolver()
public getCommandResolver ( ) : Webmozart\Console\Api\Resolver\CommandResolver
return Webmozart\Console\Api\Resolver\CommandResolver The command resolver.

getDefaultDisplayName() protected method

Returns the default display name used if no display name is set.
protected getDefaultDisplayName ( ) : string
return string The default display name.

getDisplayName() public method

If no display name is set with {@link setDisplayName()}, the humanized application name is returned.
See also: setDisplayName()
public getDisplayName ( ) : string
return string The display name.

getEventDispatcher() public method

Returns the event dispatcher used to dispatch the console events.
public getEventDispatcher ( ) : Symfony\Component\EventDispatcher\EventDispatcherInterface
return Symfony\Component\EventDispatcher\EventDispatcherInterface The event dispatcher.

getHelp() public method

Returns the help text of the application.
public getHelp ( ) : string
return string The help text.

getIOFactory() public method

Returns the callable used to create {@link IO} instances.
See also: setIOFactory()
public getIOFactory ( ) : callable
return callable The callable or `null` if none was set.

getName() public method

Returns the name of the application.
See also: setName()
public getName ( ) : string
return string The application name.

getStyleSet() public method

Returns the configured style set.
See also: setStyleSet()
public getStyleSet ( ) : StyleSet
return Webmozart\Console\Api\Formatter\StyleSet The style set.

getVersion() public method

Returns the version of the application.
public getVersion ( ) : string
return string The application version.

hasCommandConfig() public method

Returns whether the application has a command with a given name.
See also: beginCommand()
public hasCommandConfig ( string $name ) : boolean
$name string The name of the command.
return boolean Returns `true` if the command configuration with the given name exists and `false` otherwise.

hasCommandConfigs() public method

Returns whether the application has any registered command configurations.
See also: beginCommand()
public hasCommandConfigs ( ) : boolean
return boolean Returns `true` if command configurations were added to the application and `false` otherwise.

isDebug() public method

In debug mode, the verbosity is always {@link IO::DEBUG}.
See also: setDebug()
public isDebug ( ) : boolean
return boolean Returns `true` if the application is in debug mode.

isExceptionCaught() public method

Returns whether the application catches and displays exceptions thrown while running a command.
See also: setCatchExceptions()
public isExceptionCaught ( ) : boolean
return boolean Returns `true` if exceptions are caught and `false` otherwise.

isTerminatedAfterRun() public method

Returns whether the PHP process is terminated after running a command.
See also: setTerminateAfterRun()
public isTerminatedAfterRun ( ) : boolean
return boolean Returns `true` if the PHP process is terminated after {@link run()} and `false` otherwise.

removeEventListener() public method

Removes an event listener for the given event name.
See also: EventDispatcherInterface::removeListener()
public removeEventListener ( string $eventName, callable $listener ) : static
$eventName string The event name.
$listener callable The callback to remove.
return static The current instance.

removeEventSubscriber() public method

Removes an event subscriber from the dispatcher.
See also: EventDispatcherInterface::removeSubscriber()
public removeEventSubscriber ( Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber ) : static
$subscriber Symfony\Component\EventDispatcher\EventSubscriberInterface The subscriber to remove.
return static The current instance.

removeStyle() public method

Removes a style from the style set.
See also: StyleSet::remove()
public removeStyle ( string $tag ) : static
$tag string The tag of the style to remove.
return static The current instance.

setCatchExceptions() public method

Sets whether the application catches and displays exceptions thrown while running a command.
See also: isExceptionCaught()
public setCatchExceptions ( boolean $catch ) : static
$catch boolean Whether to catch and display exceptions thrown while running a command.
return static The current instance.

setCommandConfigs() public method

Sets the command configurations of the application.
See also: beginCommand()
public setCommandConfigs ( array $configs ) : static
$configs array The command configurations.
return static The current instance.

setCommandResolver() public method

Sets the used command resolver.
See also: getCommandResolver()
public setCommandResolver ( Webmozart\Console\Api\Resolver\CommandResolver $commandResolver ) : static
$commandResolver Webmozart\Console\Api\Resolver\CommandResolver The command resolver.
return static The current instance.

setDebug() public method

In debug mode, the verbosity is always {@link IO::DEBUG}.
See also: isDebug()
public setDebug ( boolean $debug ) : static
$debug boolean Set to `true` to activate the debug mode.
return static The current instance.

setDisplayName() public method

Sets the application name as it is displayed in the help.
See also: getDisplayName()
public setDisplayName ( string $displayName ) : static
$displayName string The display name.
return static The current instance.

setEventDispatcher() public method

Sets the event dispatcher for dispatching the console events.
public setEventDispatcher ( Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher = null ) : static
$dispatcher Symfony\Component\EventDispatcher\EventDispatcherInterface The event dispatcher.
return static The current instance.

setHelp() public method

Sets the help text of the application.
public setHelp ( string $help ) : static
$help string The help text.
return static The current instance.

setIOFactory() public method

The callable receives four arguments: * {@link RawArgs}: The raw console arguments. * {@link Input}: The input. * {@link Output}: The output. * {@link Output}: The error output. The input and output instances may be null if none were passed to {@link Application::run()}.
public setIOFactory ( callable $ioFactory ) : static
$ioFactory callable The {@link IO} factory callable.
return static The current instance.

setName() public method

Sets the name of the application.
See also: getName()
public setName ( string $name ) : static
$name string The application name.
return static The current instance.

setStyleSet() public method

Sets the used style set.
See also: getStyleSet()
public setStyleSet ( StyleSet $styleSet ) : static
$styleSet Webmozart\Console\Api\Formatter\StyleSet The style set to use.
return static The current instance.

setTerminateAfterRun() public method

Sets whether to terminate the PHP process after running a command.
See also: isTerminatedAfterRun()
public setTerminateAfterRun ( boolean $terminate ) : static
$terminate boolean Whether to terminate the PHP process after running a command.
return static The current instance.

setVersion() public method

Sets the version of the application.
public setVersion ( string $version ) : static
$version string The application version.
return static The current instance.