Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • Command
  • HelpCommand
  • ListCommand
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo

Class Command

Base class for all commands.

Direct known subclasses

Contrib\Bundle\CoverallsV1Bundle\Command\CoverallsV1JobsCommand, Symfony\Component\Console\Command\HelpCommand, Symfony\Component\Console\Command\ListCommand
Namespace: Symfony\Component\Console\Command
Author: Fabien Potencier <fabien@symfony.com>
Api
Located at console/Symfony/Component/Console/Command/Command.php
Methods summary
public
# __construct( string $name = null )

Constructor.

Constructor.

Parameters

$name
string
$name The name of the command

Throws

LogicException
When the command name is empty

Api

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
Symfony\Component\Console\Application
$application An Application instance

Api

public
# setHelperSet( Symfony\Component\Console\Helper\HelperSet $helperSet )

Sets the helper set.

Sets the helper set.

Parameters

$helperSet
Symfony\Component\Console\Helper\HelperSet
$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

Api

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
Symfony\Component\Console\Input\InputInterface
$input An InputInterface instance
$output
Symfony\Component\Console\Output\OutputInterface
$output An OutputInterface instance

Returns

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

Throws

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.

Parameters

$input
Symfony\Component\Console\Input\InputInterface
$input An InputInterface instance
$output
Symfony\Component\Console\Output\OutputInterface
$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
Symfony\Component\Console\Input\InputInterface
$input An InputInterface instance
$output
Symfony\Component\Console\Output\OutputInterface
$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
Symfony\Component\Console\Input\InputInterface
$input An InputInterface instance
$output
Symfony\Component\Console\Output\OutputInterface
$output An OutputInterface instance

Returns

integer
The command exit code

Throws

Exception

See

Symfony\Component\Console\Command\Command::setCode()
Symfony\Component\Console\Command\Command::execute()

Api

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
callable
$code A callable(InputInterface $input, OutputInterface $output)

Returns

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

Throws

InvalidArgumentException

See

Symfony\Component\Console\Command\Command::execute()

Api

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
array|Symfony\Component\Console\Input\InputDefinition
$definition An array of argument and option instances or a definition instance

Returns

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

Api

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

Api

protected 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.

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
string
$name The argument name
$mode
integer
$mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
$description
string
$description A description text
$default
mixed
$default The default value (for InputArgument::OPTIONAL mode only)

Returns

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

Api

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
string
$name The option name
$shortcut
string
$shortcut The shortcut (can be null)
$mode
integer
$mode The option mode: One of the InputOption::VALUE_* constants
$description
string
$description A description text
$default
mixed
$default The default value (must be null for InputOption::VALUE_REQUIRED or InputOption::VALUE_NONE)

Returns

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

Api

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
string
$name The command name

Returns

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

Throws

InvalidArgumentException
When command name given is empty

Api

public string
# getName( )

Returns the command name.

Returns the command name.

Returns

string
The command name

Api

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

Sets the description for the command.

Sets the description for the command.

Parameters

$description
string
$description The description for the command

Returns

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

Api

public string
# getDescription( )

Returns the description for the command.

Returns the description for the command.

Returns

string
The description for the command

Api

public Symfony\Component\Console\Command\Command
# setHelp( string $help )

Sets the help for the command.

Sets the help for the command.

Parameters

$help
string
$help The help for the command

Returns

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

Api

public string
# getHelp( )

Returns the help for the command.

Returns the help for the command.

Returns

string
The help for the command

Api

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( array $aliases )

Sets the aliases for the command.

Sets the aliases for the command.

Parameters

$aliases
array
$aliases An array of aliases for the command

Returns

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

Api

public array
# getAliases( )

Returns the aliases for the command.

Returns the aliases for the command.

Returns

array
An array of aliases for the command

Api

public string
# getSynopsis( )

Returns the synopsis for the command.

Returns the synopsis for the command.

Returns

string
The synopsis
public mixed
# getHelper( string $name )

Gets a helper instance by name.

Gets a helper instance by name.

Parameters

$name
string
$name The helper name

Returns

mixed
The helper value

Throws

InvalidArgumentException
if the helper is not defined

Api

public string
# asText( )

Returns a text representation of the command.

Returns a text representation of the command.

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.

Parameters

$asDom
Boolean
$asDom Whether to return a DOM or an XML string

Returns

string|DOMDocument
An XML string representing the command
php-coveralls API documentation generated by ApiGen 2.8.0