Created
February 6, 2013 10:03
-
-
Save thekid/4721573 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/core/src/main/php/lang/AbstractClassLoader.class.php b/core/src/main/php/lang/AbstractClassLoader.class.php | |
| index 2b81b01..2992162 100644 | |
| --- a/core/src/main/php/lang/AbstractClassLoader.class.php | |
| +++ b/core/src/main/php/lang/AbstractClassLoader.class.php | |
| @@ -19,11 +19,12 @@ | |
| * Load the class by the specified name | |
| * | |
| * @param string class fully qualified class name io.File | |
| + * @param string intent default NULL what kind of class we're looking for | |
| * @return lang.XPClass | |
| * @throws lang.ClassNotFoundException in case the class can not be found | |
| */ | |
| - public function loadClass($class) { | |
| - return new XPClass($this->loadClass0($class)); | |
| + public function loadClass($class, $intent= NULL) { | |
| + return new XPClass($this->loadClass0($class, $intent)); | |
| } | |
| /** | |
| @@ -38,11 +39,12 @@ | |
| * Load the class by the specified name | |
| * | |
| * @param string class fully qualified class name io.File | |
| + * @param string intent default NULL what kind of class we're looking for | |
| * @return string class name | |
| * @throws lang.ClassNotFoundException in case the class can not be found | |
| * @throws lang.ClassFormatException in case the class format is invalud | |
| */ | |
| - public function loadClass0($class) { | |
| + public function loadClass0($class, $intent= NULL) { | |
| if (isset(xp::$registry['classloader.'.$class])) return xp::reflect($class); | |
| // Load class | |
| diff --git a/core/src/main/php/lang/ClassLoader.class.php b/core/src/main/php/lang/ClassLoader.class.php | |
| index ac65aac..ce49ed7 100644 | |
| --- a/core/src/main/php/lang/ClassLoader.class.php | |
| +++ b/core/src/main/php/lang/ClassLoader.class.php | |
| @@ -327,16 +327,17 @@ | |
| * Loads a class | |
| * | |
| * @param string class fully qualified class name | |
| + * @param string intent default NULL what kind of class we're looking for | |
| * @return string class name of class loaded | |
| * @throws lang.ClassNotFoundException in case the class can not be found | |
| * @throws lang.ClassFormatException in case the class format is invalud | |
| */ | |
| - public function loadClass0($class) { | |
| + public function loadClass0($class, $intent= NULL) { | |
| if (isset(xp::$registry['classloader.'.$class])) return xp::reflect($class); | |
| // Ask delegates | |
| foreach (self::$delegates as $delegate) { | |
| - if ($delegate->providesClass($class)) return $delegate->loadClass0($class); | |
| + if ($delegate->providesClass($class)) return $delegate->loadClass0($class, $intent); | |
| } | |
| throw new ClassNotFoundException($class, self::getLoaders()); | |
| } | |
| @@ -410,11 +411,12 @@ | |
| * Load the class by the specified name | |
| * | |
| * @param string class fully qualified class name | |
| + * @param string intent default NULL what kind of class we're looking for | |
| * @return lang.XPClass | |
| * @throws lang.ClassNotFoundException in case the class can not be found | |
| */ | |
| - public function loadClass($class) { | |
| - return new XPClass($this->loadClass0($class)); | |
| + public function loadClass($class, $intent= NULL) { | |
| + return new XPClass($this->loadClass0($class, $intent)); | |
| } | |
| /** | |
| diff --git a/core/src/main/php/lang/IClassLoader.class.php b/core/src/main/php/lang/IClassLoader.class.php | |
| index e52d5a3..8f97dd5 100644 | |
| --- a/core/src/main/php/lang/IClassLoader.class.php | |
| +++ b/core/src/main/php/lang/IClassLoader.class.php | |
| @@ -49,19 +49,21 @@ | |
| * Load the class by the specified name | |
| * | |
| * @param string class fully qualified class name io.File | |
| + * @param string intent default NULL what kind of class we're looking for | |
| * @return lang.XPClass | |
| * @throws lang.ClassNotFoundException in case the class can not be found | |
| */ | |
| - public function loadClass($class); | |
| + public function loadClass($class, $intent= NULL); | |
| /** | |
| * Load the class by the specified name | |
| * | |
| * @param string class fully qualified class name io.File | |
| + * @param string intent default NULL what kind of class we're looking for | |
| * @return string class name | |
| * @throws lang.ClassNotFoundException in case the class can not be found | |
| */ | |
| - public function loadClass0($class); | |
| + public function loadClass0($class, $intent= NULL); | |
| /** | |
| * Loads a resource. | |
| diff --git a/core/src/main/php/lang/Module.class.php b/core/src/main/php/lang/Module.class.php | |
| index 34aa0cd..5aea540 100644 | |
| --- a/core/src/main/php/lang/Module.class.php | |
| +++ b/core/src/main/php/lang/Module.class.php | |
| @@ -107,26 +107,31 @@ | |
| * Load the class by the specified name | |
| * | |
| * @param string class fully qualified class name io.File | |
| + * @param string intent default NULL what kind of class we're looking for | |
| * @return lang.XPClass | |
| * @throws lang.ClassNotFoundException in case the class can not be found | |
| */ | |
| - public function loadClass($class) { | |
| - foreach ($this->delegates as $l) { | |
| - if ($l->providesClass($class)) return $l->loadClass($class); | |
| - } | |
| - throw new ClassNotFoundException('Cannot find class '.$class); | |
| + public function loadClass($class, $intent= NULL) { | |
| + return new XPClass($this->loadClass0($class, $intent)); | |
| } | |
| /** | |
| * Load the class by the specified name | |
| * | |
| * @param string class fully qualified class name io.File | |
| + * @param string intent default NULL what kind of class we're looking for | |
| * @return string class name | |
| * @throws lang.ClassNotFoundException in case the class can not be found | |
| */ | |
| - public function loadClass0($class) { | |
| - foreach ($this->delegates as $l) { | |
| - if ($l->providesClass($class)) return $l->loadClass0($class); | |
| + public function loadClass0($class, $intent= NULL) { | |
| + $delegates= $this->delegates; | |
| + if (isset($delegates[$intent])) { // Ask this delegate first! | |
| + $l= $delegates[$intent]; | |
| + if ($l->providesClass($class)) return $l->loadClass0($class, $intent); | |
| + unset($delegates[$intent]); | |
| + } | |
| + foreach ($delegates as $l) { | |
| + if ($l->providesClass($class)) return $l->loadClass0($class, $intent); | |
| } | |
| throw new ClassNotFoundException('Cannot find class '.$class); | |
| } | |
| diff --git a/core/src/main/php/xp/unittest/Runner.class.php b/core/src/main/php/xp/unittest/Runner.class.php | |
| index 022988c..9102caa 100644 | |
| --- a/core/src/main/php/xp/unittest/Runner.class.php | |
| +++ b/core/src/main/php/xp/unittest/Runner.class.php | |
| @@ -210,6 +210,7 @@ | |
| // Parse arguments | |
| $sources= new Vector(); | |
| $listener= TestListeners::$DEFAULT; | |
| + $cl= ClassLoader::getDefault(); | |
| $arguments= array(); | |
| $colors= NULL; | |
| $cmap= array( | |
| @@ -303,7 +304,7 @@ | |
| } else if (is_dir($args[$i])) { | |
| $sources->add(new xp·unittest·sources·FolderSource(new Folder($args[$i]))); | |
| } else { | |
| - $sources->add(new xp·unittest·sources·ClassSource(XPClass::forName($args[$i]))); | |
| + $sources->add(new xp·unittest·sources·ClassSource($cl->loadClass($args[$i], 'tests'))); | |
| } | |
| } | |
| } catch (Throwable $e) { | |
| diff --git a/core/src/test/php/net/xp_framework/unittest/core/modules/ImagingTestModuleTest.class.php b/core/src/test/php/net/xp_framework/unittest/core/modules/ImagingTestModuleTest.class.php | |
| index 223ec5d..2f6b6a3 100755 | |
| --- a/core/src/test/php/net/xp_framework/unittest/core/modules/ImagingTestModuleTest.class.php | |
| +++ b/core/src/test/php/net/xp_framework/unittest/core/modules/ImagingTestModuleTest.class.php | |
| @@ -60,8 +60,8 @@ | |
| public function providesClass($name) { /* Not reached */ } | |
| public function providesPackage($name) { /* Not reached */ } | |
| public function packageContents($name) { /* Not reached */ } | |
| - public function loadClass($name) { /* Not reached */ } | |
| - public function loadClass0($name) { /* Not reached */ } | |
| + public function loadClass($name, $intent= NULL) { /* Not reached */ } | |
| + public function loadClass0($name, $intent= NULL) { /* Not reached */ } | |
| public function getResource($name) { /* Not reached */ } | |
| public function getResourceAsStream($name) { /* Not reached */ } | |
| public function instanceId() { return "(test-fixture)"; } | |
| @@ -80,8 +80,8 @@ | |
| public function providesClass($name) { throw new IllegalStateException("Loader asked for class ".$name); } | |
| public function providesPackage($name) { /* Not reached */ } | |
| public function packageContents($name) { /* Not reached */ } | |
| - public function loadClass($name) { /* Not reached */ } | |
| - public function loadClass0($name) { /* Not reached */ } | |
| + public function loadClass($name, $intent= NULL) { /* Not reached */ } | |
| + public function loadClass0($name, $intent= NULL) { /* Not reached */ } | |
| public function getResource($name) { /* Not reached */ } | |
| public function getResourceAsStream($name) { /* Not reached */ } | |
| public function instanceId() { return "(test-fixture)"; } | |
| @@ -100,8 +100,8 @@ | |
| public function providesClass($name) { /* Not reached */ } | |
| public function providesPackage($name) { throw new IllegalStateException("Loader asked for package ".$name); } | |
| public function packageContents($name) { /* Not reached */ } | |
| - public function loadClass($name) { /* Not reached */ } | |
| - public function loadClass0($name) { /* Not reached */ } | |
| + public function loadClass($name, $intent= NULL) { /* Not reached */ } | |
| + public function loadClass0($name, $intent= NULL) { /* Not reached */ } | |
| public function getResource($name) { /* Not reached */ } | |
| public function getResourceAsStream($name) { /* Not reached */ } | |
| public function instanceId() { return "(test-fixture)"; } | |
| diff --git a/core/src/test/php/net/xp_framework/unittest/core/modules/ModuleDeclarationTest.class.php b/core/src/test/php/net/xp_framework/unittest/core/modules/ModuleDeclarationTest.class.php | |
| index b61c300..9db3953 100755 | |
| --- a/core/src/test/php/net/xp_framework/unittest/core/modules/ModuleDeclarationTest.class.php | |
| +++ b/core/src/test/php/net/xp_framework/unittest/core/modules/ModuleDeclarationTest.class.php | |
| @@ -29,8 +29,8 @@ | |
| public function providesClass($name) { return FALSE; } | |
| public function providesPackage($name) { return FALSE; } | |
| public function packageContents($name) { /* Not reached */ } | |
| - public function loadClass($name) { /* Not reached */ } | |
| - public function loadClass0($name) { /* Not reached */ } | |
| + public function loadClass($name, $intent= NULL) { /* Not reached */ } | |
| + public function loadClass0($name, $intent= NULL) { /* Not reached */ } | |
| public function getResource($name) { return $this->moduleInfo; } | |
| public function getResourceAsStream($name) { /* Not reached */ } | |
| public function instanceId() { return "(`".$this->moduleInfo."`)"; } | |
| diff --git a/core/src/test/php/net/xp_framework/unittest/core/modules/ModuleRegistrationTest.class.php b/core/src/test/php/net/xp_framework/unittest/core/modules/ModuleRegistrationTest.class.php | |
| index 202ffaf..f557639 100755 | |
| --- a/core/src/test/php/net/xp_framework/unittest/core/modules/ModuleRegistrationTest.class.php | |
| +++ b/core/src/test/php/net/xp_framework/unittest/core/modules/ModuleRegistrationTest.class.php | |
| @@ -24,8 +24,8 @@ | |
| public function providesClass($name) { return FALSE; } | |
| public function providesPackage($name) { return FALSE; } | |
| public function packageContents($name) { /* Not reached */ } | |
| - public function loadClass($name) { /* Not reached */ } | |
| - public function loadClass0($name) { /* Not reached */ } | |
| + public function loadClass($name, $intent= NULL) { /* Not reached */ } | |
| + public function loadClass0($name, $intent= NULL) { /* Not reached */ } | |
| public function getResource($name) { return "<?php module registration-fixture { } ?>"; } | |
| public function getResourceAsStream($name) { /* Not reached */ } | |
| public function instanceId() { return "(registration-fixture)"; } | |
| diff --git a/core/src/test/php/net/xp_framework/unittest/reflection/ClassLoaderTest.class.php b/core/src/test/php/net/xp_framework/unittest/reflection/ClassLoaderTest.class.php | |
| index 8a34db0..6d27ef8 100644 | |
| --- a/core/src/test/php/net/xp_framework/unittest/reflection/ClassLoaderTest.class.php | |
| +++ b/core/src/test/php/net/xp_framework/unittest/reflection/ClassLoaderTest.class.php | |
| @@ -162,6 +162,15 @@ | |
| } | |
| /** | |
| + * Loads a class that has been loaded before | |
| + * | |
| + */ | |
| + #[@test] | |
| + public function loadClassWithIntent() { | |
| + $this->assertXPClass('lang.Object', ClassLoader::getDefault()->loadClass('lang.Object', 'tests')); | |
| + } | |
| + | |
| + /** | |
| * Tests the findClass() method | |
| * | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment