Skip to content

Commit

Permalink
Update documentation for the current release
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Dec 25, 2024
1 parent 19874d1 commit 93ef923
Showing 1 changed file with 59 additions and 26 deletions.
85 changes: 59 additions & 26 deletions docs/uri/7.0/rfc3986.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,65 @@ echo $uri = //returns 'file:///etc/fstab'

<p class="message-notice"><code>fromRfc8089</code> is added since version <code>7.4.0</code></p>

## URI string representation

The `Uri` class handles URI according to RFC3986 as such you can retrieve its string representation using the
`toString` method.

```php
use League\Uri\Uri;

$uri = Uri::new("http://foo:[email protected]:81/how/are/you?foo=baz#title");

echo $uri->toString(); //displays RFC3986 string representation
echo $uri; //displays RFC3986 string representation
```

But `Uri` can have multiple string representation depending on its scheme or context. As
such the package provides several other string representations.

The `Uri` instance can be json encoded using the same URI representation from JavaScript to allow
easier interoperability

```php
use League\Uri\Uri;

$uri = Uri::new("http://foo:[email protected]:81/how/are/you?foo=baz#title");
json_encode($uri); //returns "http:\/\/foo:[email protected]:81\/how\/are\/you?foo=baz#title"
```

<p class="message-info">Available since version <code>7.6.0</code></p>

Two new URI string representation are added, the `toNormalizedString` normalizes the URI using
destructive normalization. Please refer to the [URI normalization section](#uri-normalization-and-comparison) for more information.
The `toDisplayString` returns a human-readable representation of the URI. The returned value
may represent an invalid URI but can be used to display the URI to the client for instance as the
content of a `a` HTML tag.

```php
use League\Uri\Uri;

$uri = Uri::new('eXAMPLE://a/./b/../b/%63/%7bfoo%7d?foo[]=bar');
echo $uri->toString(); //displays 'example://a/./b/../b/%63/%7bfoo%7d?foo%5B%5D=bar'
echo $uri->toNormalizedString(); //displays 'example://a/b/c/%7Bfoo%7D?foo%5B%5D=bar'
echo $uri->toDisplayString(); //displays 'example://a/b/c/{foo}?foo[]=bar'
````

File specific representation are also added to allow representing Unix and Windows Path.

```php
use League\Uri\Uri;

$uri = Uri::new('file:///c:/windows/My%20Documents%20100%2520/foo.txt');
echo $uri->toWindowsPath(); //display 'c:\windows\My Documents 100%20\foo.txt'

$uri = Uri::new('file:///path%20empty/bar');
echo $uri->toUnixPath(); // display '/path empty/bar'

$uri = Uri::new('file://localhost/etc/fstab');
echo $uri->toRfc8089(); //display 'file:/etc/fstab'
```

## Accessing URI properties

Let's examine the result of building a URI:
Expand Down Expand Up @@ -249,32 +308,6 @@ Uri::new('https://example.com/123')

The method takes into account i18n while comparing both URI if the PHP's `idn_*` functions can be used.

## URI string representation

The `Uri` class handles URI according to RFC3986 as such you can retrieve its string representation using the
`toString` method. But `URI` can have multiple string representation depending on its scheme or context. As
such the package provides several other string representations:

```php
use League\Uri\Uri;

$uri = Uri::new("http://foo:[email protected]:81/how/are/you?foo=baz#title");

echo $uri->toString(); //displays RFC3986 string representation
echo $uri; //displays RFC3986 string representation
echo json_encode($uri); //display JSON encoded string representation

/**
* NEW in version 7.6+
*/

echo $uri->toNormalizedString(); //displays the normalized URI string representation
echo $uri->toDisplayString(); //displays the URI display representation
echo $uri->toRfc8089String(); //display the string file representation according to RFC8089 or null if the scheme is not file
echo $uri->toUnixPath(); //display the string path as a Unix Path or null if the scheme is not file
echo $uri->toWindowsPath(); //display the string path as a Windows Path or null if the scheme is not file
```

## Modifying URI properties

Use the modifying methods exposed by all URI instances to replace one of the URI component.
Expand Down

0 comments on commit 93ef923

Please sign in to comment.