summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/generated/xdiff.php
blob: 27feef39f57b95100fde5fa8f6c7f9d7940c2c8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php

namespace Safe;

use Safe\Exceptions\XdiffException;

/**
 * Makes a binary diff of two files and stores the result in a patch file.
 * This function works with both text and binary files. Resulting patch
 * file can be later applied using xdiff_file_bpatch/xdiff_string_bpatch.
 *
 * @param string $old_file Path to the first file. This file acts as "old" file.
 * @param string $new_file Path to the second file. This file acts as "new" file.
 * @param string $dest Path of the resulting patch file. Resulting file contains differences
 * between "old" and "new" files. It is in binary format and is human-unreadable.
 * @throws XdiffException
 *
 */
function xdiff_file_bdiff(string $old_file, string $new_file, string $dest): void
{
    error_clear_last();
    $result = \xdiff_file_bdiff($old_file, $new_file, $dest);
    if ($result === false) {
        throw XdiffException::createFromPhpError();
    }
}


/**
 * Patches a file with a binary
 * patch and stores the result in a file dest.
 * This function accepts patches created both via xdiff_file_bdiff
 * and xdiff_file_rabdiff functions or their string counterparts.
 *
 * @param string $file The original file.
 * @param string $patch The binary patch file.
 * @param string $dest Path of the resulting file.
 * @throws XdiffException
 *
 */
function xdiff_file_bpatch(string $file, string $patch, string $dest): void
{
    error_clear_last();
    $result = \xdiff_file_bpatch($file, $patch, $dest);
    if ($result === false) {
        throw XdiffException::createFromPhpError();
    }
}


/**
 * Makes a binary diff of two files and stores the result in a patch file.
 * This function works with both text and binary files. Resulting patch
 * file can be later applied using xdiff_file_bpatch.
 *
 * Starting with version 1.5.0 this function is an alias of xdiff_file_bdiff.
 *
 * @param string $old_file Path to the first file. This file acts as "old" file.
 * @param string $new_file Path to the second file. This file acts as "new" file.
 * @param string $dest Path of the resulting patch file. Resulting file contains differences
 * between "old" and "new" files. It is in binary format and is human-unreadable.
 * @throws XdiffException
 *
 */
function xdiff_file_diff_binary(string $old_file, string $new_file, string $dest): void
{
    error_clear_last();
    $result = \xdiff_file_diff_binary($old_file, $new_file, $dest);
    if ($result === false) {
        throw XdiffException::createFromPhpError();
    }
}


/**
 * Makes an unified diff containing differences between old_file and
 * new_file and stores it in dest file. The
 * resulting file is human-readable. An optional context parameter
 * specifies how many lines of context should be added around each change.
 * Setting minimal parameter to true will result in outputting the shortest
 * patch file possible (can take a long time).
 *
 * @param string $old_file Path to the first file. This file acts as "old" file.
 * @param string $new_file Path to the second file. This file acts as "new" file.
 * @param string $dest Path of the resulting patch file.
 * @param int $context Indicates how many lines of context you want to include in diff
 * result.
 * @param bool $minimal Set this parameter to TRUE if you want to minimalize size of the result
 * (can take a long time).
 * @throws XdiffException
 *
 */
function xdiff_file_diff(string $old_file, string $new_file, string $dest, int $context = 3, bool $minimal = false): void
{
    error_clear_last();
    $result = \xdiff_file_diff($old_file, $new_file, $dest, $context, $minimal);
    if ($result === false) {
        throw XdiffException::createFromPhpError();
    }
}


/**
 * Patches a file with a binary
 * patch and stores the result in a file dest.
 * This function accepts patches created both via xdiff_file_bdiff
 * or xdiff_file_rabdiff functions or their string counterparts.
 *
 * Starting with version 1.5.0 this function is an alias of xdiff_file_bpatch.
 *
 * @param string $file The original file.
 * @param string $patch The binary patch file.
 * @param string $dest Path of the resulting file.
 * @throws XdiffException
 *
 */
function xdiff_file_patch_binary(string $file, string $patch, string $dest): void
{
    error_clear_last();
    $result = \xdiff_file_patch_binary($file, $patch, $dest);
    if ($result === false) {
        throw XdiffException::createFromPhpError();
    }
}


/**
 * Makes a binary diff of two files and stores the result in a patch file.
 * The difference between this function and xdiff_file_bdiff is different
 * algorithm used which should result in faster execution and smaller diff produced.
 * This function works with both text and binary files. Resulting patch
 * file can be later applied using xdiff_file_bpatch/xdiff_string_bpatch.
 *
 * For more details about differences between algorithm used please check libxdiff
 * website.
 *
 * @param string $old_file Path to the first file. This file acts as "old" file.
 * @param string $new_file Path to the second file. This file acts as "new" file.
 * @param string $dest Path of the resulting patch file. Resulting file contains differences
 * between "old" and "new" files. It is in binary format and is human-unreadable.
 * @throws XdiffException
 *
 */
function xdiff_file_rabdiff(string $old_file, string $new_file, string $dest): void
{
    error_clear_last();
    $result = \xdiff_file_rabdiff($old_file, $new_file, $dest);
    if ($result === false) {
        throw XdiffException::createFromPhpError();
    }
}


/**
 * Patches a string str with a binary patch.
 * This function accepts patches created both via xdiff_string_bdiff
 * and xdiff_string_rabdiff functions or their file counterparts.
 *
 * @param string $str The original binary string.
 * @param string $patch The binary patch string.
 * @return string Returns the patched string.
 * @throws XdiffException
 *
 */
function xdiff_string_bpatch(string $str, string $patch): string
{
    error_clear_last();
    $result = \xdiff_string_bpatch($str, $patch);
    if ($result === false) {
        throw XdiffException::createFromPhpError();
    }
    return $result;
}


/**
 * Patches a string str with a binary patch.
 * This function accepts patches created both via xdiff_string_bdiff
 * and xdiff_string_rabdiff functions or their file counterparts.
 *
 * Starting with version 1.5.0 this function is an alias of xdiff_string_bpatch.
 *
 * @param string $str The original binary string.
 * @param string $patch The binary patch string.
 * @return string Returns the patched string.
 * @throws XdiffException
 *
 */
function xdiff_string_patch_binary(string $str, string $patch): string
{
    error_clear_last();
    $result = \xdiff_string_patch_binary($str, $patch);
    if ($result === false) {
        throw XdiffException::createFromPhpError();
    }
    return $result;
}


/**
 * Patches a str string with an unified patch in patch parameter
 * and returns the result. patch has to be an unified diff created by
 * xdiff_file_diff/xdiff_string_diff function.
 * An optional flags parameter specifies mode of operation. Any
 * rejected parts of the patch will be stored inside error variable if
 * it is provided.
 *
 * @param string $str The original string.
 * @param string $patch The unified patch string. It has to be created using xdiff_string_diff,
 * xdiff_file_diff functions or compatible tools.
 * @param int $flags flags can be either
 * XDIFF_PATCH_NORMAL (default mode, normal patch)
 * or XDIFF_PATCH_REVERSE (reversed patch).
 *
 * Starting from version 1.5.0, you can also use binary OR to enable
 * XDIFF_PATCH_IGNORESPACE flag.
 * @param string|null $error If provided then rejected parts are stored inside this variable.
 * @return string Returns the patched string.
 * @throws XdiffException
 *
 */
function xdiff_string_patch(string $str, string $patch, int $flags = null, ?string &$error = null): string
{
    error_clear_last();
    if ($error !== null) {
        $result = \xdiff_string_patch($str, $patch, $flags, $error);
    } elseif ($flags !== null) {
        $result = \xdiff_string_patch($str, $patch, $flags);
    } else {
        $result = \xdiff_string_patch($str, $patch);
    }
    if ($result === false) {
        throw XdiffException::createFromPhpError();
    }
    return $result;
}