RuleName.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\route;
  12. class RuleName
  13. {
  14. protected $item = [];
  15. /**
  16. * 注册路由标识
  17. * @access public
  18. * @param string $name 路由标识
  19. * @param array $value 路由规则
  20. * @param bool $first 是否置顶
  21. * @return void
  22. */
  23. public function set($name, $value, $first = false)
  24. {
  25. if ($first) {
  26. array_unshift($this->item[$name], $value);
  27. } else {
  28. $this->item[$name][] = $value;
  29. }
  30. }
  31. /**
  32. * 导入路由标识
  33. * @access public
  34. * @param array $name 路由标识
  35. * @return void
  36. */
  37. public function import($item)
  38. {
  39. $this->item = $item;
  40. }
  41. /**
  42. * 根据路由标识获取路由信息(用于URL生成)
  43. * @access public
  44. * @param string $name 路由标识
  45. * @return array|null
  46. */
  47. public function get($name = null)
  48. {
  49. if (is_null($name)) {
  50. return $this->item;
  51. }
  52. $name = strtolower($name);
  53. return isset($this->item[$name]) ? $this->item[$name] : null;
  54. }
  55. }