public static function run($base, $user, $server) { // The three files for merging. $mergeBaseFile = uniqid(sys_get_temp_dir() . "/") . "mergebase.txt"; $userModificationFile = uniqid(sys_get_temp_dir() . "/") . "usermodification.txt"; $serverModificationFile = uniqid(sys_get_temp_dir() . "/") . "servermodification.txt"; $success = false; // Try a standard line-based merge. Should be sufficient for most cases. file_put_contents($mergeBaseFile, $base); file_put_contents($userModificationFile, $user); file_put_contents($serverModificationFile, $server); $exit_code = Filter_Merge::merge($mergeBaseFile, $userModificationFile, $serverModificationFile); $result = file_get_contents($userModificationFile); if ($exit_code == 0) { $success = true; } if (!$success) { // Convert the data to one word per line, and try to merge again. $baseWords = Filter_Merge::lines2words($base); $userWords = Filter_Merge::lines2words($user); $serverWords = Filter_Merge::lines2words($server); file_put_contents($mergeBaseFile, $baseWords); file_put_contents($userModificationFile, $userWords); file_put_contents($serverModificationFile, $serverWords); $exit_code = Filter_Merge::merge($mergeBaseFile, $userModificationFile, $serverModificationFile); $result = file_get_contents($userModificationFile); $result = Filter_Merge::words2lines($result); if ($exit_code == 0) { $success = true; } } if (!$success) { // Convert the data so it has one grapheme per line, and try again. $baseGraphemes = Filter_Merge::lines2graphemes($base); $userGraphemes = Filter_Merge::lines2graphemes($user); $serverGraphemes = Filter_Merge::lines2graphemes($server); file_put_contents($mergeBaseFile, $baseGraphemes); file_put_contents($userModificationFile, $userGraphemes); file_put_contents($serverModificationFile, $serverGraphemes); $exit_code = Filter_Merge::merge($mergeBaseFile, $userModificationFile, $serverModificationFile); $result = file_get_contents($userModificationFile); $result = Filter_Merge::graphemes2lines($result); if ($exit_code == 0) { $success = true; } } if (!$success) { // Everthing failed. Return the server data. $result = $server; } // Clear up. @unlink($mergeBaseFile); @unlink($userModificationFile); @unlink($serverModificationFile); // Merge result. return $result; }
public static function run($base, $user, $server) { $success = false; // Try a standard line-based merge. Should be sufficient for most cases. $result = Filter_Merge::merge($base, $user, $server); if ($result) { $success = true; } if (!$success) { // Convert the data to one word per line, and try to merge again. $baseWords = Filter_Merge::lines2words($base); $userWords = Filter_Merge::lines2words($user); $serverWords = Filter_Merge::lines2words($server); $result = Filter_Merge::merge($baseWords, $userWords, $serverWords); $result = Filter_Merge::words2lines($result); if ($result) { $success = true; } } if (!$success) { // Convert the data so it has one grapheme per line, and try again. $baseGraphemes = Filter_Merge::lines2graphemes($base); $userGraphemes = Filter_Merge::lines2graphemes($user); $serverGraphemes = Filter_Merge::lines2graphemes($server); $result = Filter_Merge::merge($baseGraphemes, $userGraphemes, $serverGraphemes); $result = Filter_Merge::graphemes2lines($result); if ($result) { $success = true; } } if (!$success) { // Everything failed. Return the server data. $result = $server; } // Merge result. return $result; }