|
19 | 19 |
|
20 | 20 | function php_strip_whitespace($file): string
|
21 | 21 | {
|
| 22 | + $lines = file($file, FILE_IGNORE_NEW_LINES); |
| 23 | + |
22 | 24 | // First pass, process inline comments
|
23 | 25 | // We need to rely on the LF chars here
|
24 |
| - $lines = file($file, FILE_IGNORE_NEW_LINES); |
25 | 26 | $lines = array_map(function ($line) {
|
26 | 27 | if (preg_match('!^//.*$!', $line)) {
|
27 | 28 | return null;
|
@@ -55,10 +56,19 @@ function php_strip_whitespace($file): string
|
55 | 56 | return true;
|
56 | 57 | });
|
57 | 58 |
|
58 |
| - $lines = implode(" ", $tokens); |
| 59 | + $text = implode(" ", $tokens); |
| 60 | + $text = preg_replace('/\s\s+/', ' ', $text); |
59 | 61 |
|
| 62 | + // Restore compatibility for heredoc blocks |
| 63 | + // NOTE: Line-breaks inside heredoc are not preserved |
| 64 | + preg_match("/.*<<<" . "'([A-Z]+)'/", $text, $m); |
| 65 | + for ($i = 1; $i < count($m); $i++) { |
| 66 | + $boundary = $m[$i]; |
| 67 | + $text = str_replace("<<<'$boundary'", "<<<'$boundary'\n", $text); |
| 68 | + $text = str_replace("$boundary;", "\n$boundary;\n", $text); |
| 69 | + } |
60 | 70 |
|
61 |
| - return preg_replace('/\s\s+/', ' ', $lines); |
| 71 | + return $text; |
62 | 72 | }
|
63 | 73 |
|
64 | 74 | class Phar extends BuiltinPhar
|
|
0 commit comments