Skip to content

Instantly share code, notes, and snippets.

@gonzaloserrano
Created March 9, 2015 09:37
Show Gist options
  • Save gonzaloserrano/8ecdecb04179f688ef4b to your computer and use it in GitHub Desktop.
Save gonzaloserrano/8ecdecb04179f688ef4b to your computer and use it in GitHub Desktop.
<?php
require_once 'vendor/autoload.php';
$localTable = [
[ "A", "new_column_2" ],
[ "dfdf", null ],
[ null, null ],
[ "xxx", null ],
[ "yyy", null ],
[ null, null ],
[ "fd", null ],
[ "f", null ],
[ "d", null ],
[ "fdf", null ],
[ null, null ],
[ 4, null ],
[ 545, null ],
[ 4, null ],
[ 5, null ],
[ 4, null ],
[ 5, null ],
[ 45, null ],
[ 4, null ],
[ 54, null ],
[ 5, null ],
[ null, null ],
[ null, null ],
[ null, null ],
[ null, null ],
[ null, null ],
[ 454, null ],
[ null, null ],
[ null, null ],
[ 4, null ],
[ 5, null ]
];
$remoteTable = [
[ "A", "new_column_2" ],
[ "dfdf", null ],
[ null, null ],
[ "fd", null ],
[ "fd", null ],
[ null, null ],
[ "fd", null ],
[ "f", null ],
[ "d", null ],
[ "fdf", null ],
[ null, null ],
[ 4, null ],
[ 545, null ],
[ 4, null ],
[ 5, null ],
[ 4, null ],
[ 5, null ],
[ 45, null ],
[ 4, null ],
[ 54, null ],
[ 5, null ],
[ null, null ],
[ null, null ],
[ null, null ],
[ null, null ],
[ null, null ],
[ 454, null ],
[ null, null ],
[ null, null ],
[ 4, null ],
[ 5, null ]
];
$localTableView = new \coopy_PhpTableView($localTable);
$remoteTableView = new \coopy_PhpTableView($remoteTable);
$compareView = \coopy_Coopy::compareTables($localTableView, $remoteTableView);
// compute aligment
$alignment = $compareView->align();
// produce the diff
$tableDiffData = [];
$tableDiffView = new \coopy_PhpTableView($tableDiffData);
$flags = new \coopy_CompareFlags();
$flags->always_show_order = true;
$flags->never_show_order = false;
$highlighter = new \coopy_TableDiff($alignment, $flags);
$highlighter->hilite($tableDiffView);
$htmlDiffRender = new \coopy_DiffRender();
$htmlDiffRender->usePrettyArrows(false);
$htmlDiffRender->render($tableDiffView);
echo $htmlDiffRender->html();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment