From 796937e14658131e51cb0ae6634e1367bd60a04b Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 23 Aug 2026 18:56:32 +0200 Subject: [PATCH 1/7] Move Module class to lang namespace --- src/main/php/lang/ClassLoader.class.php | 3 +-- src/main/php/lang/{reflect => }/Module.class.php | 4 +--- src/test/php/lang/unittest/ModuleLoadingTest.class.php | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) rename src/main/php/lang/{reflect => }/Module.class.php (96%) diff --git a/src/main/php/lang/ClassLoader.class.php b/src/main/php/lang/ClassLoader.class.php index 42e1f3c7d..1e9b94314 100755 --- a/src/main/php/lang/ClassLoader.class.php +++ b/src/main/php/lang/ClassLoader.class.php @@ -1,7 +1,6 @@ Date: Sun, 23 Aug 2026 19:02:43 +0200 Subject: [PATCH 2/7] Use lang.Module --- src/main/php/xp/runtime/Modules.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/php/xp/runtime/Modules.class.php b/src/main/php/xp/runtime/Modules.class.php index 66f06b9b4..7d4cfe863 100755 --- a/src/main/php/xp/runtime/Modules.class.php +++ b/src/main/php/xp/runtime/Modules.class.php @@ -1,7 +1,6 @@ Date: Sun, 23 Aug 2026 19:05:10 +0200 Subject: [PATCH 3/7] Fix import in tests --- src/test/php/lang/unittest/ModuleTest.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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() ); } From 4c68e5e886daf7540d87534e8ef0b24f783e4e1f Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 23 Aug 2026 20:11:35 +0200 Subject: [PATCH 4/7] Improve static initializer performance --- src/main/php/lang/ClassLoader.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/php/lang/ClassLoader.class.php b/src/main/php/lang/ClassLoader.class.php index 1e9b94314..7bafc2578 100755 --- a/src/main/php/lang/ClassLoader.class.php +++ b/src/main/php/lang/ClassLoader.class.php @@ -52,16 +52,18 @@ static function __static() { } else { $cl= ArchiveClassLoader::instanceFor($element, false); } - if (isset(self::$delegates[$cl->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)); } } From 7d8bd009ea8c63672e232f28897f3405d33ca0d6 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 23 Aug 2026 20:18:43 +0200 Subject: [PATCH 5/7] QA: Performance improvement in registerLoader() --- src/main/php/lang/ClassLoader.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/php/lang/ClassLoader.class.php b/src/main/php/lang/ClassLoader.class.php index 7bafc2578..933798861 100755 --- a/src/main/php/lang/ClassLoader.class.php +++ b/src/main/php/lang/ClassLoader.class.php @@ -111,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; } From 727aa0185596916a15d4512c8e4d6893c02ae5a8 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 23 Aug 2026 20:25:07 +0200 Subject: [PATCH 6/7] QA: Rename tearDown() -> remove() to clarify purpose --- .../lang/unittest/ModuleLoadingTest.class.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/php/lang/unittest/ModuleLoadingTest.class.php b/src/test/php/lang/unittest/ModuleLoadingTest.class.php index e4c49bc07..acadbd3be 100755 --- a/src/test/php/lang/unittest/ModuleLoadingTest.class.php +++ b/src/test/php/lang/unittest/ModuleLoadingTest.class.php @@ -17,7 +17,7 @@ protected function register($l) { } #[After] - public function tearDown() { + public function remove() { foreach ($this->registered as $l) { ClassLoader::removeLoader($l); } @@ -28,7 +28,7 @@ public function simple_module() { try { $this->register(new LoaderProviding(['module.xp' => 'module xp-framework/simple { }'])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -37,7 +37,7 @@ public function leading_php_tag_is_stripped() { try { $this->register(new LoaderProviding(['module.xp' => 'tearDown(); + $this->remove(); } } @@ -46,7 +46,7 @@ public function leading_and_trailing_php_tags_are_stripped() { try { $this->register(new LoaderProviding(['module.xp' => ''])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -55,7 +55,7 @@ public function trailing_php_tag_is_stripped() { try { $this->register(new LoaderProviding(['module.xp' => 'module xp-framework/tagend { } ?>'])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -67,7 +67,7 @@ public function module_in_namespace() { }'])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -76,7 +76,7 @@ public function empty_module_file() { try { $this->register(new LoaderProviding(['module.xp' => ''])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -85,7 +85,7 @@ public function module_without_name() { try { $this->register(new LoaderProviding(['module.xp' => 'module { }'])); } finally { - $this->tearDown(); + $this->remove(); } } @@ -96,7 +96,7 @@ public function loaded_module() { $this->register($cl); Assert::equals(new Module('xp-framework/loaded', $cl), Module::forName('xp-framework/loaded')); } finally { - $this->tearDown(); + $this->remove(); } } @@ -112,7 +112,7 @@ public function initialize() { }'])); Assert::equals(true, Module::forName('xp-framework/initialized')->initialized); } finally { - $this->tearDown(); + $this->remove(); } } @@ -134,7 +134,7 @@ public function initialized() { $this->register($tracksInit); Assert::equals(1, Module::forName('xp-framework/tracks-init')->initialized()); } finally { - $this->tearDown(); + $this->remove(); } } @@ -147,7 +147,7 @@ public function module_inheritance() { ])); Assert::equals($cl, new XPClass(typeof(Module::forName('xp-framework/child'))->reflect()->getParentclass())); } finally { - $this->tearDown(); + $this->remove(); } } @@ -160,7 +160,7 @@ public function module_implementation() { ])); Assert::true(typeof(Module::forName('xp-framework/impl'))->reflect()->isSubclassOf($cl->reflect())); } finally { - $this->tearDown(); + $this->remove(); } } @@ -174,7 +174,7 @@ public function initialize() { }']); $this->register($selfUpfront); } finally { - $this->tearDown(); + $this->remove(); } } } \ No newline at end of file From 3f31d02c35d64295d28e0ac04f1f15c88cb3e6e2 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 23 Aug 2026 20:37:45 +0200 Subject: [PATCH 7/7] QA: Simplify test code --- .../lang/unittest/ModuleLoadingTest.class.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/test/php/lang/unittest/ModuleLoadingTest.class.php b/src/test/php/lang/unittest/ModuleLoadingTest.class.php index acadbd3be..a1f58cedd 100755 --- a/src/test/php/lang/unittest/ModuleLoadingTest.class.php +++ b/src/test/php/lang/unittest/ModuleLoadingTest.class.php @@ -4,19 +4,24 @@ use test\{After, Assert, Expect, Test}; class ModuleLoadingTest { - protected $registered= []; + private $registered= []; /** * Register a loader with the CL * * @param lang.IClassLoader $l - * @return void + * @return lang.IClassLoader */ - protected function register($l) { + private function register($l) { $this->registered[]= ClassLoader::registerLoader($l); + return $l; } - #[After] + /** + * Removes all registered loaders + * + * @return void + */ public function remove() { foreach ($this->registered as $l) { ClassLoader::removeLoader($l); @@ -92,8 +97,7 @@ public function module_without_name() { #[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->remove(); @@ -167,12 +171,11 @@ public function module_implementation() { #[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->remove(); }