This is a line-by-line conversion to append to a string property rather
than print into a PHP output buffer.
The changes to the base class break subclasses such as MobileFrontend's
InlineDiffFormatter, which is updated in I81dd01cb.
Depends-On: I81dd01cbb9ce11b87115fb1fed511027aee436a1
Change-Id: Idf2a6c593b81a152edec923d4db6272ca1f3f545
*/
protected $trailingContextLines = 0;
*/
protected $trailingContextLines = 0;
+ /** @var string The output buffer; holds the output while it is built. */
+ private $result = '';
+
}
protected function startDiff() {
}
protected function startDiff() {
+ $this->result = '';
+ }
+
+ /**
+ * Writes a string to the output buffer.
+ *
+ * @param string $text
+ */
+ protected function writeOutput( $text ) {
+ $this->result .= $text;
}
/**
* @return string
*/
protected function endDiff() {
}
/**
* @return string
*/
protected function endDiff() {
- $val = ob_get_contents();
- ob_end_clean();
+ $val = $this->result;
+ $this->result = '';
* @param string $header
*/
protected function startBlock( $header ) {
* @param string $header
*/
protected function startBlock( $header ) {
+ $this->writeOutput( $header . "\n" );
*/
protected function lines( $lines, $prefix = ' ' ) {
foreach ( $lines as $line ) {
*/
protected function lines( $lines, $prefix = ' ' ) {
foreach ( $lines as $line ) {
- echo "$prefix $line\n";
+ $this->writeOutput( "$prefix $line\n" );
*/
protected function changed( $orig, $closing ) {
$this->deleted( $orig );
*/
protected function changed( $orig, $closing ) {
$this->deleted( $orig );
+ $this->writeOutput( "---\n" );
$this->added( $closing );
}
$this->added( $closing );
}
* @param string $header
*/
protected function startBlock( $header ) {
* @param string $header
*/
protected function startBlock( $header ) {
+ $this->writeOutput( $header );
}
protected function endBlock() {
}
protected function endBlock() {
*/
protected function added( $lines ) {
foreach ( $lines as $line ) {
*/
protected function added( $lines ) {
foreach ( $lines as $line ) {
- echo '<tr>' . $this->emptyLine() .
+ $this->writeOutput( '<tr>' . $this->emptyLine() .
$this->addedLine( '<ins class="diffchange">' .
$this->addedLine( '<ins class="diffchange">' .
- htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n";
+ htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n" );
*/
protected function deleted( $lines ) {
foreach ( $lines as $line ) {
*/
protected function deleted( $lines ) {
foreach ( $lines as $line ) {
- echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
+ $this->writeOutput( '<tr>' . $this->deletedLine( '<del class="diffchange">' .
htmlspecialchars( $line ) . '</del>' ) .
htmlspecialchars( $line ) . '</del>' ) .
- $this->emptyLine() . "</tr>\n";
+ $this->emptyLine() . "</tr>\n" );
*/
protected function context( $lines ) {
foreach ( $lines as $line ) {
*/
protected function context( $lines ) {
foreach ( $lines as $line ) {
+ $this->writeOutput( '<tr>' .
$this->contextLine( htmlspecialchars( $line ) ) .
$this->contextLine( htmlspecialchars( $line ) ) .
- $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n";
+ $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n" );
$line = array_shift( $del );
while ( $line ) {
$aline = array_shift( $add );
$line = array_shift( $del );
while ( $line ) {
$aline = array_shift( $add );
- echo '<tr>' . $this->deletedLine( $line ) .
- $this->addedLine( $aline ) . "</tr>\n";
+ $this->writeOutput( '<tr>' . $this->deletedLine( $line ) .
+ $this->addedLine( $aline ) . "</tr>\n" );
$line = array_shift( $del );
}
foreach ( $add as $line ) { # If any leftovers
$line = array_shift( $del );
}
foreach ( $add as $line ) { # If any leftovers
- echo '<tr>' . $this->emptyLine() .
- $this->addedLine( $line ) . "</tr>\n";
+ $this->writeOutput( '<tr>' . $this->emptyLine() .
+ $this->addedLine( $line ) . "</tr>\n" );
*/
protected function lines( $lines, $prefix = ' ' ) {
foreach ( $lines as $line ) {
*/
protected function lines( $lines, $prefix = ' ' ) {
foreach ( $lines as $line ) {
- echo "{$prefix}{$line}\n";
+ $this->writeOutput( "{$prefix}{$line}\n" );