PHP Class ConsoleKit\Colors

Text can be colorized (foreground only) by using a static method named after the color code. $text = Colors::colorize('hello world', Colors::RED) $text = Colors::colorize('hello world', 'red') $text = Colors::colorize('hello world', Colors::RED | Colors::BOLD) $text = Colors::colorize('hello world', 'red+bold') $text = Colors::red('hello world');
ファイルを表示 Open project: maximebf/consolekit Class Usage Examples

Public Methods

Method Description
__callStatic ( $method, $args )
colorize ( string $text, string $fgcolor = null, string $bgcolor = null ) : string Returns a colorized string
colorizeLines ( string $text, string $fgcolor = null, string $bgcolor = null ) : string Returns a text with each lines colorized independently
getBgColorString ( $colorCode ) : string Returns a background color string
getColorCode ( integer | string $color, array $options = [] ) : integer Returns a color code
getFgColorString ( $colorCode ) : string Returns a foreground color string

Private Methods

Method Description
extractColorAndOptions ( integer $colorCode ) : array Extracts the options and the color from a color code

Method Details

__callStatic() public static method

public static __callStatic ( $method, $args )

colorize() public static method

Returns a colorized string
public static colorize ( string $text, string $fgcolor = null, string $bgcolor = null ) : string
$text string
$fgcolor string (a key from the $foregroundColors array)
$bgcolor string (a key from the $backgroundColors array)
return string

colorizeLines() public static method

Returns a text with each lines colorized independently
public static colorizeLines ( string $text, string $fgcolor = null, string $bgcolor = null ) : string
$text string
$fgcolor string
$bgcolor string
return string

getBgColorString() public static method

Returns a background color string
public static getBgColorString ( $colorCode ) : string
return string

getColorCode() public static method

$color can be a string with the color name, or one of the color constants.
public static getColorCode ( integer | string $color, array $options = [] ) : integer
$color integer | string
$options array
return integer

getFgColorString() public static method

Returns a foreground color string
public static getFgColorString ( $colorCode ) : string
return string