public static function addColorOption(array $args, $colorOption)
    {
        if (!$colorOption
            || in_array($colorOption, $args)
            || !preg_match('/^--([a-z]+$)|(^--[a-z]+=)/', $colorOption, $matches)) {
            return $args;
        }

        if (isset($matches[2])) {
            // Handle --color(s)= options
            if (false !== ($index = array_search($matches[2].'auto', $args))) {
                $args[$index] = $colorOption;
                return $args;
            } elseif (preg_grep('/^'.$matches[2].'/', $args)) {
                return $args;
            }
        } elseif (in_array('--no-'.$matches[1], $args)) {
            return $args;
        }

        if (false !== ($index = array_search('--', $args))) {
            // Position option before double-dash delimiter
            array_splice($args, $index, 0, $colorOption);
        } else {
            $args[] = $colorOption;
        }

        return $args;
    }
public static function addColorOption(array $args, $colorOption)
    {
        if (!$colorOption
            || in_array($colorOption, $args)
            || !preg_match('/^--([a-z]+$)|(^--[a-z]+=)/', $colorOption, $matches)) {
            return $args;
        }

        if (isset($matches[2])) {
            // Handle --color(s)= options
            if (false !== ($index = array_search($matches[2].'auto', $args))) {
                $args[$index] = $colorOption;
                return $args;
            } elseif (preg_grep('/^'.$matches[2].'/', $args)) {
                return $args;
            }
        } elseif (in_array('--no-'.$matches[1], $args)) {
            return $args;
        }

        if (false !== ($index = array_search('--', $args))) {
            // Position option before double-dash delimiter
            array_splice($args, $index, 0, $colorOption);
        } else {
            $args[] = $colorOption;
        }

        return $args;
    }
public static function addColorOption ( array $ args , $ colorOption ) { if ( ! $ colorOption || in_array ( $ colorOption , $ args ) || ! preg_match ( '/^--([a-z]+$)|(^--[a-z]+=)/' , $ colorOption , $ matches ) ) { return $ args ; } if ( isset ( $ matches [ 2 ] ) ) { // Handle --color(s)= options if ( false !== ( $ index = array_search ( $ matches [ 2 ] . 'auto' , $ args ) ) ) { $ args [ $ index ] = $ colorOption ; return $ args ; } elseif ( preg_grep ( '/^' . $ matches [ 2 ] . '/' , $ args ) ) { return $ args ; } } elseif ( in_array ( '--no-' . $ matches [ 1 ] , $ args ) ) { return $ args ; } if ( false !== ( $ index = array_search ( '--' , $ args ) ) ) { // Position option before double-dash delimiter array_splice ( $ args , $ index , 0 , $ colorOption ) ; } else { $ args [ ] = $ colorOption ; } return $ args ; }
Returns an array of parameters, including a color option if required

A color option is needed because child process output is piped.

@param array $args The script parameters
@param string $colorOption The long option to force color output

@return array
Returns an array of parameters including a color option if required