FileDiffer

Class
Read only: Yes Final: Yes

Renders deterministic summaries and unified diffs for file comparisons.

Table of Contents

Properties

Methods

__construct()

Creates a new file differ.

 : mixed
colorize()

Colorizes a unified diff for decorated console output.

 : string
diff()

Compares a source file against the target file that would be overwritten.

 : FileDiff
diffContents()

Compares managed content against the current target contents.

 : FileDiff
formatForConsole()

Formats a diff payload for console output.

 : string|null
isBinary()

Reports whether the given content should be treated as binary.

 : bool
Properties
Methods

colorize()

Public

Colorizes a unified diff for decorated console output.

public colorize( string  $diff) : string
Parameters
$diff : string

Description

the plain unified diff

Return values
string

Description

the colorized diff using Symfony Console tags

diff()

Public

Compares a source file against the target file that would be overwritten.

public diff( string  $sourcePath, string  $targetPath) : FileDiff
Parameters
$sourcePath : string

Description

the source file path that would replace the target

$targetPath : string

Description

the existing target file path

Return values

Description

the rendered comparison result

diffContents()

Public

Compares managed content against the current target contents.

public diffContents( string  $sourceLabel, string  $targetPath, string  $sourceContent, string|null  $targetContent[, string|null  $changedSummary = null]) : FileDiff
Parameters
$sourceLabel : string

Description

the human-readable source label shown in summaries

$targetPath : string

Description

the target file path

$sourceContent : string

Description

the generated or source content

$targetContent : string|null

Description

the current target content, or null when the target does not exist

$changedSummary : string|null = null

Description

an optional changed-state summary override

Return values

Description

the rendered comparison result

formatForConsole()

Public

Formats a diff payload for console output.

public formatForConsole( string|null  $diff, bool  $decorated) : string|null
Parameters
$diff : string|null

Description

the plain unified diff, if available

$decorated : bool

Description

whether console decoration is enabled

Return values
string|null

Description

the diff payload ready for console output

isBinary()

Private

Reports whether the given content should be treated as binary.

private isBinary( string  $content) : bool
Parameters
$content : string

Description

the content to inspect

Return values
bool

Description

true when the content should not receive a text diff