[ClassCollectionLoader] fixed comment striping on classes in global namespace
This commit is contained in:
parent
b34bdd4639
commit
6c9c2ec1f3
@ -103,14 +103,16 @@ class ClassCollectionLoader
|
|||||||
|
|
||||||
$c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($class->getFileName()));
|
$c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($class->getFileName()));
|
||||||
|
|
||||||
// add namespace declaration for global code
|
// fakes namespace declaration for global code
|
||||||
if (!$class->inNamespace()) {
|
if (!$class->inNamespace()) {
|
||||||
$c = "\nnamespace\n{\n".self::stripComments($c)."\n}\n";
|
$c = "\nnamespace;\n".$c."\n";
|
||||||
} else {
|
|
||||||
$c = self::fixNamespaceDeclarations('<?php '.$c);
|
|
||||||
$c = preg_replace('/^\s*<\?php/', '', $c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$c = self::fixNamespaceDeclarations('<?php '.$c);
|
||||||
|
$c = preg_replace('/^\s*<\?php/', '', $c);
|
||||||
|
// replace multiple new lines with a single newline
|
||||||
|
$c = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $c);
|
||||||
|
|
||||||
$content .= $c;
|
$content .= $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,37 +202,6 @@ class ClassCollectionLoader
|
|||||||
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
|
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes comments from a PHP source string.
|
|
||||||
*
|
|
||||||
* We don't use the PHP php_strip_whitespace() function
|
|
||||||
* as we want the content to be readable and well-formatted.
|
|
||||||
*
|
|
||||||
* @param string $source A PHP string
|
|
||||||
*
|
|
||||||
* @return string The PHP string with the comments removed
|
|
||||||
*/
|
|
||||||
static private function stripComments($source)
|
|
||||||
{
|
|
||||||
if (!function_exists('token_get_all')) {
|
|
||||||
return $source;
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = '';
|
|
||||||
foreach (token_get_all($source) as $token) {
|
|
||||||
if (is_string($token)) {
|
|
||||||
$output .= $token;
|
|
||||||
} elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
|
|
||||||
$output .= $token[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// replace multiple new lines with a single newline
|
|
||||||
$output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an ordered array of passed classes including all their dependencies.
|
* Gets an ordered array of passed classes including all their dependencies.
|
||||||
*
|
*
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
"homepage": "http://symfony.com/contributors"
|
"homepage": "http://symfony.com/contributors"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"minimum-stability": "dev",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.3"
|
"php": ">=5.3.3"
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user