Skip to content

Commit 854affb

Browse files
committed
(WIP) Experimental/Working Support heredocs
1 parent 5501ea3 commit 854affb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Phar.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
function php_strip_whitespace($file): string
2121
{
22+
$lines = file($file, FILE_IGNORE_NEW_LINES);
23+
2224
// First pass, process inline comments
2325
// We need to rely on the LF chars here
24-
$lines = file($file, FILE_IGNORE_NEW_LINES);
2526
$lines = array_map(function ($line) {
2627
if (preg_match('!^//.*$!', $line)) {
2728
return null;
@@ -55,10 +56,19 @@ function php_strip_whitespace($file): string
5556
return true;
5657
});
5758

58-
$lines = implode(" ", $tokens);
59+
$text = implode(" ", $tokens);
60+
$text = preg_replace('/\s\s+/', ' ', $text);
5961

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+
}
6070

61-
return preg_replace('/\s\s+/', ' ', $lines);
71+
return $text;
6272
}
6373

6474
class Phar extends BuiltinPhar

0 commit comments

Comments
 (0)