1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-08 07:47:00 +02:00
This commit is contained in:
Ryan Cramer
2024-02-21 11:08:07 -05:00
parent 1f2d597f52
commit 47c639617c

View File

@@ -1677,18 +1677,19 @@ class WireFileTools extends Wire {
return $namespace;
}
// get everything that appears before "namespace" keyword
$head = substr($data, 0, $namespacePos);
$headPrev = $head;
// declare(...); is the one statement allowed to appear before namespace in PHP files
if(strpos($head, 'declare')) {
$head = preg_replace('/declare[ ]*\(.+?\)[ ]*;\s*/s', '', $head);
// find where line ends after "namespace ..." keyword
foreach(array("\n", "\r", ";") as $c) {
$eol = strpos($data, $c, $namespacePos);
if($eol !== false) break;
}
// get everything that appears before "namespace", and after "namespace" on same line
$head = $eol === false ? $data : substr($data, 0, $eol);
$headPrev = $head;
// single line comment(s) appear before namespace
if(strpos($head, '//') !== false) {
$head = preg_replace('!//.*!', '', $head);
$head = preg_replace('!//[^\r\n]*!', '', $head);
}
// single or multi-line comments before namespace
@@ -1696,6 +1697,11 @@ class WireFileTools extends Wire {
$head = preg_replace('!/\*.*\*/!s', '', $head);
}
// declare(...); is the one statement allowed to appear before namespace in PHP files
if(strpos($head, 'declare')) {
$head = preg_replace('/declare[ ]*\(.+?\)[ ]*;\s*/s', '', $head);
}
// replace cleaned up head in data
if($head !== $headPrev) {
$data = str_replace($headPrev, $head, $data);