1 | <?php |
||
25 | class Relativize extends AbstractUriModifier |
||
26 | { |
||
27 | /** |
||
28 | * Base URI |
||
29 | * |
||
30 | * @var Uri|UriInterface |
||
31 | */ |
||
32 | protected $base_uri; |
||
33 | |||
34 | /** |
||
35 | * New instance |
||
36 | * |
||
37 | * @param Uri|UriInterface $base_uri |
||
38 | */ |
||
39 | 147 | public function __construct($base_uri) |
|
40 | { |
||
41 | 147 | $this->assertUriObject($base_uri); |
|
42 | 147 | $this->base_uri = $this->hostToAscii($base_uri); |
|
43 | 147 | } |
|
44 | |||
45 | /** |
||
46 | * Convert the Uri host component to its ascii version |
||
47 | * |
||
48 | * @param Uri|UriInterface $uri |
||
49 | * |
||
50 | * @return Uri|UriInterface |
||
51 | */ |
||
52 | 147 | protected function hostToAscii($uri) |
|
61 | |||
62 | /** |
||
63 | * Return a Uri object modified according to the modifier |
||
64 | * |
||
65 | * @param Uri|UriInterface $target |
||
66 | * |
||
67 | * @return Uri|UriInterface |
||
68 | */ |
||
69 | 147 | public function __invoke($target) |
|
93 | |||
94 | /** |
||
95 | * Tell whether the submitted URI object can be relativize |
||
96 | * |
||
97 | * @param Uri|UriInterface $target |
||
98 | * |
||
99 | * @return bool |
||
100 | */ |
||
101 | 147 | protected function isRelativizable($target) |
|
109 | |||
110 | /** |
||
111 | * Relative the URI for a authority-less target URI |
||
112 | * |
||
113 | * @param string $path |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 60 | protected function relativizePath($path) |
|
133 | |||
134 | /** |
||
135 | * returns the path segments |
||
136 | * |
||
137 | * @param string $path |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | 66 | protected function getSegments($path) |
|
149 | |||
150 | /** |
||
151 | * Formatting the path to keep a valid URI |
||
152 | * |
||
153 | * @param string $path |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | 60 | protected function formatPath($path) |
|
175 | |||
176 | /** |
||
177 | * Formatting the path to keep a resolvable URI |
||
178 | * |
||
179 | * @param string $path |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | 6 | protected function formatPathWithEmptyBaseQuery($path) |
|
190 | } |
||
191 |