diff --git a/src/main/php/xp/web/Source.class.php b/src/main/php/xp/web/Source.class.php index ded32086..0e232224 100755 --- a/src/main/php/xp/web/Source.class.php +++ b/src/main/php/xp/web/Source.class.php @@ -24,7 +24,13 @@ private function newInstance($application, $environment) { $cl= ClassLoader::getDefault(); try { - $class= is_file($application) ? $cl->loadUri($application) : $cl->loadClass($application); + if (is_file($application)) { + $class= $cl->loadUri($application); + } else if ($application[0] < 'a' || false !== strpos($application, '.')) { + $class= $cl->loadClass($application); + } else { + $class= $cl->loadClass("xp.{$application}.Web"); + } } catch (ClassLoadingException $e) { throw new IllegalArgumentException('Cannot load class '.$application, $e); } diff --git a/src/test/php/web/unittest/SourceTest.class.php b/src/test/php/web/unittest/SourceTest.class.php index 14931a6c..97c6ce9d 100755 --- a/src/test/php/web/unittest/SourceTest.class.php +++ b/src/test/php/web/unittest/SourceTest.class.php @@ -1,9 +1,9 @@ application()); } + #[Test] + public function application_class_in_global_namespace() { + $class= ClassLoader::defineClass('HelloWorld', Application::class, [], [ + 'routes' => function() { } + ]); + $src= new Source('HelloWorld', $this->environment); + Assert::instance($class, $src->application()); + } + #[Test] public function application_file() { - $base= XPClass::forName('web.unittest.HelloWorld')->getClassLoader()->path; + $base= ClassLoader::getDefault()->findClass(HelloWorld::class)->path; $src= new Source(new Path($base, 'web/unittest/HelloWorld.class.php'), $this->environment); Assert::instance(HelloWorld::class, $src->application()); } @@ -48,4 +57,14 @@ public function non_existant_class() { public function unrelated_class() { (new Source('util.Date', $this->environment))->application(); } + + #[Test] + public function lowercase_xp_namespaced_web_app() { + $class= ClassLoader::defineClass('xp.lambda.Web', Application::class, [], [ + 'routes' => function() { } + ]); + + $src= new Source('lambda', $this->environment); + Assert::instance($class, $src->application()); + } } \ No newline at end of file