Permalink
Browse files

[ClassLoader] fixed unbracketed namespaces (closes #5747)

  • Loading branch information...
1 parent 475b92b commit c393e86a03dca1f65d0367b009593ee4ec3f4abb @fabpot fabpot committed Oct 27, 2012
Showing with 14 additions and 1 deletion.
  1. +14 −1 ClassCollectionLoader.php
View
@@ -19,6 +19,7 @@
class ClassCollectionLoader
{
private static $loaded;
+ private static $useTokenizer = true;
/**
* Loads a list of classes and caches them in one big file.
@@ -125,7 +126,11 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
*/
public static function fixNamespaceDeclarations($source)
{
- if (!function_exists('token_get_all')) {
+ if (!function_exists('token_get_all') || !self::$useTokenizer) {
+ if (preg_match('/namespace(.*?)\s*;/', $source)) {
+ $source = preg_replace('/namespace(.*?)(\s*);/', "namespace$1$2\n{", $source)."}\n";
+ }
+
return $source;
}
@@ -219,4 +224,12 @@ private static function stripComments($source)
return $output;
}
+
+ /**
+ * This method is only useful for testing.
+ */
+ public static function enableTokenizer($bool)
+ {
+ self::$useTokenizer = (Boolean) $bool;
+ }
}

0 comments on commit c393e86

Please sign in to comment.