Fix parsing of large files that go over the PCRE limits

main
Jordi Boggiano 12 years ago
parent bd72e3765b
commit 75da832cd3

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

@ -52,6 +52,8 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php', 'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php',
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php', 'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.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()), array(__DIR__.'/Fixtures/template', array()),
); );

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save