|
16 | 16 | use Deprecated; |
17 | 17 | use League\Uri\Contracts\UriException; |
18 | 18 | use League\Uri\Contracts\UriInterface; |
| 19 | +use League\Uri\Exceptions\MissingFeature; |
19 | 20 | use League\Uri\Exceptions\SyntaxError; |
20 | 21 | use League\Uri\UriTemplate\Template; |
21 | 22 | use League\Uri\UriTemplate\TemplateCanNotBeExpanded; |
|
30 | 31 |
|
31 | 32 | use function array_fill_keys; |
32 | 33 | use function array_key_exists; |
| 34 | +use function class_exists; |
33 | 35 |
|
34 | 36 | /** |
35 | 37 | * Defines the URI Template syntax and the process for expanding a URI Template into a URI reference. |
@@ -138,22 +140,28 @@ public function expand(iterable $variables = [], Rfc3986Uri|WhatWgUrl|Stringable |
138 | 140 | } |
139 | 141 |
|
140 | 142 | /** |
| 143 | + * @throws MissingFeature if no Uri\Rfc3986\Uri class is found |
141 | 144 | * @throws TemplateCanNotBeExpanded if the variables are invalid |
142 | 145 | * @throws InvalidUriException if the base URI cannot be converted to a Uri\Rfc3986\Uri instance |
143 | 146 | * @throws InvalidUriException if the resulting expansion cannot be converted to a Uri\Rfc3986\Uri instance |
144 | 147 | */ |
145 | 148 | public function expandToUri(iterable $variables = [], Rfc3986Uri|WhatWgUrl|Stringable|string|null $baseUri = null): Rfc3986Uri |
146 | 149 | { |
| 150 | + class_exists(Rfc3986Uri::class) || throw new MissingFeature('Support for '.Rfc3986Uri::class.' requires PHP8.5+ or a polyfill. Run "composer require league/uri-polyfill" or use you owm polyfill.'); |
| 151 | + |
147 | 152 | return new Rfc3986Uri($this->templateExpanded($variables), $this->newRfc3986Uri($baseUri)); |
148 | 153 | } |
149 | 154 |
|
150 | 155 | /** |
| 156 | + * @throws MissingFeature if no Uri\Whatwg\Url class is found |
151 | 157 | * @throws TemplateCanNotBeExpanded if the variables are invalid |
152 | 158 | * @throws InvalidUrlException if the base URI cannot be converted to a Uri\Whatwg\Url instance |
153 | 159 | * @throws InvalidUrlException if the resulting expansion cannot be converted to a Uri\Whatwg\Url instance |
154 | 160 | */ |
155 | 161 | public function expandToUrl(iterable $variables = [], Rfc3986Uri|WhatWgUrl|Stringable|string|null $baseUrl = null): WhatWgUrl |
156 | 162 | { |
| 163 | + class_exists(WhatWgUrl::class) || throw new MissingFeature('Support for '.Rfc3986Uri::class.' requires PHP8.5+ or a polyfill. Run "composer require league/uri-polyfill" or use you owm polyfill.'); |
| 164 | + |
157 | 165 | return new WhatWgUrl($this->templateExpanded($variables), $this->newWhatWgUrl($baseUrl)); |
158 | 166 | } |
159 | 167 |
|
@@ -191,22 +199,28 @@ public function expandOrFail(iterable $variables = [], Rfc3986Uri|WhatWgUrl|Stri |
191 | 199 | } |
192 | 200 |
|
193 | 201 | /** |
| 202 | + * @throws MissingFeature if no Uri\Rfc3986\Uri class is found |
194 | 203 | * @throws TemplateCanNotBeExpanded if the variables are invalid |
195 | 204 | * @throws InvalidUriException if the base URI cannot be converted to a Uri\Rfc3986\Uri instance |
196 | 205 | * @throws InvalidUriException if the resulting expansion cannot be converted to a Uri\Rfc3986\Uri instance |
197 | 206 | */ |
198 | 207 | public function expandToUriOrFail(iterable $variables = [], Rfc3986Uri|WhatWgUrl|Stringable|string|null $baseUri = null): Rfc3986Uri |
199 | 208 | { |
| 209 | + class_exists(Rfc3986Uri::class) || throw new MissingFeature('Support for '.Rfc3986Uri::class.' requires PHP8.5+ or a polyfill. Run "composer require league/uri-polyfill" or use you owm polyfill.'); |
| 210 | + |
200 | 211 | return new Rfc3986Uri($this->templateExpandedOrFail($variables), $this->newRfc3986Uri($baseUri)); |
201 | 212 | } |
202 | 213 |
|
203 | 214 | /** |
| 215 | + * @throws MissingFeature if no Uri\Whatwg\Url class is found |
204 | 216 | * @throws TemplateCanNotBeExpanded if the variables are invalid |
205 | 217 | * @throws InvalidUrlException if the base URI cannot be converted to a Uri\Whatwg\Url instance |
206 | 218 | * @throws InvalidUrlException if the resulting expansion cannot be converted to a Uri\Whatwg\Url instance |
207 | 219 | */ |
208 | 220 | public function expandToUrlOrFail(iterable $variables = [], Rfc3986Uri|WhatWgUrl|Stringable|string|null $baseUrl = null): WhatWgUrl |
209 | 221 | { |
| 222 | + class_exists(WhatWgUrl::class) || throw new MissingFeature('Support for '.Rfc3986Uri::class.' requires PHP8.5+ or a polyfill. Run "composer require league/uri-polyfill" or use you owm polyfill.'); |
| 223 | + |
210 | 224 | return new WhatWgUrl($this->templateExpandedOrFail($variables), $this->newWhatWgUrl($baseUrl)); |
211 | 225 | } |
212 | 226 |
|
|
0 commit comments