1 | <?php |
||
13 | class Router |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var array with $_SERVER environment |
||
18 | */ |
||
19 | protected $server; |
||
20 | |||
21 | /** |
||
22 | * @param array $server $_SERVER environment |
||
23 | */ |
||
24 | 36 | public function __construct(array $server = []) |
|
31 | |||
32 | /** |
||
33 | * get request-URL relative to Phile base-URL |
||
34 | * |
||
35 | * @return string relative URL e.g. `index`, `sub/`, `sub/page` |
||
36 | */ |
||
37 | 7 | public function getCurrentUrl() |
|
56 | |||
57 | /** |
||
58 | * Get base-URL of the Phile installation |
||
59 | * |
||
60 | * @return string `scheme://host/path/phile-root` |
||
61 | */ |
||
62 | 34 | public function getBaseUrl() |
|
84 | |||
85 | /** |
||
86 | * get the URL for a page-Id |
||
87 | * |
||
88 | * e.g. `sub/index` --> `http://host/phile-root/sub` |
||
89 | * |
||
90 | * @param string $pageId |
||
91 | * @param bool $base return a full or root-relative URL |
||
92 | * @return string URL |
||
93 | */ |
||
94 | 6 | public function urlForPage($pageId, $base = true) |
|
102 | |||
103 | /** |
||
104 | * converts Phile-root relative URL to full URL |
||
105 | * |
||
106 | * e.g. `foo/bar.ext` --> `http://host/phile-root/foo/bar.ext` |
||
107 | * |
||
108 | * @param string $url |
||
109 | * @return string |
||
110 | */ |
||
111 | 3 | public function url($url) |
|
115 | |||
116 | /** |
||
117 | * get the HTTP-protocol |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | 3 | public function getProtocol() |
|
132 | |||
133 | /** |
||
134 | * get path of an URL |
||
135 | * |
||
136 | * `scheme://host/path/sub` --> `/path/sub` |
||
137 | * |
||
138 | * @param string $url |
||
139 | * @return string |
||
140 | */ |
||
141 | 7 | protected function getUrlPath($url) |
|
152 | } |
||
153 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: