FileDiffer
Renders deterministic summaries and unified diffs for file comparisons.
Properties
Methods
Creates a new file differ.
Colorizes a unified diff for decorated console output.
Compares managed content against the current target contents.
Formats a diff payload for console output.
Reports whether the given content should be treated as binary.
private
DifferInterface
$differ
private
FilesystemInterface
$filesystem
Creates a new file differ.
public
__construct(FilesystemInterface
$filesystem, DifferInterface
$differ) : mixed
Parameters
Description
the filesystem used to read compared file contents
Description
the differ used to generate unified diffs
Colorizes a unified diff for decorated console output.
public
colorize(
string
$diff) : string
Parameters
$diff
:
string
Description
the plain unified diff
Return values
Description
the colorized diff using Symfony Console tags
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
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
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
Description
the diff payload ready for console output
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
Description
true when the content should not receive a text diff