diff --git a/src/main/php/lang/ClassLoader.class.php b/src/main/php/lang/ClassLoader.class.php index 42e1f3c7d..933798861 100755 --- a/src/main/php/lang/ClassLoader.class.php +++ b/src/main/php/lang/ClassLoader.class.php @@ -1,7 +1,6 @@ instanceId()])) continue; - self::$delegates[$cl->instanceId()]= $cl; - if ($cl->providesResource('module.xp')) $modules[]= $cl; + $id= $cl->instanceId(); + if (isset(self::$delegates[$id])) continue; + + self::$delegates[$id]= $cl; + if ($cl->providesResource('module.xp')) $modules[$id]= $cl; } // Initialize modules \xp::$loader= new self(); - foreach ($modules as $cl) { - self::$modules[$cl->instanceId()]= Module::register(self::declareModule($cl)); + foreach ($modules as $id => $cl) { + self::$modules[$id]= Module::register(self::declareModule($cl)); } } @@ -110,7 +111,7 @@ public static function registerPath($element, $before= false) { public static function registerLoader(IClassLoader $l, $before= false) { $id= $l->instanceId(); if ($before) { - self::$delegates= array_merge([$id => $l], self::$delegates); + self::$delegates= [$id => $l] + self::$delegates; } else { self::$delegates[$id]= $l; } @@ -149,7 +150,7 @@ public static function declareModule($l) { if (strstr($m[2], 'extends')) { $parent= $m[2]; } else { - $parent= ' extends \lang\reflect\Module '.$m[2]; + $parent= ' extends \lang\Module '.$m[2]; } $dyn= DynamicClassLoader::instanceFor('modules'); diff --git a/src/main/php/lang/reflect/Module.class.php b/src/main/php/lang/Module.class.php similarity index 96% rename from src/main/php/lang/reflect/Module.class.php rename to src/main/php/lang/Module.class.php index cf05ee5ae..188132896 100755 --- a/src/main/php/lang/reflect/Module.class.php +++ b/src/main/php/lang/Module.class.php @@ -1,6 +1,4 @@ -registered[]= ClassLoader::registerLoader($l); + return $l; } - #[After] - public function tearDown() { + /** + * Removes all registered loaders + * + * @return void + */ + public function remove() { foreach ($this->registered as $l) { ClassLoader::removeLoader($l); } @@ -29,7 +33,7 @@ public function simple_module() { try { $this->register(new LoaderProviding(['module.xp' => 'module xp-framework/simple { }'])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -38,7 +42,7 @@ public function leading_php_tag_is_stripped() { try { $this->register(new LoaderProviding(['module.xp' => 'tearDown(); + $this->remove(); } } @@ -47,7 +51,7 @@ public function leading_and_trailing_php_tags_are_stripped() { try { $this->register(new LoaderProviding(['module.xp' => ''])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -56,7 +60,7 @@ public function trailing_php_tag_is_stripped() { try { $this->register(new LoaderProviding(['module.xp' => 'module xp-framework/tagend { } ?>'])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -68,7 +72,7 @@ public function module_in_namespace() { }'])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -77,7 +81,7 @@ public function empty_module_file() { try { $this->register(new LoaderProviding(['module.xp' => ''])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -86,18 +90,17 @@ public function module_without_name() { try { $this->register(new LoaderProviding(['module.xp' => 'module { }'])); } finally { - $this->tearDown(); + $this->remove(); } } #[Test] public function loaded_module() { try { - $cl= new LoaderProviding(['module.xp' => 'module xp-framework/loaded { }']); - $this->register($cl); + $cl= $this->register(new LoaderProviding(['module.xp' => 'module xp-framework/loaded { }'])); Assert::equals(new Module('xp-framework/loaded', $cl), Module::forName('xp-framework/loaded')); } finally { - $this->tearDown(); + $this->remove(); } } @@ -113,7 +116,7 @@ public function initialize() { }'])); Assert::equals(true, Module::forName('xp-framework/initialized')->initialized); } finally { - $this->tearDown(); + $this->remove(); } } @@ -135,7 +138,7 @@ public function initialized() { $this->register($tracksInit); Assert::equals(1, Module::forName('xp-framework/tracks-init')->initialized()); } finally { - $this->tearDown(); + $this->remove(); } } @@ -148,7 +151,7 @@ public function module_inheritance() { ])); Assert::equals($cl, new XPClass(typeof(Module::forName('xp-framework/child'))->reflect()->getParentclass())); } finally { - $this->tearDown(); + $this->remove(); } } @@ -161,21 +164,20 @@ public function module_implementation() { ])); Assert::true(typeof(Module::forName('xp-framework/impl'))->reflect()->isSubclassOf($cl->reflect())); } finally { - $this->tearDown(); + $this->remove(); } } #[Test] public function modules_initializer_can_register_itself_upfront_without_causing_endless_recursion() { try { - $selfUpfront= new LoaderProviding(['module.xp' => 'module xp-framework/self-upfront { + $this->register(new LoaderProviding(['module.xp' => 'module xp-framework/self-upfront { public function initialize() { \lang\ClassLoader::registerLoader($this->classLoader(), true); } - }']); - $this->register($selfUpfront); + }'])); } finally { - $this->tearDown(); + $this->remove(); } } } \ No newline at end of file diff --git a/src/test/php/lang/unittest/ModuleTest.class.php b/src/test/php/lang/unittest/ModuleTest.class.php index 5fa0947ec..72c9304c7 100755 --- a/src/test/php/lang/unittest/ModuleTest.class.php +++ b/src/test/php/lang/unittest/ModuleTest.class.php @@ -1,7 +1,6 @@ ', + 'lang.Module', (new Module('xp-framework/test', $this->cl))->toString() ); }