Parse.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Qii\Route;
  3. use \Qii\Autoloader\Import;
  4. use \Qii\Config\Register;
  5. use \Qii\Config\Consts;
  6. /**
  7. * 路由规则类
  8. *
  9. * @author Jinhui Zhu<jinhui.zhu@live.cn>2015-10-24 23:11
  10. */
  11. class Parse
  12. {
  13. const VERSION = 1.3;
  14. /**
  15. * 路由转发, 转发对应的规则中xx不能为*
  16. *
  17. * @param String $controller
  18. * @param String $action
  19. * @param Array $router
  20. * @return Array ($controller, $action);
  21. *
  22. * *:* => *:yyy 所有controller和action都转发到 *->yyy
  23. * *:* => yy:* 所有转发到xxx->*, 这里的*,前边对应的是什么,后边就对应转发到什么,比如: *:xxx => yy:yyy
  24. * xx:* => yy:* xx中对应的方法转发到yy对应的方法
  25. * xx:* => yy:yyy xxx Controller转发到 yy->yyy
  26. * *:xxx => yy:yyy 所有Controller转发到 yy->yyy
  27. */
  28. public static function get($controller, $action = '', $thirdParam = '')
  29. {
  30. if ($controller == 'Qii') {
  31. return array('controller' => $controller, 'action' => $action);
  32. }
  33. //如果第一列的是*号则所有的controller都执行对应的x:
  34. $router = Register::getAppConfigure(Consts::APP_SITE_ROUTER);
  35. $rewriteRule = Register::getAppConfigure(Register::get(Consts::APP_INI_FILE), 'rewriteRule');
  36. if (!$rewriteRule) $rewriteRule = 'Normal';
  37. Import::requires(Qii_DIR . DS . 'Route' . DS . 'Parse' .DS. $rewriteRule . '.php');
  38. $className = '\Qii\Route\Parse\\' . $rewriteRule;
  39. if (!class_exists($className, false)) {
  40. throw new \Qii\Exceptions\ClassNotFound(\Qii::i(1103, $className), __LINE__);
  41. }
  42. $class = new $className();
  43. $class->setConfig($router);
  44. return $class->parse($controller, $action, $thirdParam);
  45. }
  46. }
  47. ;