No Description

Dispatcher.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * The Dispatcher class
  4. */
  5. class LtDispatcher
  6. {
  7. public $viewDir;
  8. public $viewTplDir;
  9. public $viewTplAutoCompile;
  10. public $data;
  11. public function __construct()
  12. {
  13. }
  14. protected function _dispatch($module, $action, $context = null, $classType = "Action")
  15. {
  16. $classType = ucfirst($classType);
  17. $actionClassName = $module . $action . $classType;
  18. if (!class_exists($actionClassName))
  19. {
  20. //DebugHelper::debug("{$classType}_CLASS_NOT_FOUND", array(strtolower($classType) => $action));
  21. trigger_error("{$actionClassName} CLASS NOT FOUND! module={$module} action={$action} classType={$classType}");
  22. }
  23. else
  24. {
  25. if (!($context instanceof LtContext))
  26. {
  27. $newContext = new LtContext;
  28. }
  29. else
  30. {
  31. $newContext = clone $context;
  32. }
  33. $newContext->uri['module'] = $module;
  34. $newContext->uri[strtolower($classType)] = $action;
  35. $actionInstance = new $actionClassName();
  36. $actionInstance->context = $newContext;
  37. $actionInstance->viewDir = $this->viewDir;
  38. $actionInstance->viewTplDir = $this->viewTplDir; // 模板编译目录
  39. $actionInstance->viewTplAutoCompile = $this->viewTplAutoCompile;
  40. $actionInstance->executeChain();
  41. $this->data = $actionInstance->data;
  42. }
  43. }
  44. /**
  45. * Disptach the module/action calling.
  46. *
  47. * @param $module string
  48. * @param $action string
  49. * @return void
  50. * @todo allow one action dispatch another action
  51. */
  52. public function dispatchAction($module, $action, $context = null)
  53. {
  54. $this->_dispatch($module, $action, $context);
  55. }
  56. /**
  57. * Disptach the module/component calling.
  58. *
  59. * @param $module string
  60. * @param $component string
  61. * @param $data mixed
  62. * @return void
  63. */
  64. public function dispatchComponent($module, $component, $context = null)
  65. {
  66. $cloneOfContext = clone $context;
  67. $this->_dispatch($module, $component, $cloneOfContext, "Component");
  68. }
  69. }