Permalink
Browse files

Fix parsing of large files that go over the PCRE limits

  • Loading branch information...
1 parent bd72e37 commit 75da832cd39041fedd512a68ca72fa31dd02ec9c @Seldaek Seldaek committed Nov 12, 2012
@@ -116,19 +116,19 @@ private static function findClasses($path)
$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 = '';
@@ -52,6 +52,8 @@ public function getTestCreateMapTests()
'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()),
);
Oops, something went wrong.

0 comments on commit 75da832

Please sign in to comment.