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

  • Command
  • HelpCommand
  • ListCommand
  • Overview
  • Namespace
  • Class

Class Command

Base class for all commands.

Direct known subclasses

BarBucCommand, Foo1Command, FooSubnamespaced2Command, Peridot\Console\Command, Symfony\Component\Console\Command\HelpCommand, Symfony\Component\Console\Command\ListCommand, Symfony\Component\Console\Tests\Fixtures\DescriptorCommand1, Symfony\Component\Console\Tests\Fixtures\DescriptorCommand2, TestCommand, Foo2Command, Foo3Command, Foo4Command, Foo5Command, Foo6Command, FoobarCommand, FooCommand, FooSubnamespaced1Command
Namespace: Symfony\Component\Console\Command
Author: Fabien Potencier fabien@symfony.com
Located at Command/Command.php
Methods summary
public
# __construct( string|null $name = null )

Constructor.

Constructor.

Parameters

$name
The name of the command; passing null means it must be set in configure()

Throws

Symfony\Component\Console\Exception\LogicException
When the command name is empty
public
# ignoreValidationErrors( )

Ignores validation errors.

Ignores validation errors.

This is mainly useful for the help command.

public
# setApplication( Symfony\Component\Console\Application $application = null )

Sets the application instance for this command.

Sets the application instance for this command.

Parameters

$application
An Application instance
public
# setHelperSet( Symfony\Component\Console\Helper\HelperSet $helperSet )

Sets the helper set.

Sets the helper set.

Parameters

$helperSet
A HelperSet instance
public Symfony\Component\Console\Helper\HelperSet
# getHelperSet( )

Gets the helper set.

Gets the helper set.

Returns

Symfony\Component\Console\Helper\HelperSet
A HelperSet instance
public Symfony\Component\Console\Application
# getApplication( )

Gets the application instance for this command.

Gets the application instance for this command.

Returns

Symfony\Component\Console\Application
An Application instance
public boolean
# isEnabled( )

Checks whether the command is enabled or not in the current environment.

Checks whether the command is enabled or not in the current environment.

Override this to check for x or y and return false if the command can not run properly under the current conditions.

Returns

boolean
protected
# configure( )

Configures the current command.

Configures the current command.

protected null|integer
# execute( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )

Executes the current command.

Executes the current command.

This method is not abstract because you can use this class as a concrete class. In this case, instead of defining the execute() method, you set the code to execute by passing a Closure to the setCode() method.

Parameters

$input
An InputInterface instance
$output
An OutputInterface instance

Returns

null|integer
null or 0 if everything went fine, or an error code

Throws

Symfony\Component\Console\Exception\LogicException
When this abstract method is not implemented

See

Symfony\Component\Console\Command\Command::setCode()
protected
# interact( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )

Interacts with the user.

Interacts with the user.

This method is executed before the InputDefinition is validated. This means that this is the only place where the command can interactively ask for values of missing required arguments.

Parameters

$input
An InputInterface instance
$output
An OutputInterface instance
protected
# initialize( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )

Initializes the command just after the input has been validated.

Initializes the command just after the input has been validated.

This is mainly useful when a lot of commands extends one main command where some things need to be initialized based on the input arguments and options.

Parameters

$input
An InputInterface instance
$output
An OutputInterface instance
public integer
# run( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )

Runs the command.

Runs the command.

The code to execute is either defined directly with the setCode() method or by overriding the execute() method in a sub-class.

Parameters

$input
An InputInterface instance
$output
An OutputInterface instance

Returns

integer
The command exit code

See

Symfony\Component\Console\Command\Command::setCode()
Symfony\Component\Console\Command\Command::execute()
public Symfony\Component\Console\Command\Command
# setCode( callable $code )

Sets the code to execute when running this command.

Sets the code to execute when running this command.

If this method is used, it overrides the code defined in the execute() method.

Parameters

$code
A callable(InputInterface $input, OutputInterface $output)

Returns

Symfony\Component\Console\Command\Command
The current instance

Throws

Symfony\Component\Console\Exception\InvalidArgumentException

See

Symfony\Component\Console\Command\Command::execute()
public
# mergeApplicationDefinition( boolean $mergeArgs = true )

Merges the application definition with the command definition.

Merges the application definition with the command definition.

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

Parameters

$mergeArgs
Whether to merge or not the Application definition arguments to Command definition arguments
public Symfony\Component\Console\Command\Command
# setDefinition( array|Symfony\Component\Console\Input\InputDefinition $definition )

Sets an array of argument and option instances.

Sets an array of argument and option instances.

Parameters

$definition
An array of argument and option instances or a definition instance

Returns

Symfony\Component\Console\Command\Command
The current instance
public Symfony\Component\Console\Input\InputDefinition
# getDefinition( )

Gets the InputDefinition attached to this Command.

Gets the InputDefinition attached to this Command.

Returns

Symfony\Component\Console\Input\InputDefinition
An InputDefinition instance
public Symfony\Component\Console\Input\InputDefinition
# getNativeDefinition( )

Gets the InputDefinition to be used to create XML and Text representations of this Command.

Gets the InputDefinition to be used to create XML and Text representations of this Command.

Can be overridden to provide the original command representation when it would otherwise be changed by merging with the application InputDefinition.

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

Returns

Symfony\Component\Console\Input\InputDefinition
An InputDefinition instance
public Symfony\Component\Console\Command\Command
# addArgument( string $name, integer $mode = null, string $description = '', mixed $default = null )

Adds an argument.

Adds an argument.

Parameters

$name
The argument name
$mode
The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
$description
A description text
$default
The default value (for InputArgument::OPTIONAL mode only)

Returns

Symfony\Component\Console\Command\Command
The current instance
public Symfony\Component\Console\Command\Command
# addOption( string $name, string $shortcut = null, integer $mode = null, string $description = '', mixed $default = null )

Adds an option.

Adds an option.

Parameters

$name
The option name
$shortcut
The shortcut (can be null)
$mode
The option mode: One of the InputOption::VALUE_* constants
$description
A description text
$default
The default value (must be null for InputOption::VALUE_NONE)

Returns

Symfony\Component\Console\Command\Command
The current instance
public Symfony\Component\Console\Command\Command
# setName( string $name )

Sets the name of the command.

Sets the name of the command.

This method can set both the namespace and the name if you separate them by a colon (:) $command->setName('foo:bar');

Parameters

$name
The command name

Returns

Symfony\Component\Console\Command\Command
The current instance

Throws

Symfony\Component\Console\Exception\InvalidArgumentException
When the name is invalid
public Symfony\Component\Console\Command\Command
# setProcessTitle( string $title )

Sets the process title of the command.

Sets the process title of the command.

This feature should be used only when creating a long process command, like a daemon.

PHP 5.5+ or the proctitle PECL library is required

Parameters

$title
The process title

Returns

Symfony\Component\Console\Command\Command
The current instance
public string
# getName( )

Returns the command name.

Returns the command name.

Returns

string
The command name
public Symfony\Component\Console\Command\Command
# setDescription( string $description )

Sets the description for the command.

Sets the description for the command.

Parameters

$description
The description for the command

Returns

Symfony\Component\Console\Command\Command
The current instance
public string
# getDescription( )

Returns the description for the command.

Returns the description for the command.

Returns

string
The description for the command
public Symfony\Component\Console\Command\Command
# setHelp( string $help )

Sets the help for the command.

Sets the help for the command.

Parameters

$help
The help for the command

Returns

Symfony\Component\Console\Command\Command
The current instance
public string
# getHelp( )

Returns the help for the command.

Returns the help for the command.

Returns

string
The help for the command
public string
# getProcessedHelp( )

Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.

Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.

Returns

string
The processed help for the command
public Symfony\Component\Console\Command\Command
# setAliases( string[] $aliases )

Sets the aliases for the command.

Sets the aliases for the command.

Parameters

$aliases
An array of aliases for the command

Returns

Symfony\Component\Console\Command\Command
The current instance

Throws

Symfony\Component\Console\Exception\InvalidArgumentException
When an alias is invalid
public array
# getAliases( )

Returns the aliases for the command.

Returns the aliases for the command.

Returns

array
An array of aliases for the command
public string
# getSynopsis( boolean $short = false )

Returns the synopsis for the command.

Returns the synopsis for the command.

Parameters

$short
Whether to show the short version of the synopsis (with options folded) or not

Returns

string
The synopsis
public Symfony\Component\Console\Command\Command
# addUsage( string $usage )

Add a command usage example.

Add a command usage example.

Parameters

$usage
The usage, it'll be prefixed with the command name

Returns

Symfony\Component\Console\Command\Command
The current instance
public array
# getUsages( )

Returns alternative usages of the command.

Returns alternative usages of the command.

Returns

array
public mixed
# getHelper( string $name )

Gets a helper instance by name.

Gets a helper instance by name.

Parameters

$name
The helper name

Returns

mixed
The helper value

Throws

Symfony\Component\Console\Exception\LogicException
if no HelperSet is defined
Symfony\Component\Console\Exception\InvalidArgumentException
if the helper is not defined
public string
# asText( )

Returns a text representation of the command.

Returns a text representation of the command.

Deprecated

since version 2.3, to be removed in 3.0.

Returns

string
A string representing the command
public string|DOMDocument
# asXml( boolean $asDom = false )

Returns an XML representation of the command.

Returns an XML representation of the command.

Deprecated

since version 2.3, to be removed in 3.0.

Parameters

$asDom
Whether to return a DOM or an XML string

Returns

string|DOMDocument
An XML string representing the command
Peridot API documentation generated by ApiGen