mirror of
https://github.com/processwire/processwire.git
synced 2025-08-07 23:38:29 +02:00
Fix issue processwire/processwire-issues#1878
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user