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'); } }
Show file Open project: maximebf/consolekit Class Usage Examples

Protected Properties

Property Type Description
$console Console
$defaultFormatOptions array

Public Methods

Method 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 method

public __construct ( Console $console )
$console Console

context() public method

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

execute() public method

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 method

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
return string

getConsole() public method

public getConsole ( ) : Console
return Console

write() public method

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
return Command

writeerr() public method

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

writeln() public method

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

Property Details

$console protected property

protected Console,consolekit $console
return Console

$defaultFormatOptions protected property

protected array $defaultFormatOptions
return array