Skip to content

Commit

Permalink
Merge pull request #201 from GwendolenLynch/uri-string
Browse files Browse the repository at this point in the history
[docs] Update Parsing, Building & Normalizing URIs
  • Loading branch information
nyamsprod committed Apr 2, 2022
2 parents 22f1ab2 + 2c576f5 commit a81ac40
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 85 deletions.
4 changes: 2 additions & 2 deletions docs/_data/project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Documentation website
title: "URI"
tagline: "Modern API to process URI in PHP."
description: "Modern API to process URI in PHP"
tagline: "Modern API to process URIs in PHP."
description: "Modern API to process URIs in PHP"
google_analytics_tracking_id: UA-46050814-14
# Github repository
author:
Expand Down
5 changes: 4 additions & 1 deletion docs/_includes/building-block.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
<span class="k">use</span> <span class="nx">League\Uri\UriModifier</span><span class="p">;</span>

<span class="nv">$uri</span> <span class="o">=</span> <span class="nx">Uri</span><span class="o">::</span><span class="na">createFromString</span><span class="p">(</span><span class="s1">'http://example.com?q=value#fragment'</span><span class="p">);</span>
<span class="nv">$uri</span><span class="o">-&gt;</span><span class="na">getScheme</span><span class="p">();</span> <span class="c1">// returns 'http'</span>
<span class="nv">$uri</span><span class="o">-&gt;</span><span class="na">getHost</span><span class="p">();</span> <span class="c1">// returns 'example.com'</span>

<span class="nv">$newUri</span> <span class="o">=</span> <span class="nx">UriModifier</span><span class="o">::</span><span class="na">appendQuery</span><span class="p">(</span><span class="nv">$uri</span><span class="p">,</span> <span class="s1">'q=new.Value'</span><span class="p">);</span>
<span class="k">echo</span> <span class="nv">$newUri</span><span class="p">;</span> <span class="c1">// 'http://example.com?q=value&amp;q=new.Value#fragment';</span>
<span class="k">echo</span> <span class="nv">$newUri</span><span class="p">;</span> <span class="c1">// 'http://example.com?q=value&amp;q=new.Value#fragment'</span>

<span class="nv">$query</span> <span class="o">=</span> <span class="nx">Query</span><span class="o">::</span><span class="na">createFromUri</span><span class="p">(</span><span class="nv">$newUri</span><span class="p">);</span>
<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">get</span><span class="p">(</span><span class="s1">'q'</span><span class="p">);</span> <span class="c1">// returns 'value'</span>
Expand Down
15 changes: 8 additions & 7 deletions docs/_layouts/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ <h1>Intuitive</h1>
<div class="column one">
<h1>Highlights</h1>
<div class="description">
<p>This suite of packages provides simple and intuitive classes to parse, validate, format and manipulate URIs and their components. It is built to enable working with
<p>This suite of packages provides intuitive classes to parse, validate, format and manipulate URIs and their components. It is built to enable working with
any kind of RFC3986 compliant URI and also follow closely the latest WHATWG Living standard specification.</p>
<p>It provides an enhanced replacement for PHP's <code>parse_url</code>, <code>http_build_query</code>, and PECL's <code>http_build_url</code> functions.</p>
</div>
</div>
<div class="column two">
Expand All @@ -69,32 +70,32 @@ <h1>Packages</h1>
<h1>building blocks</h1>
<dl>
<dt><a href="/uri/6.0/">uri</a></dt>
<dd>This is the main package. It's goal is to ease generating and manipulation a full URI object independently from the URI schemes.</dd>
<dd>This is the main package. Its goal is to ease the generation and manipulation of URI objects, independently of its scheme.</dd>
</dl>
<dl>
<dt><a href="/components/2.0/">uri-components</a></dt>
<dd>This package complement the URI package by providing a object oriented way to access and manipulate each URI components. It can be use to partially update such component in a full URI object context.</dd>
<dd>This package complements the URI package, providing an object-oriented way to access and manipulate each component value of the underlying URI.</dd>
</dl>
</div>
<div class="packages-list">
<h1>Deprecated blocks</h1>
<dl>
<dt><a href="/schemes/1.0/">uri-schemes</a></dt>
<dd>Collection of URI objects.<br><strong>This package is deprecated because it conflicts and is superseded by the latest URI object package.</strong></dd>
<dd>Collection of URI objects.<br><strong>This package is deprecated because it conflicts with, and is superseded by, the latest URI object package.</strong></dd>
</dl>
<dl>
<dt><a href="/manipulations/1.0/">uri-manipulations</a></dt>
<dd>Functions and Middleware to ease URI Objects manipulations.<br><strong>This package is deprecated because it is superseded by the latest URI component object package.</strong></dd>
<dd>Functions and Middleware to ease URI object manipulation.<br><strong>This package is deprecated because it is superseded by the latest URI component object package.</strong></dd>
</dl>
<dl>
<dt><a href="/domain-parser/1.0/">uri-hostname-parser</a></dt>
<dd>A lightweight public suffix list ICANN section parser.<br><strong>This package is deprecated and its feature removed as it was a temporary solution. Other dedicated PHP package like <a href="https://github.com/jeremykendall/php-domain-parser">PHP Domain Parser</a> provide a better and stable approach.</strong></dd>
<dd>A lightweight public suffix list ICANN section parser.<br><strong>This package is deprecated and its feature removed as it was a temporary solution. Other dedicated PHP package like <a href="https://github.com/jeremykendall/php-domain-parser">PHP Domain Parser</a> provides a better, and more stable, approach.</strong></dd>
</dl>
</div>
<div class="packages-list">
<h1>Helpers blocks</h1>
<p class="message-notice">While no longer updated the following helper packages will continue to receive patch fixes <a href="https://www.php.net/supported-versions.php">as long as PHP7 is maintained</a>.
Their features are back-ported into maintained packages without BC break. Avoid using them for new projects.</p>
Their features have been merged into maintained packages, while maintaining backwards-compatibility. Avoid using them for new projects.</p>
<dl>
<dt><a href="/parser/1.0/">uri-parser</a></dt>
<dd>a PHP user land RFC3986 compliant parser and builder to turn any valid URI string into an array and to build an URI out of a given array.</dd>
Expand Down
10 changes: 10 additions & 0 deletions docs/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

