PHP Class ConsoleKit\Console

Inheritance: implements consolekit\TextWriter
Show file Open project: maximebf/consolekit Class Usage Examples

Protected Properties

Property Type Description
$commands array
$defaultCommand string
$exitOnException boolean
$helpCommand string
$helpCommandClass string
$optionsParser consolekit\OptionsParser
$singleCommand boolean
$textWriter consolekit\TextWriter
$verboseException boolean

Public Methods

Method Description
__construct ( array $commands = [], consolekit\OptionsParser $parser = null, consolekit\TextWriter $writer = null )
addCommand ( callback $callback, string $alias = null, boolean $default = false ) : Console Registers a command
addCommands ( array $commands ) : Console Adds multiple commands at once
addCommandsFromDir ( string $dir, string $namespace = '', boolean $includeFiles = false ) : Console Registers commands from a directory
areExceptionsVerbose ( ) : boolean
execute ( string $command = null, array $args = [], array $options = [] ) : mixed Executes a command
exitsOnException ( ) : boolean
getCommand ( string $name ) : string
getCommands ( ) : array
getDefaultCommand ( ) : string
getOptionsParser ( ) : consolekit\OptionsParser
getTextWriter ( ) : consolekit\TextWriter
hasCommand ( string $name ) : boolean
run ( array $argv = null ) : mixed
setDefaultCommand ( string $name = null ) : Console
setExitOnException ( boolean $exit = true ) : Console Sets whether to call exit(1) when an exception is caught
setOptionsParser ( consolekit\OptionsParser $parser ) : Console
setSingleCommand ( type $singleCommand ) : Console Turn off command parsing
setTextWriter ( consolekit\TextWriter $writer ) : Console
setVerboseException ( boolean $enable = true ) Sets whether a detailed error message is displayed when exception are caught
write ( string $text, $pipe = TextWriter::STDOUT ) : Console Writes some text to the text writer
writeException ( Exception $e ) : Console Writes an error message to stderr
writeln ( string $text = '', $pipe = TextWriter::STDOUT ) : Console Writes a line of text

Method Details

__construct() public method

public __construct ( array $commands = [], consolekit\OptionsParser $parser = null, consolekit\TextWriter $writer = null )
$commands array
$parser consolekit\OptionsParser
$writer consolekit\TextWriter

addCommand() public method

Registers a command
public addCommand ( callback $callback, string $alias = null, boolean $default = false ) : Console
$callback callback Associated class name, function name, Command instance or closure
$alias string Command name to be used in the shell
$default boolean True to set the command as the default one
return Console

addCommands() public method

Adds multiple commands at once
See also: addCommand()
public addCommands ( array $commands ) : Console
$commands array
return Console

addCommandsFromDir() public method

Registers commands from a directory
public addCommandsFromDir ( string $dir, string $namespace = '', boolean $includeFiles = false ) : Console
$dir string
$namespace string
$includeFiles boolean
return Console

areExceptionsVerbose() public method

public areExceptionsVerbose ( ) : boolean
return boolean

execute() public method

Executes a command
public execute ( string $command = null, array $args = [], array $options = [] ) : mixed
$command string
$args array
$options array
return mixed

exitsOnException() public method

public exitsOnException ( ) : boolean
return boolean

getCommand() public method

public getCommand ( string $name ) : string
$name string
return string

getCommands() public method

public getCommands ( ) : array
return array

getDefaultCommand() public method

public getDefaultCommand ( ) : string
return string

getOptionsParser() public method

public getOptionsParser ( ) : consolekit\OptionsParser
return consolekit\OptionsParser

getTextWriter() public method

public getTextWriter ( ) : consolekit\TextWriter
return consolekit\TextWriter

hasCommand() public method

public hasCommand ( string $name ) : boolean
$name string
return boolean

run() public method

public run ( array $argv = null ) : mixed
$argv array
return mixed Results of the command callback

setDefaultCommand() public method

public setDefaultCommand ( string $name = null ) : Console
$name string
return Console

setExitOnException() public method

Sets whether to call exit(1) when an exception is caught
public setExitOnException ( boolean $exit = true ) : Console
$exit boolean
return Console

setOptionsParser() public method

public setOptionsParser ( consolekit\OptionsParser $parser ) : Console
$parser consolekit\OptionsParser
return Console

setSingleCommand() public method

Turn off command parsing
public setSingleCommand ( type $singleCommand ) : Console
$singleCommand type
return Console

setTextWriter() public method

public setTextWriter ( consolekit\TextWriter $writer ) : Console
$writer consolekit\TextWriter
return Console

setVerboseException() public method

Sets whether a detailed error message is displayed when exception are caught
public setVerboseException ( boolean $enable = true )
$enable boolean

write() public method

Writes some text to the text writer
See also: TextWriter::write()
public write ( string $text, $pipe = TextWriter::STDOUT ) : Console
$text string
return Console

writeException() public method

Writes an error message to stderr
public writeException ( Exception $e ) : Console
$e Exception
return Console

writeln() public method

Writes a line of text
See also: TextWriter::writeln()
public writeln ( string $text = '', $pipe = TextWriter::STDOUT ) : Console
$text string
return Console

Property Details

$commands protected property

protected array $commands
return array

$defaultCommand protected property

protected string $defaultCommand
return string

$exitOnException protected property

protected bool $exitOnException
return boolean

$helpCommand protected property

protected string $helpCommand
return string

$helpCommandClass protected property

protected string $helpCommandClass
return string

$optionsParser protected property

protected OptionsParser,consolekit $optionsParser
return consolekit\OptionsParser

$singleCommand protected property

protected bool $singleCommand
return boolean

$textWriter protected property

protected TextWriter,consolekit $textWriter
return consolekit\TextWriter

$verboseException protected property

protected bool $verboseException
return boolean