Diff_Renderer_Html_Array
extends Diff_Renderer_Abstract
in package
Abstract class for diff renderers in PHP DiffLib.
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.
Table of Contents
Properties
- $diff : object
- $defaultOptions : array<string|int, mixed>
- $options : array<string|int, mixed>
Methods
- __construct() : mixed
- The constructor. Instantiates the rendering engine and if options are passed, sets the options for the renderer.
- fixSpaces() : string
- Replace a string containing spaces with a HTML representation using .
- render() : array<string|int, mixed>
- Render and return an array structure suitable for generating HTML based differences. Generally called by subclasses that generate a HTML based diff and return an array of the changes to show in the diff.
- setOptions() : mixed
- Set the options of the renderer to those supplied in the passed in array.
- expandTabs() : string
- Replace tabs in a single line with a number of spaces as defined by the tabSize option.
- formatLines() : array<string|int, mixed>
- Format a series of lines suitable for output in a HTML rendered diff.
- getChangeExtent() : array<string|int, mixed>
- Given two strings, determine where the changes in the two strings begin, and where the changes in the two strings end.
- htmlSafe() : string
- Make a string containing HTML safe for output on a page.
Properties
$diff
public
object
$diff
Instance of the diff class that this renderer is generating the rendered diff for.
$defaultOptions
protected
array<string|int, mixed>
$defaultOptions
= array('tabSize' => 4)
Array of the default options that apply to this renderer.
$options
protected
array<string|int, mixed>
$options
= array()
Array containing the user applied and merged default options for the renderer.
Methods
__construct()
The constructor. Instantiates the rendering engine and if options are passed, sets the options for the renderer.
public
__construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
-
Optionally, an array of the options for the renderer.
fixSpaces()
Replace a string containing spaces with a HTML representation using .
public
static fixSpaces(string $matches) : string
Parameters
- $matches : string
-
Regex matches array.
Return values
string —The HTML representation of the string.
render()
Render and return an array structure suitable for generating HTML based differences. Generally called by subclasses that generate a HTML based diff and return an array of the changes to show in the diff.
public
render() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of the generated chances, suitable for presentation in HTML.
setOptions()
Set the options of the renderer to those supplied in the passed in array.
public
setOptions(array<string|int, mixed> $options) : mixed
Options are merged with the default to ensure that there aren't any missing options.
Parameters
- $options : array<string|int, mixed>
-
Array of options to set.
expandTabs()
Replace tabs in a single line with a number of spaces as defined by the tabSize option.
private
expandTabs(string $line) : string
Parameters
- $line : string
-
The containing tabs to convert.
Return values
string —The line with the tabs converted to spaces.
formatLines()
Format a series of lines suitable for output in a HTML rendered diff.
private
formatLines(array<string|int, mixed> $lines) : array<string|int, mixed>
This involves replacing tab characters with spaces, making the HTML safe for output, ensuring that double spaces are replaced with etc.
Parameters
- $lines : array<string|int, mixed>
-
Array of lines to format.
Return values
array<string|int, mixed> —Array of the formatted lines.
getChangeExtent()
Given two strings, determine where the changes in the two strings begin, and where the changes in the two strings end.
private
getChangeExtent(string $fromLine, string $toLine) : array<string|int, mixed>
Parameters
- $fromLine : string
-
The first string.
- $toLine : string
-
The second string.
Return values
array<string|int, mixed> —Array containing the starting position (0 by default) and the ending position (-1 by default)
htmlSafe()
Make a string containing HTML safe for output on a page.
private
htmlSafe(string $string) : string
Parameters
- $string : string
-
The string.
Return values
string —The string with the HTML characters replaced by entities.