Documentation

Console
in package

Console class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)

license

http://www.popphp.org/license New BSD License

version
4.1.0

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 = []

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

addCommands()

Add commands

public addCommands(array<string|int, mixed> $commands) : Console
Parameters
$commands : array<string|int, mixed>
Return values
Console

addCommandsFromRoutes()

Add commands from routes

public addCommandsFromRoutes(Cli $routeMatch[, string|null $scriptName = null ]) : Console
Parameters
$routeMatch : Cli
$scriptName : string|null = null
Return values
Console

alert()

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

alertBox()

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

alertDanger()

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

alertDark()

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

alertInfo()

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

alertLight()

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

alertPrimary()

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

alertSecondary()

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

alertSuccess()

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

alertWarning()

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

append()

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
Console

clear()

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
string

confirm()

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
string

displayHelp()

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|null

getCommands()

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>|null

getFooter()

Get the console footer

public getFooter([bool $formatted = false ]) : string|null
Parameters
$formatted : bool = false
Return values
string|null

getHeader()

Get the console header

public getHeader([bool $formatted = false ]) : string|null
Parameters
$formatted : bool = false
Return values
string|null

getHeaderSent()

Get the console header sent flag

public getHeaderSent() : bool
Return values
bool

getHeight()

Get the terminal height of the console object

public getHeight() : int
Return values
int

getHelpColors()

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
string

getMargin()

Get the margin of the console object

public getMargin() : int
Return values
int

getServer()

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>|null

getWidth()

Get the terminal width of the console object

public getWidth() : int
Return values
int

getWrap()

Get the wrap width of the console object

public getWrap() : int
Return values
int

hasCommand()

Check if the console object has a command

public hasCommand(string $command) : bool
Parameters
$command : string
Return values
bool

hasHeight()

Has terminal height

public hasHeight() : bool
Return values
bool

hasMargin()

Has margin

public hasMargin() : bool
Return values
bool

hasWidth()

Has terminal width

public hasWidth() : bool
Return values
bool

hasWrap()

Has wrap

public hasWrap() : bool
Return values
bool

header()

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

headerCenter()

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

headerLeft()

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

headerRight()

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

help()

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|null

isColor()

Check is console terminal supports color

public isColor() : bool
Return values
bool

isWindows()

Check is console terminal is in a Windows environment

public isWindows() : bool
Return values
bool

line()

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

prompt()

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
string

send()

Send the response

public send([bool $withHeaders = true ]) : Console
Parameters
$withHeaders : bool = true
Return values
Console

setFooter()

Set the console footer

public setFooter(string $footer[, bool $newline = true ]) : Console
Parameters
$footer : string
$newline : bool = true
Return values
Console

setHeader()

Set the console header

public setHeader(string $header[, bool $newline = true ]) : Console
Parameters
$header : string
$newline : bool = true
Return values
Console

setHeaderSent()

Set the console header sent flag

public setHeaderSent([bool $headerSent = true ]) : Console
Parameters
$headerSent : bool = true
Return values
Console

setHeight()

Set the terminal height of the console object

public setHeight(int $height) : Console
Parameters
$height : int
Return values
Console

setHelpColors()

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
Console

setIndent()

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
Console

setMargin()

Set the margin of the console object

public setMargin(int $margin) : Console
Parameters
$margin : int
Return values
Console

setWidth()

Set the terminal width of the console object

public setWidth(int $width) : Console
Parameters
$width : int
Return values
Console

setWrap()

Set the wrap width of the console object

public setWrap(int $wrap) : Console
Parameters
$wrap : int
Return values
Console

write()

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
Console

calculatePad()

Calculate string pad

protected calculatePad(string $string, int $size[, string $align = 'center' ]) : int
Parameters
$string : string
$size : int
$align : string = 'center'
Return values
int

formatTemplate()

Format header or footer template

protected formatTemplate(string $template) : string
Parameters
$template : string
Return values
string

getPromptInput()

Get prompt input

protected getPromptInput(string $prompt[, int $length = 500 ][, bool $caseSensitive = false ]) : string
Parameters
$prompt : string
$length : int = 500
$caseSensitive : bool = false
Return values
string

        
On this page

Search results