public static function apply($text, $foreground = null, $background = null, array $options = [])
    {
        if (!self::hasColorSupport()) {
            return $text;
        }

        $setCodes   = [];
        $unsetCodes = [];

        if (null !== $foreground) {
            $setCodes[]   = self::$availableForegroundColors[$foreground]['set'];
            $unsetCodes[] = self::$availableForegroundColors[$foreground]['unset'];
        }
        if (null !== $background) {
            $setCodes[]   = self::$availableBackgroundColors[$background]['set'];
            $unsetCodes[] = self::$availableBackgroundColors[$background]['unset'];
        }
        if (!empty($options)) {
            foreach ($options as $option) {
                $setCodes[]   = self::$availableOptions[$option]['set'];
                $unsetCodes[] = self::$availableOptions[$option]['unset'];
            }
        }

        if (0 === count($setCodes)) {
            return $text;
        }

        return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, implode(';', $unsetCodes));
    }
public static function apply($text, $foreground = null, $background = null, array $options = [])
    {
        if (!self::hasColorSupport()) {
            return $text;
        }

        $setCodes   = [];
        $unsetCodes = [];

        if (null !== $foreground) {
            $setCodes[]   = self::$availableForegroundColors[$foreground]['set'];
            $unsetCodes[] = self::$availableForegroundColors[$foreground]['unset'];
        }
        if (null !== $background) {
            $setCodes[]   = self::$availableBackgroundColors[$background]['set'];
            $unsetCodes[] = self::$availableBackgroundColors[$background]['unset'];
        }
        if (!empty($options)) {
            foreach ($options as $option) {
                $setCodes[]   = self::$availableOptions[$option]['set'];
                $unsetCodes[] = self::$availableOptions[$option]['unset'];
            }
        }

        if (0 === count($setCodes)) {
            return $text;
        }

        return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, implode(';', $unsetCodes));
    }
public static function apply ( $ text , $ foreground = null , $ background = null , array $ options = [ ] ) { if ( ! self :: hasColorSupport ( ) ) { return $ text ; } $ setCodes = [ ] ; $ unsetCodes = [ ] ; if ( null !== $ foreground ) { $ setCodes [ ] = self :: $ availableForegroundColors [ $ foreground ] [ 'set' ] ; $ unsetCodes [ ] = self :: $ availableForegroundColors [ $ foreground ] [ 'unset' ] ; } if ( null !== $ background ) { $ setCodes [ ] = self :: $ availableBackgroundColors [ $ background ] [ 'set' ] ; $ unsetCodes [ ] = self :: $ availableBackgroundColors [ $ background ] [ 'unset' ] ; } if ( ! empty ( $ options ) ) { foreach ( $ options as $ option ) { $ setCodes [ ] = self :: $ availableOptions [ $ option ] [ 'set' ] ; $ unsetCodes [ ] = self :: $ availableOptions [ $ option ] [ 'unset' ] ; } } if ( 0 === count ( $ setCodes ) ) { return $ text ; } return sprintf ( "\033[%sm%s\033[%sm" , implode ( ';' , $ setCodes ) , $ text , implode ( ';' , $ unsetCodes ) ) ; }
Applies the style to a given text.

@param string $text The text to style=
@param null   $foreground
@param null   $background
@param array  $options

@return string
Applies the style to a given text .