ConsoleKit\Colors::getColorCode PHP Method

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
    public static function getColorCode($color, $options = array())
    {
        $code = (int) $color;
        if (is_string($color)) {
            $options = array_merge(explode('+', strtolower($color)), $options);
            $color = array_shift($options);
            if (!isset(self::$colors[$color])) {
                throw new ConsoleException("Unknown color '{$color}'");
            }
            $code = self::$colors[$color];
        }
        foreach ($options as $opt) {
            $opt = strtolower($opt);
            if (!isset(self::$options[$opt])) {
                throw new ConsoleException("Unknown option '{$color}'");
            }
            $code = $code | self::$options[$opt];
        }
        return $code;
    }

Usage Example

示例#1
0
 /**
  * @expectedException        ConsoleKit\ConsoleException
  * @expectedExceptionMessage Unknown color 'foobar'
  */
 public function testGetUnknownColorCode()
 {
     Colors::getColorCode('foobar');
 }