\Inhere\Console\UtilFormatUtil

Class FormatUtil

Summary

Methods
Properties
Constants
typeToString()
applyIndent()
wrapText()
alignOptions()
memoryUsage()
howLongAgo()
spliceKeyValue()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

typeToString()

typeToString(mixed  $val) : string

Parameters

mixed $val

Returns

string

applyIndent()

applyIndent(string  $string, integer  $indent = 2, string  $indentChar = ' ') : string

Parameters

string $string
integer $indent
string $indentChar

Returns

string

wrapText()

wrapText(string  $text, integer  $indent, integer  $width) : string

Word wrap text with indentation to fit the screen size

If screen size could not be detected, or the indentation is greater than the screen size, the text will not be wrapped.

The first line will not be indented, so wrapText("Lorem ipsum dolor sit amet.", 4) will result in the following output, given the screen width is 16 characters:

Lorem ipsum
    dolor sit
    amet.

Parameters

string $text

the text to be wrapped

integer $indent

number of spaces to use for indentation.

integer $width

Returns

string —

the wrapped text.

alignOptions()

alignOptions(array  $options) : array

Parameters

array $options

Returns

array

memoryUsage()

memoryUsage(float  $memory) : string

Parameters

float $memory

Returns

string —
FormatUtil::memoryUsage(memory_get_usage(true));

howLongAgo()

howLongAgo(integer  $secs) : string

format timestamp to how long ago

Parameters

integer $secs

Returns

string

spliceKeyValue()

spliceKeyValue(array  $data, array  $opts = array()) : string

splice Array

Parameters

array $data

e.g [ 'system' => 'Linux', 'version' => '4.4.5', ]

array $opts

Returns

string