private function formatTextBlock($text, $prefix = '', $prefixAllLines = false)
    {
        if (empty($text)) {
            return $text;
        }

        $textLines = explode(PHP_EOL, $text);

        // remove the trailing PHP_EOL (and add it back afterwards) to avoid formatting issues
        $addTrailingNewline = false;
        if ('' === $textLines[count($textLines) - 1]) {
            array_pop($textLines);
            $addTrailingNewline = true;
        }

        $newTextLines = array();
        foreach ($textLines as $line) {
            if ($prefixAllLines) {
                $newTextLines[] = $prefix.$line;
            } else {
                if (isset($line[0]) && ' ' !== $line[0]) {
                    $newTextLines[] = $prefix.$line;
                } else {
                    $newTextLines[] = str_repeat(' ', strlen($prefix)).$line;
                }
            }
        }

        return implode(PHP_EOL, $newTextLines).($addTrailingNewline ? PHP_EOL : '');
    }
private function formatTextBlock($text, $prefix = '', $prefixAllLines = false)
    {
        if (empty($text)) {
            return $text;
        }

        $textLines = explode(PHP_EOL, $text);

        // remove the trailing PHP_EOL (and add it back afterwards) to avoid formatting issues
        $addTrailingNewline = false;
        if ('' === $textLines[count($textLines) - 1]) {
            array_pop($textLines);
            $addTrailingNewline = true;
        }

        $newTextLines = array();
        foreach ($textLines as $line) {
            if ($prefixAllLines) {
                $newTextLines[] = $prefix.$line;
            } else {
                if (isset($line[0]) && ' ' !== $line[0]) {
                    $newTextLines[] = $prefix.$line;
                } else {
                    $newTextLines[] = str_repeat(' ', strlen($prefix)).$line;
                }
            }
        }

        return implode(PHP_EOL, $newTextLines).($addTrailingNewline ? PHP_EOL : '');
    }
private function formatTextBlock ( $ text , $ prefix = '' , $ prefixAllLines = false ) { if ( empty ( $ text ) ) { return $ text ; } $ textLines = explode ( PHP_EOL , $ text ) ; // remove the trailing PHP_EOL (and add it back afterwards) to avoid formatting issues $ addTrailingNewline = false ; if ( '' === $ textLines [ count ( $ textLines ) - 1 ] ) { array_pop ( $ textLines ) ; $ addTrailingNewline = true ; } $ newTextLines = array ( ) ; foreach ( $ textLines as $ line ) { if ( $ prefixAllLines ) { $ newTextLines [ ] = $ prefix . $ line ; } else { if ( isset ( $ line [ 0 ] ) && ' ' !== $ line [ 0 ] ) { $ newTextLines [ ] = $ prefix . $ line ; } else { $ newTextLines [ ] = str_repeat ( ' ' , strlen ( $ prefix ) ) . $ line ; } } } return implode ( PHP_EOL , $ newTextLines ) . ( $ addTrailingNewline ? PHP_EOL : '' ) ; }
Prepends the prefix to every line of the given string.

@param string $text
@param string $prefix
@param bool   $prefixAllLines If false, prefix is only added to lines that don't start with white spaces

@return string
Prepends the prefix to every line of the given string .