@@ -33,6 +33,25 @@ echo $uri; //display https://example.com/hotels/Rest%20%26%20Relax/bookings/42"
3333<p class =" message-notice " ><code >expandToUri()</code > and <code >expandToUrl()</code > are available since
3434version <code >7.6.0</code ></p >
3535
36+ <p class =" message-info " >Since version <code >7.6</code > the method takes a second optional parameter
37+ which serves as a base URI. The generated URI is resolved against the Base URI.</p >
38+
39+ ~~~ php
40+ <?php
41+
42+ use League\Uri\UriTemplate;
43+
44+ $template = '/hotels/{hotel}/bookings/{booking}';
45+ $params = ['booking' => '42', 'hotel' => 'Rest & Relax'];
46+
47+ $uriTemplate = new UriTemplate($template);
48+ $uri = $uriTemplate->expand($params, 'https://example.com'); // instance of League\Uri\Uri
49+ $rfc3986Uri = $uriTemplate->expandToUri($params, 'https://example.com'); // instance of Uri\Rfc3986\Uri
50+ $whatWgUrl = $uriTemplate->expandToUrl($params, 'https://example.com'); // instance of Uri\Whatwg\Url
51+
52+ echo $uri; //display https://example.com/hotels/Rest%20%26%20Relax/bookings/42"
53+ ~~~
54+
3655## Template variables
3756
3857<p class =" message-notice " >For maximum interoperability you should make sure your variables are
@@ -78,11 +97,11 @@ echo $uriTemplate->expand($params), PHP_EOL;
7897//displays https://api.twitter.com/2.0/search/j/john/?q=a&q=b&limit=10
7998~~~
8099
81- The ` expandToUri() ` and the ` expandToUrl() ` methods will act exactly like the ` expand() ` method
100+ The ` expandToUri() ` and the ` expandToUrl() ` methods will act exactly like the ` expand() ` method
82101but will instead return a ` Uri\Rfc3986\Uri ` and a ` Uri\Whatwg\Url ` object respectively.
83102
84103<p class =" message-warning " >a WHATWG URL must always be absolute if the URI template is not you
85- should provide to <code >expandToUrl()</code > a base URL otherwise an <code >Uri\WhatWg\InvalidUrlException</code >
104+ MUST provide a base URL to <code >expandToUrl()</code > otherwise an <code >Uri\WhatWg\InvalidUrlException</code >
86105exception will be thrown.</p >
87106
88107~~~ php
@@ -102,10 +121,6 @@ echo $uriTemplate->expandToUrl($params, 'https://api.twitter.com')->toAsciiStrin
102121echo $uriTemplate->expandToUrl($params); //will throw
103122~~~
104123
105- <p class =" message-info " >The same feature of adding a base URI is also supported for the
106- other two methods <code >expand()</code > and <code >expandToUri</code > but only if the
107- baseURI variable is not <code >null</code >.</p >
108-
109124### Updating the default variables
110125
111126At any given time you may update your default variables but since the ` UriTemplate `
0 commit comments