HproseClassManager.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**********************************************************\
  3. | |
  4. | hprose |
  5. | |
  6. | Official WebSite: http://www.hprose.com/ |
  7. | http://www.hprose.net/ |
  8. | http://www.hprose.org/ |
  9. | |
  10. \**********************************************************/
  11. /**********************************************************\
  12. * *
  13. * HproseClassManager.php *
  14. * *
  15. * hprose class manager library for php5. *
  16. * *
  17. * LastModified: Nov 12, 2013 *
  18. * Author: Ma Bingyao <andot@hprfc.com> *
  19. * *
  20. \**********************************************************/
  21. class HproseClassManager {
  22. private static $classCache1 = array();
  23. private static $classCache2 = array();
  24. public static function register($class, $alias) {
  25. self::$classCache1[$alias] = $class;
  26. self::$classCache2[$class] = $alias;
  27. }
  28. public static function getClassAlias($class) {
  29. if (array_key_exists($class, self::$classCache2)) {
  30. return self::$classCache2[$class];
  31. }
  32. $alias = str_replace('\\', '_', $class);
  33. self::register($class, $alias);
  34. return $alias;
  35. }
  36. public static function getClass($alias) {
  37. if (array_key_exists($alias, self::$classCache1)) {
  38. return self::$classCache1[$alias];
  39. }
  40. if (!class_exists($alias)) {
  41. $class = str_replace('_', '\\', $alias);
  42. if (class_exists($class)) {
  43. self::register($class, $alias);
  44. return $class;
  45. }
  46. eval("class " . $alias . " { }");
  47. }
  48. return $alias;
  49. }
  50. }
  51. ?>