Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Dec 27, 2024
1 parent faf7859 commit 97d13ab
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions docs/uri/7.0/rfc3986.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ The `Uri` class handles URI according to RFC3986 as such you can retrieve its st
`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
Expand All @@ -126,8 +124,6 @@ The `Uri` instance can be json encoded using the same URI representation from Ja
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"
```
Expand All @@ -141,8 +137,6 @@ may represent an invalid URI but can be used to display the URI to the client fo
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'
Expand All @@ -152,8 +146,6 @@ echo $uri->toDisplayString(); //displays 'example://a/b/c/{foo}?foo[]=bar'
HTML specific representation are added to allow adding URI to your HTML/Markdown page.

```php
use League\Uri\Uri;

$uri = Uri::new('eXAMPLE://a/./b/../b/%63/%7bfoo%7d?foo[]=bar');
echo $uri->toMarkdown();
//display '[example://a/b/c/{foo}?foo[]=bar](example://a/./b/../b/%63/%7bfoo%7d?foo%5B%5D=bar)
Expand All @@ -168,8 +160,6 @@ echo $uri->toAnchorTag('my link');
You can also generate the Link `tag` and/or `header` depending on how you want your URI link to be rendered:

```php
use League\Uri\Uri;

$uri = Uri::new('https://example.com/my/css/v1.3');
echo $uri->toLinkTag(['rel' => 'stylesheet']);
//display '<link href="https://example.com/my/css/v1.3" rel="stylesheet">
Expand All @@ -180,8 +170,6 @@ echo $uri->toLinkFieldValue(['rel' => 'stylesheet']);
File specific representation are 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'

Expand Down Expand Up @@ -378,24 +366,21 @@ $uri = Uri::new("ftp://thephpleague.com/fr/")
echo $uri; //displays yolo://foo:[email protected]:81?foo=baz#fine
~~~

<p class="message-notice">The <code>withUser</code> and <code>withPassword</code> methods are available
since version <code>7.6.0</code> to be inline with PHP native <code>Uri</code> interface.</p>

<p class="message-notice">The <code>when</code> method is available since version <code>7.6.0</code></p>
To ease building the instance, the `when` method is added to conditionally create your component.

```php
use League\Uri\Uri;
<p class="message-notice">The <code>withUser</code> and <code>withPassword</code> methods are available
since version <code>7.6.0</code> to be inline with PHP native <code>Uri</code> interface.</p>

$foo = '';
```php
echo Uri::new('https://uri.thephpleague.com/components/7.0/modifiers/')
->when(
'' !== $foo,
fn (Uri $uri) => $uri->withPath('/'.$foo), //on true
fn (Uri $uri) => $uri->withPath('/default'), //on false
fn (Uri $uri) => $uri->getPassword() !== null,
fn (Uri $uri) => $uri->withQuery('access=allowed'), //on true
fn (Uri $uri) => $uri->withQuery('access=deny'), //on false
)
->toString();
// returns 'https://uri.thephpleague.com/default';
// returns 'https://uri.thephpleague.com/components/7.0/modifiers/?access=deny';
```

## URI resolution
Expand Down

0 comments on commit 97d13ab

Please sign in to comment.