MMOframework
Pourquoi l'IA Playground Bibliothèques Développeurs Agence
FR EN
Créer un projet en direct
Index

DataMerge

MMO\admin\helpers · 1 symbole · générée le 30 Nov 2026

class

DataMerge

DataMerge.php:25

Merges the two versions of a file a site and its copy here both changed (DataSync::BOTH), from the version they last had in common, and shows how they differ -- with mmo.git's diff (Repository::DiffContents).

class MMO\admin\helpers\DataMerge
Espace de noms
MMO\admin\helpers
- **A JSON collection** -- an object of documents by id, as mmo.core's JsonRepository writes `users.json` or `pages.json` on one line -- is merged document by document: one side's change is taken, a document both sides changed differently is a conflict, shown as the diff of the two documents written out. - **A text** is merged by `git merge-file` ([`Repository::MergeContents`](https://mmoframework.fr/fr/documentation/mmo.git/php/helpers/Repository.md#repository-mergecontents)) when the common version is known, each conflict then shown on its own; without it, every hunk of the diff is one. - **Anything else** (an SQLite database, an image) is one side or the other, whole. Each conflict goes to the resolver, which answers [`LOCAL`](https://mmoframework.fr/fr/documentation/mmo.admin/php/helpers/DataMerge.md#datamerge-local) or [`TARGET`](https://mmoframework.fr/fr/documentation/mmo.admin/php/helpers/DataMerge.md#datamerge-target) -- at a terminal, a person (`data-merge`), or a rule (`--prefer=`).
$merge = new DataMerge(fn(array $conflict) => DataMerge::TARGET); ['content' => $merged] = $merge->merge('db/pages.json', $base, $local, $remote);

Index

LOCALthe version here
TARGETthe target's version
conflicts
merged
resolve
ask($path, $unit, $kind, $diff, $local, $target)
Collection($content) static
diff($path, $local, $target)What differs between the two versions, unit by unit: a collection's documents, else the whole file.
Encode($documents, $like) staticWrite a collection as the file it came from was written: on one line or pretty, its slashes and its accents escaped or not -- so a merge changes the documents, not the whole file.
Format($diff, $from, $to, $max) staticA diff as a terminal shows it: removed lines red, added ones green, each hunk under its line numbers.
merge($path, $base, $local, $target)
mergeCollection($path, $base, $local, $target)
mergeHunks($path, $local, $target)Without the common version: each hunk of the diff from the local version to the target's is one question.
mergeText($path, $base, $local, $target)
Pretty($document) static
__construct($resolve)

Constantes2

LOCAL

the version here

const LOCAL = 'local'

TARGET

the target's version

const TARGET = 'target'

Propriétés3

conflicts

int $conflicts = 0
Type
int

merged

int $merged = 0
Type
int

resolve

protected $resolve = null

Méthodes11

Collection($content)

staticDataMerge.php:99
static function Collection(string $content): ?array
$contentstring
retournenull | arrayobject>|null its documents by id, when it is an object of objects (an empty object too)

diff($path, $local, $target)

DataMerge.php:76

What differs between the two versions, unit by unit: a collection's documents, else the whole file.

function diff(string $path, ?string $local, ?string $target): array
$pathstring
$localnull | string
$targetnull | string
retournearrayDiffFile|null> unit => its diff from the local version to the target's (null: a binary file)

Encode($documents, $like)

staticDataMerge.php:148

Write a collection as the file it came from was written: on one line or pretty, its slashes and its accents escaped or not -- so a merge changes the documents, not the whole file.

static function Encode(array $documents, string $like): string
$documentsarray
$likestring
retournestring

Format($diff, $from, $to, $max)

staticDataMerge.php:214

A diff as a terminal shows it: removed lines red, added ones green, each hunk under its line numbers.

static function Format( ?MMO\git\helpers\DiffFile $diff, string $from = 'local', string $to = 'target', int $max = 120 ): string
$diffnull | DiffFile
$from = 'local'stringwhat the removed side is
$to = 'target'stringwhat the added side is
$max = 120inthow many lines at most
retournestring

merge($path, $base, $local, $target)

DataMerge.php:53
function merge(string $path, ?string $base, ?string $local, ?string $target): array
$pathstring
$basenull | stringthe version both sides last held (null: unknown)
$localnull | stringthe version here (null: absent)
$targetnull | stringthe target's version, portable (null: absent)
retournearray?string} the merged version (null: the file is removed)

mergeHunks($path, $local, $target)

DataMerge.php:174

Without the common version: each hunk of the diff from the local version to the target's is one question.

protected function mergeHunks(string $path, string $local, string $target): string
$pathstring
$localstring
$targetstring
retournestring

Pretty($document)

staticDataMerge.php:112
static function Pretty(mixed $document): string
$documentmixed
retournestringa document written out, one value per line, for a diff a person reads

__construct($resolve)

DataMerge.php:44
function __construct(callable $resolve)
$resolvecallablefn(array $conflict): string -- LOCAL or TARGET for one conflict: its path, its unit (a document's id, hunk 2, file), its kind (document, hunk, file), its diff from the local version to the target's (null for a binary), and both versions of it (null: absent)