mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 07:47:00 +02:00
Fix issue processwire/processwire-issues#1878
This commit is contained in:
@@ -1677,18 +1677,19 @@ class WireFileTools extends Wire {
|
|||||||
return $namespace;
|
return $namespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get everything that appears before "namespace" keyword
|
// find where line ends after "namespace ..." keyword
|
||||||
$head = substr($data, 0, $namespacePos);
|
foreach(array("\n", "\r", ";") as $c) {
|
||||||
$headPrev = $head;
|
$eol = strpos($data, $c, $namespacePos);
|
||||||
|
if($eol !== false) break;
|
||||||
// declare(...); is the one statement allowed to appear before namespace in PHP files
|
|
||||||
if(strpos($head, 'declare')) {
|
|
||||||
$head = preg_replace('/declare[ ]*\(.+?\)[ ]*;\s*/s', '', $head);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// single line comment(s) appear before namespace
|
||||||
if(strpos($head, '//') !== false) {
|
if(strpos($head, '//') !== false) {
|
||||||
$head = preg_replace('!//.*!', '', $head);
|
$head = preg_replace('!//[^\r\n]*!', '', $head);
|
||||||
}
|
}
|
||||||
|
|
||||||
// single or multi-line comments before namespace
|
// single or multi-line comments before namespace
|
||||||
@@ -1696,6 +1697,11 @@ class WireFileTools extends Wire {
|
|||||||
$head = preg_replace('!/\*.*\*/!s', '', $head);
|
$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
|
// replace cleaned up head in data
|
||||||
if($head !== $headPrev) {
|
if($head !== $headPrev) {
|
||||||
$data = str_replace($headPrev, $head, $data);
|
$data = str_replace($headPrev, $head, $data);
|
||||||
|
Reference in New Issue
Block a user