ConsoleKit\Colors::colorize PHP Method

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
    public static function colorize($text, $fgcolor = null, $bgcolor = null)
    {
        $colors = '';
        if ($bgcolor) {
            $colors .= self::getBgColorString(self::getColorCode($bgcolor));
        }
        if ($fgcolor) {
            $colors .= self::getFgColorString(self::getColorCode($fgcolor));
        }
        if ($colors) {
            $text = $colors . $text . self::RESET;
        }
        return $text;
    }

Usage Example

示例#1
0
 public function testColorize()
 {
     $this->assertEquals("red", Colors::colorize('red', Colors::RED));
     $this->assertEquals("red", Colors::colorize('red', Colors::RED | Colors::BOLD));
     $this->assertEquals("red", Colors::colorize('red', Colors::RED, Colors::YELLOW));
     $this->assertEquals("red", Colors::red('red'));
 }
All Usage Examples Of ConsoleKit\Colors::colorize