PHP Class ConsoleKit\Command

Can be used to represent a single command: class MyCommand extends Command { public function execute(array $args, array $options = array()) { $this->writeln('hello world'); } } If "execute()" is not overriden, the execution will be forwarded to subcommand methods. The subcommand name will be the first argument value and the associated method must be prefixed with "execute". class MyCommand extends Command { public function executeSub1(array $args, array $options = array()) { $this->writeln('hello world'); } public function executeSub2(array $args, array $options = array()) { $this->writeln('hello world'); } }
Afficher le fichier Open project: maximebf/consolekit Class Usage Examples

Protected Properties

Свойство Type Description
$console Console
$defaultFormatOptions array

Méthodes publiques

Méthode Description
__construct ( Console $console )
context ( array $formatOptions, Closure $closure ) Executes the closure with a {@see FormatedWriter} object as the first argument, initialized with the $formatOptions array
execute ( array $args, array $options = [] ) If not overriden, will execute the command specified as the first argument
format ( string $text, integer | array $formatOptions = [] ) : string Formats text using a {@see TextFormater}
getConsole ( ) : Console
write ( string $text, integer | array $formatOptions = [], integer $pipe = TextWriter::STDOUT ) : Command Writes some text to the text writer
writeerr ( string $text ) : Command Writes a message in bold red to STDERR
writeln ( string $text, integer | array $formatOptions = [], integer $pipe = TextWriter::STDOUT ) : Command Writes a line of text

Method Details

__construct() public méthode

public __construct ( Console $console )
$console Console

context() public méthode

$this->context(array('quote' => ' * '), function($f) { $f->writeln('quoted text'); })
public context ( array $formatOptions, Closure $closure )
$formatOptions array
$closure Closure

execute() public méthode

Commands must be defined as methods named after the command, prefixed with execute (eg. create -> executeCreate)
public execute ( array $args, array $options = [] )
$args array
$options array

format() public méthode

Formats text using a {@see TextFormater}
public format ( string $text, integer | array $formatOptions = [] ) : string
$text string
$formatOptions integer | array Either an array of options for TextFormater or a color code
Résultat string

getConsole() public méthode

public getConsole ( ) : Console
Résultat Console

write() public méthode

Writes some text to the text writer
See also: format()
public write ( string $text, integer | array $formatOptions = [], integer $pipe = TextWriter::STDOUT ) : Command
$text string
$formatOptions integer | array
$pipe integer
Résultat Command

writeerr() public méthode

Writes a message in bold red to STDERR
public writeerr ( string $text ) : Command
$text string
Résultat Command

writeln() public méthode

Writes a line of text
public writeln ( string $text, integer | array $formatOptions = [], integer $pipe = TextWriter::STDOUT ) : Command
$text string
$formatOptions integer | array
$pipe integer
Résultat Command

Property Details

$console protected_oe property

protected Console,consolekit $console
Résultat Console

$defaultFormatOptions protected_oe property

protected array $defaultFormatOptions
Résultat array