PHP Класс 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'); } }
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$console Console
$defaultFormatOptions array

Открытые методы

Метод Описание
__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

Описание методов

__construct() публичный Метод

public __construct ( Console $console )
$console Console

context() публичный Метод

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

execute() публичный Метод

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() публичный Метод

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
Результат string

getConsole() публичный Метод

public getConsole ( ) : Console
Результат Console

write() публичный Метод

Writes some text to the text writer
См. также: format()
public write ( string $text, integer | array $formatOptions = [], integer $pipe = TextWriter::STDOUT ) : Command
$text string
$formatOptions integer | array
$pipe integer
Результат Command

writeerr() публичный Метод

Writes a message in bold red to STDERR
public writeerr ( string $text ) : Command
$text string
Результат Command

writeln() публичный Метод

Writes a line of text
public writeln ( string $text, integer | array $formatOptions = [], integer $pipe = TextWriter::STDOUT ) : Command
$text string
$formatOptions integer | array
$pipe integer
Результат Command

Описание свойств

$console защищенное свойство

protected Console,consolekit $console
Результат Console

$defaultFormatOptions защищенное свойство

protected array $defaultFormatOptions
Результат array