Permalink
Browse files

[ClassCollectionLoader] fixed comment striping on classes in global n…

…amespace
  • Loading branch information...
1 parent 5d8ded6 commit e120518bb059dcf51b3a14000b4d6f7dcbe93194 @bamarni bamarni committed Jul 8, 2012
Showing with 8 additions and 36 deletions.
  1. +7 −36 ClassCollectionLoader.php
  2. +1 −0 composer.json
View
@@ -103,14 +103,16 @@ static public function load($classes, $cacheDir, $name, $autoReload, $adaptive =
$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()) {
- $c = "\nnamespace\n{\n".self::stripComments($c)."\n}\n";
- } else {
- $c = self::fixNamespaceDeclarations('<?php '.$c);
- $c = preg_replace('/^\s*<\?php/', '', $c);
+ $c = "\nnamespace;\n".$c."\n";
}
+ $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;
}
@@ -201,37 +203,6 @@ static private function writeCacheFile($file, $content)
}
/**
- * 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.
*
* @param array $classes
View
@@ -15,6 +15,7 @@
"homepage": "http://symfony.com/contributors"
}
],
+ "minimum-stability": "dev",
"require": {
"php": ">=5.3.3"
},

0 comments on commit e120518

Please sign in to comment.