2017 © Pedro Peláez
 

library merge

Library used to perform merges between normalized array structures.

image

relaxedws/merge

Library used to perform merges between normalized array structures.

  • Monday, June 20, 2016
  • by dickolsson
  • Repository
  • 2 Watchers
  • 3 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Relaxedws/merge Build Status

A Library to perform recursive 3-way merge algorithm on associative arrays, written in PHP., (*1)

Insight

This library is built to perform a recursive 3-way merge algorithm. It takes 3 parameters which are arrays representing base array, local array and remote array. It compares each of these entities with other arrays line-wise. If only one out of remote or local is updated out of these 3, the final revision will have all the unchanged data in it along with the update data from the update array (Either remote or local). If more than one array is updated on the same line, it'd throw a ConflictException., (*2)

Install

The library can be installed via composer., (*3)

{
  "name": "myorg/mylib",
  "description": "A library depending on 3-way merge",
  "require": {
    "relaxedws/merge": "dev-master",
  }
}

Example

After installation, we can perform a merge the following way:, (*4)

<?php

namespace testing;

require __DIR__ ."/vendor/autoload.php";

use Relaxed\Merge\ThreeWayMerge;

$original = [
    'keyA' => [
        0 => [
            'keyB' => 'This is honey
            like this',
            'keyC' => 'This is however, not apple',
        ],
        1 => [
            'keyB' => 'This is milk',
            'keyC' => 'This is mango',
        ],
        2 => 'a little sugar',
    ]
];
$local = [
    'keyA' => [
        0 => [
            'keyB' => 'This is honeybb
            like ti',
            'keyC' => 'This is however, not apple',
        ],
        1 => [
            'keyB' => 'This is milky milky',
            'keyC' => 'This is mango',
        ],
        2 => 'a little coffee'
    ]
];
$remote = [
    'keyA' => [
        0 => [
            'keyB' => 'This is honey
            like this',
            'keyC' => 'This is however, not apple',
        ],
        1 => [
            'keyB' => 'This is milk',
            'keyC' => 'This is changed because of remote',
        ],
        2 => 'a little sugar',
    ]
];

$merge = new ThreeWayMerge();
$updated_revision = $merge->performMerge($original, $local, $remote);

Contributing

We welcome anyone to use, test, or contribute back to this project. We have extensive test coverage, but as we all know there's always bugs in software. Please file issues or pull requests with your comments or suggestions., (*5)

The Versions

20/06 2016

dev-master

9999999-dev

Library used to perform merges between normalized array structures.

  Sources   Download

The Development Requires