services:
jekyll:
image: jekyll/jekyll:latest
command: jekyll serve --watch --force_polling --verbose
ports:
- 4000:4000
volumes:
- .:/srv/jekyll
75 changes: 0 additions & 75 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,3 @@
---
layout: homepage
---

# Features

## Parsing URI

The League URI Parser parses any given URI according to RFC3986 rules

~~~php
<?php

use function League\Uri\parse;

var_export(parse('http://[email protected]/'));
//returns the following array
//array(
// 'scheme' => 'http',
// 'user' => null,
// 'pass' => null,
// 'host' => 'foo.com',
// 'port' => null,
// 'path' => '',
// 'query' => '@bar.com/',
// 'fragment' => null,
//);
~~~

## Normalizing URI

League URI objects normalize the URI string according to RFC3986/RFC3987 non destructive rules.

~~~php
<?php

use League\Uri\Http;
use function League\Uri\create;

echo create("hTTp://www.ExAmPLE.com:80/hello/./wor ld?who=f 3#title");
//displays http://www.example.com/hello/./wor%20ld?who=f%203#title

echo Http::createFromComponent(parse_url("hTTp://www.bébé.be?#"));
//displays http://xn--bb-bjab.be?#
~~~

## URI Middlewares

A collection of URI middlewares to enable reliable URI modifications with any given League URI object or [PSR-7](http://www.php-fig.org/psr/psr-7/) `UriInterface` compatible implementation.

~~~php
<?php

use Zend\Diactoros\Uri as DiactorosUri;
use function League\Uri\merge_query;

$uri = new DiactorosUri("http://www.example.com?fo.o=toto#~typo");
$new_uri = merge_query($uri, 'fo.o=bar&taz=');
echo $new_uri;
// display http://www.example.com?fo.o=bar&taz=#~typo
// $new_uri is a Zend\Diactoros\Uri instance
~~~

## URI components

Improve URI components manipulations through dedicated objects.

~~~php
<?php

use League\Uri\Components\Host;

$host = new Host('www.example.co.uk');
echo $host->getPublicSuffix(); //display 'co.uk'
echo $host->getRegisterableDomain(); //display 'example.co.uk'
echo $host->getSubdomain(); //display 'www'
$host->isPublicSuffixValid(); //return a boolean 'true' in this example
~~~
2 changes: 2 additions & 0 deletions docs/uri/6.0/parser-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,5 @@ $uri = UriString::build($components);

echo $uri; //displays http://hello:[email protected][email protected]/
~~~

The `build` method provides similar functionality to the `http_build_url()` function from v1.x of the [`pecl_http`](https://pecl.php.net/package/pecl_http) PECL extension.

0 comments on commit a81ac40

Please sign in to comment.