Class Diff

InheritanceDiff

Diff

A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc)

PHP version 5

Copyright (c) 2009 Chris Boulton chris.boulton@interspire.com

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the Chris Boulton nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() The constructor. Diff
getA() Get a range of lines from $start to $end from the first comparison string and return them as an array. If no values are supplied, the entire string is returned. It's also possible to specify just one line to return only that line. Diff
getB() Get a range of lines from $start to $end from the second comparison string and return them as an array. If no values are supplied, the entire string is returned. It's also possible to specify just one line to return only that line. Diff
getGroupedOpcodes() Generate a list of the compiled and grouped opcodes for the differences between the two strings. Generally called by the renderer, this class instantiates the sequence matcher and performs the actual diff generation and return an array of the opcodes for it. Once generated, the results are cached in the diff class instance. Diff
render() Render a diff using the supplied rendering class and return it. Diff

Method Details

__construct() public method

The constructor.

public void __construct ( $a, $b, $options = [] )
$a array

Array containing the lines of the first string to compare.

$b array

Array containing the lines for the second string to compare.

$options array
getA() public method

Get a range of lines from $start to $end from the first comparison string and return them as an array. If no values are supplied, the entire string is returned. It's also possible to specify just one line to return only that line.

public array getA ( $start 0, $end null )
$start int

The starting number.

$end int

The ending number. If not supplied, only the item in $start will be returned.

return array

Array of all of the lines between the specified range.

getB() public method

Get a range of lines from $start to $end from the second comparison string and return them as an array. If no values are supplied, the entire string is returned. It's also possible to specify just one line to return only that line.

public array getB ( $start 0, $end null )
$start int

The starting number.

$end int

The ending number. If not supplied, only the item in $start will be returned.

return array

Array of all of the lines between the specified range.

getGroupedOpcodes() public method

Generate a list of the compiled and grouped opcodes for the differences between the two strings. Generally called by the renderer, this class instantiates the sequence matcher and performs the actual diff generation and return an array of the opcodes for it. Once generated, the results are cached in the diff class instance.

public array getGroupedOpcodes ( )
return array

Array of the grouped opcodes for the generated diff.

render() public method

Render a diff using the supplied rendering class and return it.

public mixed render ( Diff_Renderer_Abstract $renderer )
$renderer Diff_Renderer_Abstract

An instance of the rendering object to use for generating the diff.

return mixed

The generated diff. Exact return value depends on the rendered.