X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fdiff%2FDiffFormatter.php;h=4b44b3c4b25dc98a0f38fdbd1e174a4feb6b3ab0;hp=33ca931fdb588175c77775566911688fc9cb17c9;hb=e3bd13db0c285f312e31bb1b7271af4628cca80c;hpb=dd8c1e2dd3feb9c5c6bd79d2a8a3356666792d0c diff --git a/includes/diff/DiffFormatter.php b/includes/diff/DiffFormatter.php index 33ca931fdb..4b44b3c4b2 100644 --- a/includes/diff/DiffFormatter.php +++ b/includes/diff/DiffFormatter.php @@ -49,6 +49,9 @@ abstract class DiffFormatter { */ protected $trailingContextLines = 0; + /** @var string The output buffer; holds the output while it is built. */ + private $result = ''; + /** * Format a diff. * @@ -60,7 +63,7 @@ abstract class DiffFormatter { $xi = $yi = 1; $block = false; - $context = array(); + $context = []; $nlead = $this->leadingContextLines; $ntrail = $this->trailingContextLines; @@ -91,7 +94,7 @@ abstract class DiffFormatter { $context = array_slice( $context, count( $context ) - $nlead ); $x0 = $xi - count( $context ); $y0 = $yi - count( $context ); - $block = array(); + $block = []; if ( $context ) { $block[] = new DiffOpCopy( $context ); } @@ -146,15 +149,24 @@ abstract class DiffFormatter { } protected function startDiff() { - ob_start(); + $this->result = ''; + } + + /** + * Writes a string to the output buffer. + * + * @param string $text + */ + protected function writeOutput( $text ) { + $this->result .= $text; } /** * @return string */ protected function endDiff() { - $val = ob_get_contents(); - ob_end_clean(); + $val = $this->result; + $this->result = ''; return $val; } @@ -185,7 +197,7 @@ abstract class DiffFormatter { * @param string $header */ protected function startBlock( $header ) { - echo $header . "\n"; + $this->writeOutput( $header . "\n" ); } /** @@ -203,7 +215,7 @@ abstract class DiffFormatter { */ protected function lines( $lines, $prefix = ' ' ) { foreach ( $lines as $line ) { - echo "$prefix $line\n"; + $this->writeOutput( "$prefix $line\n" ); } } @@ -236,7 +248,7 @@ abstract class DiffFormatter { */ protected function changed( $orig, $closing ) { $this->deleted( $orig ); - echo "---\n"; + $this->writeOutput( "---\n" ); $this->added( $closing ); }