Console
in package
Console class
Tags
Table of Contents
Properties
- $commands : array<string|int, mixed>
- Commands
- $env : array<string|int, mixed>
- ENV array
- $footer : string|null
- Console footer
- $header : string|null
- Console header
- $headerSent : bool
- Flag for if console header has been sent
- $height : int
- Console terminal height
- $helpColors : array<string|int, mixed>
- Help colors
- $margin : int|null
- Console margin
- $response : string|null
- Console response body
- $server : array<string|int, mixed>
- SERVER array
- $width : int
- Console terminal width
- $wrap : int|null
- Console wrap
Methods
- __construct() : mixed
- Instantiate a new console object
- addCommand() : Console
- Add a command
- addCommands() : Console
- Add commands
- addCommandsFromRoutes() : Console
- Add commands from routes
- alert() : Console|string
- Print a colored alert box out to the console
- alertBox() : Console|string
- Print a colorless alert outline box out to the console
- alertDanger() : Console|string
- Print a "danger" alert box out to the console
- alertDark() : Console|string
- Print a "dark" alert box out to the console
- alertInfo() : Console|string
- Print an "info" alert box out to the console
- alertLight() : Console|string
- Print a "light" alert box out to the console
- alertPrimary() : Console|string
- Print a "primary" alert box out to the console
- alertSecondary() : Console|string
- Print a "secondary" alert box out to the console
- alertSuccess() : Console|string
- Print a "success" alert box out to the console
- alertWarning() : Console|string
- Print a "warning" alert box out to the console
- append() : Console
- Append a string of text to the response body
- clear() : void
- Clear the console
- colorize() : string
- Colorize a string for output
- confirm() : string
- Display confirm message prompt
- displayHelp() : void
- Display console help
- getAvailableColors() : array<string|int, mixed>
- Get the console help colors
- getCommand() : Command|null
- Get a command
- getCommands() : array<string|int, mixed>
- Get commands
- getCommandsFromRoutes() : array<string|int, mixed>
- Get commands from routes
- getEnv() : string|array<string|int, mixed>|null
- Get a value from $_ENV, or the whole array
- getFooter() : string|null
- Get the console footer
- getHeader() : string|null
- Get the console header
- getHeaderSent() : bool
- Get the console header sent flag
- getHeight() : int
- Get the terminal height of the console object
- getHelpColors() : array<string|int, mixed>
- Get the console help colors
- getIndent() : string
- Get the indent string based on the margin (to maintain backwards compatibility)
- getMargin() : int
- Get the margin of the console object
- getServer() : string|array<string|int, mixed>|null
- Get a value from $_SERVER, or the whole array
- getWidth() : int
- Get the terminal width of the console object
- getWrap() : int
- Get the wrap width of the console object
- hasCommand() : bool
- Check if the console object has a command
- hasHeight() : bool
- Has terminal height
- hasMargin() : bool
- Has margin
- hasWidth() : bool
- Has terminal width
- hasWrap() : bool
- Has wrap
- header() : Console|string
- Print a header
- headerCenter() : Console|string
- Print a center header
- headerLeft() : Console|string
- Print a left header
- headerRight() : Console|string
- Print a right header
- help() : string|null
- Get a help
- isColor() : bool
- Check is console terminal supports color
- isWindows() : bool
- Check is console terminal is in a Windows environment
- line() : Console|string
- Print a horizontal line rule out to the console
- prompt() : string
- Get input from the prompt
- send() : Console
- Send the response
- setFooter() : Console
- Set the console footer
- setHeader() : Console
- Set the console header
- setHeaderSent() : Console
- Set the console header sent flag
- setHeight() : Console
- Set the terminal height of the console object
- setHelpColors() : Console
- Set the console help colors
- setIndent() : Console
- Set the margin of the console object by way of an indentation string (to maintain backwards compatibility)
- setMargin() : Console
- Set the margin of the console object
- setWidth() : Console
- Set the terminal width of the console object
- setWrap() : Console
- Set the wrap width of the console object
- write() : Console
- Write a string of text to the response body and send the response
- calculatePad() : int
- Calculate string pad
- formatTemplate() : string
- Format header or footer template
- getPromptInput() : string
- Get prompt input
Properties
$commands
Commands
protected
array<string|int, mixed>
$commands
= []
$env
ENV array
protected
array<string|int, mixed>
$env
= []
$footer
Console footer
protected
string|null
$footer
= null
$header
Console header
protected
string|null
$header
= null
$headerSent
Flag for if console header has been sent
protected
bool
$headerSent
= false
$height
Console terminal height
protected
int
$height
= 0
$helpColors
Help colors
protected
array<string|int, mixed>
$helpColors
= []
$margin
Console margin
protected
int|null
$margin
= null
$response
Console response body
protected
string|null
$response
= null
$server
SERVER array
protected
array<string|int, mixed>
$server
= []
$width
Console terminal width
protected
int
$width
= 0
$wrap
Console wrap
protected
int|null
$wrap
= null
Methods
__construct()
Instantiate a new console object
public
__construct([int|null $wrap = 80 ][, int|string|null $margin = 4 ]) : mixed
Parameters
- $wrap : int|null = 80
- $margin : int|string|null = 4
addCommand()
Add a command
public
addCommand(Command $command) : Console
Parameters
- $command : Command
Return values
ConsoleaddCommands()
Add commands
public
addCommands(array<string|int, mixed> $commands) : Console
Parameters
- $commands : array<string|int, mixed>
Return values
ConsoleaddCommandsFromRoutes()
Add commands from routes
public
addCommandsFromRoutes(Cli $routeMatch[, string|null $scriptName = null ]) : Console
Parameters
- $routeMatch : Cli
- $scriptName : string|null = null
Return values
Consolealert()
Print a colored alert box out to the console
public
alert(string $message, int $fg, int $bg[, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $fg : int
- $bg : int
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringalertBox()
Print a colorless alert outline box out to the console
public
alertBox(string $message[, string $h = '-' ][, string|null $v = '|' ][, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $h : string = '-'
- $v : string|null = '|'
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringalertDanger()
Print a "danger" alert box out to the console
public
alertDanger(string $message[, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringalertDark()
Print a "dark" alert box out to the console
public
alertDark(string $message[, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringalertInfo()
Print an "info" alert box out to the console
public
alertInfo(string $message[, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringalertLight()
Print a "light" alert box out to the console
public
alertLight(string $message[, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringalertPrimary()
Print a "primary" alert box out to the console
public
alertPrimary(string $message[, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringalertSecondary()
Print a "secondary" alert box out to the console
public
alertSecondary(string $message[, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringalertSuccess()
Print a "success" alert box out to the console
public
alertSuccess(string $message[, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringalertWarning()
Print a "warning" alert box out to the console
public
alertWarning(string $message[, int|string|null $size = null ][, string $align = 'center' ][, int $innerPad = 4 ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $message : string
- $size : int|string|null = null
- $align : string = 'center'
- $innerPad : int = 4
- $newline : bool = true
- $return : bool = false
Return values
Console|stringappend()
Append a string of text to the response body
public
append([string|null $text = null ][, bool $newline = true ][, bool $margin = true ]) : Console
Parameters
- $text : string|null = null
- $newline : bool = true
- $margin : bool = true
Return values
Consoleclear()
Clear the console
public
clear() : void
colorize()
Colorize a string for output
public
colorize(string $string[, int|null $fg = null ][, int|null $bg = null ]) : string
Parameters
- $string : string
- $fg : int|null = null
- $bg : int|null = null
Return values
stringconfirm()
Display confirm message prompt
public
confirm([string $message = 'Are you sure?' ][, array<string|int, mixed> $options = ['Y', 'N'] ][, bool $caseSensitive = false ][, int $length = 500 ][, bool $withHeaders = true ]) : string
Parameters
- $message : string = 'Are you sure?'
- $options : array<string|int, mixed> = ['Y', 'N']
- $caseSensitive : bool = false
- $length : int = 500
- $withHeaders : bool = true
Return values
stringdisplayHelp()
Display console help
public
displayHelp([bool $raw = false ]) : void
Parameters
- $raw : bool = false
getAvailableColors()
Get the console help colors
public
getAvailableColors() : array<string|int, mixed>
Return values
array<string|int, mixed>getCommand()
Get a command
public
getCommand(string $command) : Command|null
Parameters
- $command : string
Return values
Command|nullgetCommands()
Get commands
public
getCommands() : array<string|int, mixed>
Return values
array<string|int, mixed>getCommandsFromRoutes()
Get commands from routes
public
getCommandsFromRoutes(Cli $routeMatch[, string|null $scriptName = null ]) : array<string|int, mixed>
Parameters
- $routeMatch : Cli
- $scriptName : string|null = null
Return values
array<string|int, mixed>getEnv()
Get a value from $_ENV, or the whole array
public
getEnv([string|null $key = null ]) : string|array<string|int, mixed>|null
Parameters
- $key : string|null = null
Return values
string|array<string|int, mixed>|nullgetFooter()
Get the console footer
public
getFooter([bool $formatted = false ]) : string|null
Parameters
- $formatted : bool = false
Return values
string|nullgetHeader()
Get the console header
public
getHeader([bool $formatted = false ]) : string|null
Parameters
- $formatted : bool = false
Return values
string|nullgetHeaderSent()
Get the console header sent flag
public
getHeaderSent() : bool
Return values
boolgetHeight()
Get the terminal height of the console object
public
getHeight() : int
Return values
intgetHelpColors()
Get the console help colors
public
getHelpColors() : array<string|int, mixed>
Return values
array<string|int, mixed>getIndent()
Get the indent string based on the margin (to maintain backwards compatibility)
public
getIndent() : string
Return values
stringgetMargin()
Get the margin of the console object
public
getMargin() : int
Return values
intgetServer()
Get a value from $_SERVER, or the whole array
public
getServer([string|null $key = null ]) : string|array<string|int, mixed>|null
Parameters
- $key : string|null = null
Return values
string|array<string|int, mixed>|nullgetWidth()
Get the terminal width of the console object
public
getWidth() : int
Return values
intgetWrap()
Get the wrap width of the console object
public
getWrap() : int
Return values
inthasCommand()
Check if the console object has a command
public
hasCommand(string $command) : bool
Parameters
- $command : string
Return values
boolhasHeight()
Has terminal height
public
hasHeight() : bool
Return values
boolhasMargin()
Has margin
public
hasMargin() : bool
Return values
boolhasWidth()
Has terminal width
public
hasWidth() : bool
Return values
boolhasWrap()
Has wrap
public
hasWrap() : bool
Return values
boolheader()
Print a header
public
header(string $string[, string $char = '-' ][, int|string|null $size = null ][, string $align = 'left' ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $string : string
- $char : string = '-'
- $size : int|string|null = null
- $align : string = 'left'
- $newline : bool = true
- $return : bool = false
Return values
Console|stringheaderCenter()
Print a center header
public
headerCenter(string $string[, string $char = '-' ][, int|string|null $size = 'auto' ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $string : string
- $char : string = '-'
- $size : int|string|null = 'auto'
- $newline : bool = true
- $return : bool = false
Return values
Console|stringheaderLeft()
Print a left header
public
headerLeft(string $string[, string $char = '-' ][, int|string|null $size = 'auto' ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $string : string
- $char : string = '-'
- $size : int|string|null = 'auto'
- $newline : bool = true
- $return : bool = false
Return values
Console|stringheaderRight()
Print a right header
public
headerRight(string $string[, string $char = '-' ][, int|string|null $size = 'auto' ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $string : string
- $char : string = '-'
- $size : int|string|null = 'auto'
- $newline : bool = true
- $return : bool = false
Return values
Console|stringhelp()
Get a help
public
help([string|null $command = null ][, bool $raw = false ]) : string|null
Parameters
- $command : string|null = null
- $raw : bool = false
Return values
string|nullisColor()
Check is console terminal supports color
public
isColor() : bool
Return values
boolisWindows()
Check is console terminal is in a Windows environment
public
isWindows() : bool
Return values
boolline()
Print a horizontal line rule out to the console
public
line([string $char = '-' ][, int|null $size = null ][, bool $newline = true ][, bool $return = false ]) : Console|string
Parameters
- $char : string = '-'
- $size : int|null = null
- $newline : bool = true
- $return : bool = false
Return values
Console|stringprompt()
Get input from the prompt
public
prompt(string $prompt[, array<string|int, mixed>|null $options = null ][, bool $caseSensitive = false ][, int $length = 500 ][, bool $withHeaders = true ]) : string
Parameters
- $prompt : string
- $options : array<string|int, mixed>|null = null
- $caseSensitive : bool = false
- $length : int = 500
- $withHeaders : bool = true
Return values
stringsend()
Send the response
public
send([bool $withHeaders = true ]) : Console
Parameters
- $withHeaders : bool = true
Return values
ConsolesetFooter()
Set the console footer
public
setFooter(string $footer[, bool $newline = true ]) : Console
Parameters
- $footer : string
- $newline : bool = true
Return values
ConsolesetHeader()
Set the console header
public
setHeader(string $header[, bool $newline = true ]) : Console
Parameters
- $header : string
- $newline : bool = true
Return values
ConsolesetHeaderSent()
Set the console header sent flag
public
setHeaderSent([bool $headerSent = true ]) : Console
Parameters
- $headerSent : bool = true
Return values
ConsolesetHeight()
Set the terminal height of the console object
public
setHeight(int $height) : Console
Parameters
- $height : int
Return values
ConsolesetHelpColors()
Set the console help colors
public
setHelpColors(int $color1[, int|null $color2 = null ][, int|null $color3 = null ][, int|null $color4 = null ]) : Console
Parameters
- $color1 : int
- $color2 : int|null = null
- $color3 : int|null = null
- $color4 : int|null = null
Return values
ConsolesetIndent()
Set the margin of the console object by way of an indentation string (to maintain backwards compatibility)
public
setIndent(string $indent) : Console
Parameters
- $indent : string
Return values
ConsolesetMargin()
Set the margin of the console object
public
setMargin(int $margin) : Console
Parameters
- $margin : int
Return values
ConsolesetWidth()
Set the terminal width of the console object
public
setWidth(int $width) : Console
Parameters
- $width : int
Return values
ConsolesetWrap()
Set the wrap width of the console object
public
setWrap(int $wrap) : Console
Parameters
- $wrap : int
Return values
Consolewrite()
Write a string of text to the response body and send the response
public
write([string|null $text = null ][, bool $newline = true ][, bool $margin = true ][, bool $withHeaders = true ]) : Console
Parameters
- $text : string|null = null
- $newline : bool = true
- $margin : bool = true
- $withHeaders : bool = true
Return values
ConsolecalculatePad()
Calculate string pad
protected
calculatePad(string $string, int $size[, string $align = 'center' ]) : int
Parameters
- $string : string
- $size : int
- $align : string = 'center'
Return values
intformatTemplate()
Format header or footer template
protected
formatTemplate(string $template) : string
Parameters
- $template : string
Return values
stringgetPromptInput()
Get prompt input
protected
getPromptInput(string $prompt[, int $length = 500 ][, bool $caseSensitive = false ]) : string
Parameters
- $prompt : string
- $length : int = 500
- $caseSensitive : bool = false