Dispatcher.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }