bug #16668 [ClassLoader] Fix parsing namespace when token_get_all() is missing (nicolas-grekas)
This PR was merged into the 2.3 branch.
Discussion
----------
[ClassLoader] Fix parsing namespace when token_get_all() is missing
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #14871
| License | MIT
| Doc PR | -
Commits
-------
4a17c9e
[ClassLoader] Fix parsing namespace when token_get_all() is missing
This commit is contained in:
commit
27327d3e4d
@ -137,8 +137,8 @@ class ClassCollectionLoader
|
||||
public static function fixNamespaceDeclarations($source)
|
||||
{
|
||||
if (!function_exists('token_get_all') || !self::$useTokenizer) {
|
||||
if (preg_match('/namespace(.*?)\s*;/', $source)) {
|
||||
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
|
||||
if (preg_match('/(^|\s)namespace(.*?)\s*;/', $source)) {
|
||||
$source = preg_replace('/(^|\s)namespace(.*?)\s*;/', "$1namespace$2\n{", $source)."}\n";
|
||||
}
|
||||
|
||||
return $source;
|
||||
|
@ -205,7 +205,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
array("namespace Bar ;\nclass Foo {}\n", "namespace Bar\n{\nclass Foo {}\n}\n"),
|
||||
array("namespace Foo\Bar;\nclass Foo {}\n", "namespace Foo\Bar\n{\nclass Foo {}\n}\n"),
|
||||
array("namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n", "namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n"),
|
||||
array("namespace\n{\nclass Foo {}\n}\n", "namespace\n{\nclass Foo {}\n}\n"),
|
||||
array("\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n", "\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n"),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user