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:
@@ -1676,25 +1676,31 @@ class WireFileTools extends Wire {
|
|||||||
// note: this fails for PHP files executable on their own (like shell scripts)
|
// note: this fails for PHP files executable on their own (like shell scripts)
|
||||||
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) {
|
||||||
|
$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;
|
$headPrev = $head;
|
||||||
|
|
||||||
// declare(...); is the one statement allowed to appear before namespace in PHP files
|
// single line comment(s) appear before namespace
|
||||||
if(strpos($head, 'declare')) {
|
if(strpos($head, '//') !== false) {
|
||||||
$head = preg_replace('/declare[ ]*\(.+?\)[ ]*;\s*/s', '', $head);
|
$head = preg_replace('!//[^\r\n]*!', '', $head);
|
||||||
}
|
}
|
||||||
|
|
||||||
// single line comment(s) appear before namespace
|
|
||||||
if(strpos($head, '//') !== false) {
|
|
||||||
$head = preg_replace('!//.*!', '', $head);
|
|
||||||
}
|
|
||||||
|
|
||||||
// single or multi-line comments before namespace
|
// single or multi-line comments before namespace
|
||||||
if(strpos($head, '/' . '*') !== false) {
|
if(strpos($head, '/' . '*') !== false) {
|
||||||
$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) {
|
||||||
|
Reference in New Issue
Block a user