Changeset 698
- Timestamp:
- 05/31/07 23:57:18 (1 year ago)
- Files:
-
- trunk/src/main/php/_test/package1 (added)
- trunk/src/main/php/_test/package1/Package1Class1.php (added)
- trunk/src/main/php/_test/package1/Package1Class2.php (added)
- trunk/src/main/php/_test/package1/subpackage (added)
- trunk/src/main/php/_test/package1/subpackage/SubPackage1Class1.php (added)
- trunk/src/main/php/_test/package2 (added)
- trunk/src/main/php/net/stubbles/reflection/reflection.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/stubBaseReflectionClass.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/stubReflectionClass.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/reflection/stubReflectionObject.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/stubReflectionPackage.php (added)
- trunk/src/main/php/net/stubbles/star/StarClassRegistry.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/stubBaseObject.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/stubClassLoader.php (modified) (7 diffs)
- trunk/src/main/php/net/stubbles/stubException.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/stubObject.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/stubSerializedObject.php (modified) (8 diffs)
- trunk/src/test/php/net/stubbles/reflection/ReflectionTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/reflection/stubReflectionPackageTestCase.php (added)
- trunk/src/test/php/net/stubbles/stubClassLoaderTestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/reflection.php
r432 r698 15 15 'net.stubbles.reflection.stubReflectionFunction', 16 16 'net.stubbles.reflection.stubReflectionMethod', 17 'net.stubbles.reflection.stubReflectionObject', 18 'net.stubbles.reflection.stubReflectionPackage', 17 19 'net.stubbles.reflection.stubReflectionParameter', 18 20 'net.stubbles.reflection.stubReflectionProperty' trunk/src/main/php/net/stubbles/reflection/stubBaseReflectionClass.php
r255 r698 29 29 */ 30 30 public function getFullQualifiedClassName(); 31 32 /** 33 * returns the package where the class belongs to 34 * 35 * @return stubReflectionPackage 36 */ 37 public function getPackage(); 31 38 } 32 39 ?> trunk/src/main/php/net/stubbles/reflection/stubReflectionClass.php
r432 r698 38 38 * constructor 39 39 * 40 * @param string $className name of class to reflect 40 * @param string $className name of class to reflect 41 * @throws stubClassNotFoundException 41 42 */ 42 43 public function __construct($className) … … 253 254 return $stubRefExtension; 254 255 } 256 257 /** 258 * returns the package where the class belongs to 259 * 260 * @return stubReflectionPackage 261 */ 262 public function getPackage() 263 { 264 $refPackage = new stubReflectionPackage(stubClassLoader::getPackageName($this->getFullQualifiedClassName())); 265 return $refPackage; 266 } 255 267 } 256 268 ?> trunk/src/main/php/net/stubbles/reflection/stubReflectionObject.php
r432 r698 275 275 return $stubRefExtension; 276 276 } 277 278 /** 279 * returns the package where the class belongs to 280 * 281 * @return stubReflectionPackage 282 */ 283 public function getPackage() 284 { 285 $refPackage = new stubReflectionPackage(stubClassLoader::getPackageName($this->getFullQualifiedClassName())); 286 return $refPackage; 287 } 277 288 } 278 289 ?> trunk/src/main/php/net/stubbles/star/StarClassRegistry.php
r613 r698 134 134 135 135 /** 136 * returns a list of all classes 137 * 138 * @return string 139 */ 140 public static function getClasses() 141 { 142 return array_keys(self::$classes); 143 } 144 145 /** 136 146 * initialize the class registry 137 147 */ trunk/src/main/php/net/stubbles/stubBaseObject.php
r685 r698 27 27 return $refObject; 28 28 } 29 29 30 /** 31 * returns package informations 32 * 33 * @return stubReflectionPackage 34 * @XMLIgnore 35 */ 36 public function getPackage() 37 { 38 stubClassLoader::load('net.stubbles.reflection.stubReflectionPackage'); 39 $refPackage = new stubReflectionPackage(stubClassLoader::getPackageName($this->getClassName())); 40 return $refPackage; 41 } 42 30 43 /** 31 44 * returns the full qualified class name … … 37 50 return stubClassLoader::getFullQualifiedClassName(get_class($this)); 38 51 } 39 52 40 53 /** 41 54 * returns a unique hash code for the class … … 47 60 return spl_object_hash($this); 48 61 } 49 62 50 63 /** 51 64 * checks whether a value is equal to the class … … 86 99 return self::getStringRepresentationOf($this, get_object_vars($this)); 87 100 } 88 101 89 102 /** 90 103 * returns a string representation of the class … … 149 162 return $string; 150 163 } 151 164 152 165 /** 153 166 * determines the correct type of a value trunk/src/main/php/net/stubbles/stubClassLoader.php
r612 r698 150 150 151 151 /** 152 * does some initializing 153 */ 154 private static function init() 155 { 156 if (stubConfig::useStar() == true && class_exists('StarClassRegistry', false) == true) { 157 self::$useStar = true; 158 } else { 159 self::$useStar = false; 160 } 161 162 self::$sourcePath = stubConfig::getSourcePath() . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR; 163 } 164 165 /** 152 166 * method to load files from source path 153 167 * … … 171 185 } 172 186 173 if (null == self::$useStar) { 174 if (stubConfig::useStar() == true && class_exists('StarClassRegistry', false) == true) { 175 self::$useStar = true; 176 } else { 177 self::$useStar = false; 178 } 179 180 self::$sourcePath = stubConfig::getSourcePath() . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR; 187 if (null === self::$useStar) { 188 self::init(); 181 189 } 182 190 … … 189 197 self::$classNames[$nqClassName] = $fqClassName; 190 198 $foreignNamespace = self::getForeignNamespace($fqClassName); 191 if (null != $foreignNamespace) {199 if (null !== $foreignNamespace) { 192 200 self::$foreignClassLoaders[$foreignNamespace][0]->load($fqClassName); 193 201 return; … … 195 203 196 204 $uri = null; 197 if (true == self::$useStar) {205 if (true === self::$useStar) { 198 206 $uri = StarClassRegistry::getUriForClass($fqClassName); 199 207 } … … 213 221 214 222 /** 223 * returns a list of all available classnames within a package 224 * 225 * @param string $packageName name of the package to retrieve class names for 226 * @param bool $recursive optional true if classes of subpackages should be included 227 * @return array<string> 228 */ 229 public static function getClassNames($packageName, $recursive = false) 230 { 231 if (null == self::$useStar) { 232 self::init(); 233 } 234 235 $dirName = self::$sourcePath . str_replace('.', DIRECTORY_SEPARATOR, $packageName); 236 if (file_exists($dirName) == false) { 237 return array(); 238 } 239 240 if (false === $recursive) { 241 $dirIt = new DirectoryIterator($dirName); 242 } else { 243 $dirIt = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirName)); 244 } 245 246 $classes = array(); 247 foreach ($dirIt as $file) { 248 if ($file->isDir() == true || substr($file->getFilename(), -4) != '.php') { 249 continue; 250 } 251 252 $classes[] = str_replace(DIRECTORY_SEPARATOR, '.', str_replace('.php', '', str_replace(self::$sourcePath, '', $file->getPathname()))); 253 } 254 255 if (true === self::$useStar) { 256 $classes = StarClassRegistry::getClasses(); 257 foreach ($classes as $fqClassName) { 258 if (substr($fqClassName, 0, strlen($packageName)) !== $packageName) { 259 continue; 260 } 261 262 $nqClassName = self::getNonQualifiedClassName($fqClassName); 263 if (str_replace($nqClassName, '', $fqClassName) != $packageName && false === $recursive) { 264 continue; 265 } 266 267 $classes[] = $fqClassName; 268 } 269 } 270 271 sort($classes); 272 return $classes; 273 } 274 275 /** 215 276 * returns the non qualified class name from a full qualified class name 216 277 * … … 237 298 238 299 return null; 300 } 301 302 /** 303 * returns the package name of a class 304 * 305 * @param string $fqClassName 306 * @return string 307 */ 308 public static function getPackageName($fqClassName) 309 { 310 $classNameParts = explode('.', $fqClassName); 311 unset($classNameParts[count($classNameParts) - 1]); 312 return join('.', $classNameParts); 239 313 } 240 314 … … 262 336 } 263 337 } 338 264 339 return null; 265 340 } trunk/src/main/php/net/stubbles/stubException.php
r522 r698 25 25 return $refObject; 26 26 } 27 27 28 /** 29 * returns package informations 30 * 31 * @return stubReflectionPackage 32 * @XMLIgnore 33 */ 34 public function getPackage() 35 { 36 stubClassLoader::load('net.stubbles.reflection.stubReflectionPackage'); 37 $refPackage = new stubReflectionPackage(stubClassLoader::getPackageName($this->getClassName())); 38 return $refPackage; 39 } 40 28 41 /** 29 42 * returns the full qualified class name … … 35 48 return stubClassLoader::getFullQualifiedClassName(get_class($this)); 36 49 } 37 50 38 51 /** 39 52 * returns a unique hash code for the class … … 45 58 return spl_object_hash($this); 46 59 } 47 60 48 61 /** 49 62 * checks whether a value is equal to the class trunk/src/main/php/net/stubbles/stubObject.php
r522 r698 21 21 */ 22 22 public function getClass(); 23 24 /** 25 * returns package informations 26 * 27 * @return stubReflectionPackage 28 */ 29 public function getPackage(); 23 30 24 31 /** trunk/src/main/php/net/stubbles/stubSerializedObject.php
r522 r698 47 47 */ 48 48 protected $data; 49 49 50 50 /** 51 51 * constructor … … 65 65 $this->hashCode = $serializable->hashCode(); 66 66 } 67 67 68 68 /** 69 69 * interceptor called before object instance is serialized … … 100 100 return $this->classInstance; 101 101 } 102 102 103 103 /** 104 104 * returns the class name of the serialized class … … 123 123 return $refObject; 124 124 } 125 125 126 126 /** 127 127 * returns the full qualified class name … … 133 133 return stubClassLoader::getFullQualifiedClassName(__CLASS__); 134 134 } 135 135 136 /** 137 * returns package informations 138 * 139 * @return stubReflectionPackage 140 * @XMLIgnore 141 */ 142 public function getPackage() 143 { 144 stubClassLoader::load('net.stubbles.reflection.stubReflectionPackage'); 145 $refPackage = new stubReflectionPackage(stubClassLoader::getPackageName($this->getClassName())); 146 return $refPackage; 147 } 148 136 149 /** 137 150 * returns a unique hash code for the class … … 143 156 return spl_object_hash($this); 144 157 } 145 158 146 159 /** 147 160 * checks whether a value is equal to the class … … 159 172 return false; 160 173 } 161 174 162 175 /** 163 176 * returns a serialized representation of the class … … 171 184 throw new Exception('Can not serialize a serialized ' . $this->getClassName() . ' representation of ' . $this->fqClassName); 172 185 } 173 186 174 187 /** 175 188 * returns a string representation of the class trunk/src/test/php/net/stubbles/reflection/ReflectionTestSuite.php
r483 r698 43 43 $this->addTestFile(dirname(__FILE__) . '/stubReflectionMethodTestCase.php'); 44 44 $this->addTestFile(dirname(__FILE__) . '/stubReflectionObjectTestCase.php'); 45 $this->addTestFile(dirname(__FILE__) . '/stubReflectionPackageTestCase.php'); 45 46 $this->addTestFile(dirname(__FILE__) . '/stubReflectionParameterTestCase.php'); 46 47 $this->addTestFile(dirname(__FILE__) . '/stubReflectionPropertyTestCase.php'); trunk/src/test/php/net/stubbles/stubClassLoaderTestCase.php
r579 r698 21 21 { 22 22 $this->assertEqual(stubClassLoader::getNonQualifiedClassName('example.foo.Bar'), 'Bar'); 23 $this->assertEqual(stubClassLoader::getPackageName('example.foo.Bar'), 'example.foo'); 23 24 $this->assertNull(stubClassLoader::getFullQualifiedClassName('Bar')); 25 $this->assertEqual(stubClassLoader::getPackageName('Bar'), ''); 24 26 $this->assertEqual(stubClassLoader::getNonQualifiedClassName('stubClassLoader'), 'stubClassLoader'); 25 27 }
