1
0
Fork 0

Fix parsing of large files that go over the PCRE limits

pull/1328/head
Jordi Boggiano 2012-11-12 12:26:03 +01:00
parent bd72e3765b
commit 75da832cd3
4 changed files with 2784 additions and 6 deletions

View File

@ -116,19 +116,19 @@ class ClassMapGenerator
$contents = preg_replace('{<<<\'?(\w+)\'?(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)\\1(?=\r\n|\n|\r|;)}s', 'null', $contents);
// strip strings
$contents = preg_replace('{"[^"\\\\]*(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(\\\\.[^\'\\\\]*)*\'}', 'null', $contents);
// keep only php code
$phpContents = preg_match_all('{<\?(?:php)?(.*)\?>}s', $contents, $m) ? join($m[1], ' ') : '';
$contents = preg_replace('{<\?(php)?.*\?>}s', '', $contents);
if (preg_match('{<\?(?:php)?(.*)}s', $contents, $m)) {
$phpContents .= ' ' . $m[1];
// strip leading non-php code if needed
if (substr($contents, 0, 2) !== '<?') {
$contents = preg_replace('{^.+?<\?}s', '<?', $contents);
}
// strip non-php blocks in the file
$contents = preg_replace('{\?>.*<\?}s', '', $contents);
preg_match_all('{
(?:
\b(?<![\$:>])(?<type>class|interface'.$traits.') \s+ (?<name>\S+)
| \b(?<![\$:>])(?<ns>namespace) (?<nsname>\s+[^\s;{}\\\\]+(?:\s*\\\\\s*[^\s;{}\\\\]+)*)? \s*[\{;]
)
}ix', $phpContents, $matches);
}ix', $contents, $matches);
$classes = array();
$namespace = '';

View File

@ -52,6 +52,8 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php',
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
'Foo\\LargeClass' => realpath(__DIR__).'/Fixtures/classmap/LargeClass.php',
'Foo\\LargeGap' => realpath(__DIR__).'/Fixtures/classmap/LargeGap.php',
)),
array(__DIR__.'/Fixtures/template', array()),
);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff