| Total Complexity | 9 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class UriParser |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * 入口文件 |
||
| 11 | * |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $indexFile; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * 文本根目录 |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $documentRoot; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * URI |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $uri; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * 请求参数 |
||
| 32 | * |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | protected $query; |
||
| 36 | |||
| 37 | public function __construct(string $uri, string $indexFile) |
||
| 38 | { |
||
| 39 | $this->indexFile = $indexFile; |
||
| 40 | $url = $this->clearIndex($uri, $indexFile); |
||
| 41 | $query = parse_url($url, PHP_URL_QUERY); |
||
| 42 | if (strlen($query) > 0) { |
||
| 43 | parse_str($query, $this->query); |
||
| 44 | } |
||
| 45 | $url = parse_url($url, PHP_URL_PATH); |
||
| 46 | $this->uri = '/' . trim($url, '\/'); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function getQuery():array |
||
| 52 | } |
||
| 53 | |||
| 54 | public function getUri():string |
||
| 55 | { |
||
| 56 | return $this->uri; |
||
| 57 | } |
||
| 58 | |||
| 59 | private function clearIndex(string $url, string $indexFile) |
||
| 76 | } |
||
| 77 | } |
||
| 78 |