Download the PHP package logue/php-merge without Composer
On this page you can find all versions of the php package logue/php-merge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download logue/php-merge
More information about logue/php-merge
Files in logue/php-merge
Package php-merge
Short Description A PHP merge utility using the Diff php library or the command line git.
License MIT
Homepage https://github.com/bircher/php-merge
Informations about the package php-merge
php-merge
Introduction
When working with revisions of text one sometimes faces the problem that there are several revisions based off the same original text. Rather than choosing one and discarding the other we want to merge the two revisions.
Git does that already wonderfully. In a php application we want a simple tool
that does the same. There is the xdiff PECL extension
which has the xdiff_string_merge3
function. But xdiff_string_merge3
does not behave the same way as git and
xdiff may not be available on your system.
PhpMerge is a small library that solves this problem. There are two classes:
\PhpMerge\PhpMerge
and \PhpMerge\GitMerge
that implement the
\PhpMerge\PhpMergeInterface
which has just a merge
method.
PhpMerge
uses SebastianBergmann\Diff\Differ
to get the differences between
the different versions and calculates the merged text from it.
GitMerge
uses GitWrapper\GitWrapper
, writes the text to a temporary file
and uses the command line git to merge the text.
Usage
Simple example:
With merge conflicts:
Using the command line git to perform the merge:
Installation
PhpMerge can be installed with Composer by adding the library as a dependency to your composer.json file.
To use the command line git with GitMerge
:
Please refer to Composer's documentation for installation and usage instructions.
Difference to ~1.0
In the ~2.0 version we dropped support for php 5 and use php 7 constructs
instead. This means that the PhpMergeInterface
type-hints the arguments and
return type as strings. In addition to that all classes are now final and it
is clearer what the API is. We can consider making the classes inheritable if
needed without breaking the api but not the other way around.
If you have just been using the ~1.0 version as described in this document the version ~2.0 will continue to work.