Skip to content

Commit

Permalink
prepare 5.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Dec 1, 2017
1 parent 065272e commit f1e4470
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 196 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

All Notable changes to `League\Uri` will be documented in this file

## 5.2.0 - 2017-11-17
## 5.2.0 - 2017-12-01

- [URI hostname parser](https://github.com/thephpleague/uri-hostname-parser/releases/tag/1.0.0)
- [URI Parser](https://github.com/thephpleague/uri-parser/releases/tag/1.3.0)
- [URI Hostname parser](https://github.com/thephpleague/uri-hostname-parser/releases/tag/1.0.4)
- [URI Manipulations 1.3.0 Changelog](https://github.com/thephpleague/uri-manipulations/releases/tag/1.3.0)
- [URI Components 1.5.0 Changelog](https://github.com/thephpleague/uri-components/releases/tag/1.5.0)
- [URI Schemes 1.1.1 Changelog](https://github.com/thephpleague/uri-schemes/releases/tag/1.1.1)

- See [URI Manipulations 1.3.0 Changelog](https://github.com/thephpleague/uri-manipulations/blob/master/CHANGELOG.md#130---2017-11-24)
- See [URI Components 1.3.0 Changelog](https://github.com/thephpleague/uri-components/blob/master/CHANGELOG.md#130---2017-11-24)
### Fixed

- Support for PHP7.2

## 5.1.0 - 2017-11-17

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
"ext-mbstring" : "*",
"ext-intl" : "*",
"ext-fileinfo": "*",
"league/uri-components": "^1.4.1",
"league/uri-hostname-parser": "^1.0.2",
"league/uri-components": "^1.5.0",
"league/uri-hostname-parser": "^1.0.4",
"league/uri-interfaces": "^1.0",
"league/uri-manipulations": "^1.3",
"league/uri-parser": "^1.2",
"league/uri-schemes": "^1.1",
"league/uri-parser": "^1.3.0",
"league/uri-schemes": "^1.1.1",
"php" : ">=7.0.13",
"psr/http-message": "^1.0"
},
Expand Down
32 changes: 17 additions & 15 deletions docs/5.0/components/host.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Host implements ComponentInterface, Countable, IteratorAggregate
public function getLabel(int $offset, $default = null): mixed
public function getLabels(void): array
public function getPublicSuffix(void): string
public function getRegisterableDomain(void): string
public function getRegistrableDomain(void): string
public function getSubDomain(void): string
public function hasZoneIdentifier(void): bool
public function isIp(void): bool
Expand All @@ -40,7 +40,7 @@ class Host implements ComponentInterface, Countable, IteratorAggregate
public function withoutLabels(array $offsets): self
public function withoutRootLabel(void): self
public function withoutZoneIdentifier(void): self
public function withRegisterableDomain(string $host): self
public function withRegistrableDomain(string $host): self
public function withRootLabel(void): self
public function withSubDomain(string $host): self
}
Expand Down Expand Up @@ -184,24 +184,26 @@ $newHost->getIp(); //returns null

## Host represented by a registered name

<p class="message-warning"><code>Host::getRegisterableDomain</code> and <code>Host::withRegisterableDomain</code> are deprecated and replaced by <code>Host::getRegistrableDomain</code> and <code>Host::withRegistrableDomain</code> starting with version <code>1.5.0</code>.</p>

If you don't have a IP then you are dealing with a registered name. A registered name is a [domain name](http://tools.ietf.org/html/rfc1034) subset according to [RFC1123](http://tools.ietf.org/html/rfc1123#section-2.1). As such a registered name can not, for example, contain an `_`.

~~~php
<?php
public Host::getPublicSuffix(void): string
public Host::isPublicSuffixValid(void): bool
public Host::getRegisterableDomain(void): string
public Host::getRegistrableDomain(void): string
public Host::getSubDomain(void): string
public Host::withRegisterableDomain(string $host): self
public Host::withRegistrableDomain(string $host): self
public Host::withSubDomain(string $host): self
~~~

### Host public informations

Using data from [the public suffix list](http://publicsuffix.org/) and the [PHP Domain Parser](https://github.com/jeremykendall/php-domain-parser) library every `Host` object can:
Using data from [the public suffix list](http://publicsuffix.org/) every `Host` object can:

- return the subdomain using the `Host::getSubdomain` method;
- return the registerable domain using the `Host::getRegisterableDomain` method;
- return the subdomain using the `Host::getSubDomain` method;
- return the registerable domain using the `Host::getRegistrableDomain` method;
- return the public suffix using the `Host::getPublicSuffix` method;
- tell you if the found public suffix is valid using the `Host::isPublicSuffixValid` method;

Expand All @@ -212,8 +214,8 @@ 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'
echo $host->getRegistrableDomain(); //display 'example.co.uk'
echo $host->getSubDomain(); //display 'www'
$host->isPublicSuffixValid(); //return a boolean 'true' in this example
~~~

Expand All @@ -226,22 +228,22 @@ use League\Uri\Components\Host;

$host = new Host('192.158.26.30');
echo $host->getPublicSuffix(); //return ''
echo $host->getRegisterableDomain(); //return ''
echo $host->getSubdomain(); //return ''
echo $host->getRegistrableDomain(); //return ''
echo $host->getSubDomain(); //return ''
$host->isPublicSuffixValid(); //return false
~~~

### Updating the Registerable domain part
### Updating the Registrable domain part

You can update the registerable domain part of the host.
You can update the registrable domain part of the host.

~~~php
<?php

use League\Uri\Components\Host;

$host = new Host('www.11.be');
$newHost = $host->withRegisterableDomain('co.uk');
$newHost = $host->withRegistrableDomain('co.uk');
echo $newHost; //displays 'www.11.co.uk'
~~~

Expand All @@ -257,7 +259,7 @@ You can update the subdomain part of the host.
use League\Uri\Components\Host;

$host = new Host('www.11.be');
$newHost = $host->withSubdomain('shop');
$newHost = $host->withSubDomain('shop');
echo $newHost; //displays 'shop.11.be'
~~~

Expand Down
10 changes: 9 additions & 1 deletion docs/5.0/components/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ $ composer require league/uri-components
Dependencies
-------

- [PHP Domain Parser](https://github.com/jeremykendall/php-domain-parser)
Prior to version 1.4.0

- [PHP Domain Parser](https://github.com/jeremykendall/php-domain-parser)

Starting with version 1.4.0

- [Uri Hostname parser](/5.0/publicsuffix/)

The changes between dependencies was done to support `PHP7.2+`
235 changes: 235 additions & 0 deletions docs/5.0/components/query-parsers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
---
layout: default
title: The Query component
---

Query Parsers
=======

The library provides two classes `QueryParser` and `QueryBuilder` to ease query string creation and conversion.

~~~php
<?php

use League\Uri;

class QueryParser
{
public function convert(iterable $pairs): array
public function extract(string $query, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): array
public function parse(string $query, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): array
}


class QueryBuilder
{
public function build(iterable $pairs, string $separator = '&' , int $enc_type = PHP_QUERY_RFC3986): string
}

//functions aliases

function build_query(iterable $pairs, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): string
function extract_query(string $query, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): array
function pairs_to_params(iterable $pairs): array
function parse_query(string $query, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): array
~~~

## QueryParser::extract

~~~php
<?php

public QueryParser::extract(string $query[, string $separator = '&' [, int $enc_type = PHP_QUERY_RFC3986]]): array
~~~

This method deserializes the query string parameters into an associative `array` similar to PHP's `parse_str` when used with its optional second argument. This static public method expects the following arguments:

- The query string **required**;
- The query string separator **optional**, by default it is set to `&`;
- The query string encoding. One of the `ComponentInterface` encoding type constant.

The main differences are with `parse_str` usage are the following:

- `QueryParser::extract` accepts a parameter which describes the query string separator
- `QueryParser::extract` does not mangle the query string data.
- `QueryParser::extract` is not affected by PHP `max_input_vars`.

~~~php
<?php

use League\Uri\QueryParser;

$query_string = 'foo.bar=bar&foo_bar=baz';
parse_str($query_string, $out);
var_export($out);
// $out = ["foo_bar" => 'baz'];

$parser = new QueryParser();
$arr =$parser->extract($query_string);
// $arr = ['foo.bar' => 'bar', 'foo_bar' => baz'];
~~~

<p class="message-info">Since version <code>1.2.0</code> The alias function <code>Uri\extract_query</code> is available</p>

~~~php
<?php

use League\Uri;

$query_string = 'foo.bar=bar&foo_bar=baz';
parse_str($query_string, $out);
var_export($out);
// $out = ["foo_bar" => 'baz'];

$arr = Uri\extract_query($query_string);
// $arr = ['foo.bar' => 'bar', 'foo_bar' => baz'];
~~~


## QueryParser::parse

~~~php
<?php

public QueryParser::parse(string $query[, string $separator = '&' [, int $enc_type = PHP_QUERY_RFC3986]]): array
~~~

This method parse the query string into an associative `array` of key/values pairs. The method expects three (3) arguments:

- The query string **required**;
- The query string separator **optional**, by default it is set to `&`;
- The query string encoding. One of the `ComponentInterface` encoding type constant.

The value returned for each pair can be:

- `null`,
- a `string`
- an array of `string` and/or `null` values.

~~~php
<?php

use League\Uri;

$parser = new QueryParser();

$query_string = 'toto.foo=bar&toto.foo=baz&foo&baz=';
$arr = $parser->parse($query_string, '&');
// [
// "toto.foo" => ["bar", "baz"],
// "foo" => null,
// "baz" => "",
// ]
~~~


<p class="message-warning"><code>QueryParser::parse</code> is not simlar to <code>parse_str</code>, <code>QueryParser::extract</code> is.</p>

<p class="message-warning"><code>QueryParser::parse</code> and <code>QueryParser::extract</code> both convert the query string into an array but <code>QueryParser::parse</code> logic don't result in data loss.</p>

<p class="message-info">Since version <code>1.2.0</code> The alias function <code>Uri\parse_query</code> is available</p>

~~~php
<?php

use League\Uri;

$query_string = 'toto.foo=bar&toto.foo=baz&foo&baz=';
$arr = Uri\parse_query($query_string, '&');
// [
// "toto.foo" => ["bar", "baz"],
// "foo" => null,
// "baz" => "",
// ]
~~~

## QueryParser::convert

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


~~~php
<?php

public QueryParser::convert(iterable $pairs): array

//function alias

function pairs_to_params(iterable $pairs): array
~~~

The `QueryParser::convert` deserializes a collection of query string key/value pairs into an associative array similar to PHP’s `parse_str` when used with its optional second argument. This method expects a single argument which represents the collection of key/value pairs as an iterable construct.

The main differences are with `parse_str` usage are the following:

- `QueryParser::extract` accepts a parameter which describes the query string separator
- `QueryParser::extract` does not mangle the query string data.
- `QueryParser::extract` is not affected by PHP `max_input_vars`.

You can also use the function alias which is `Uri\pairs_to_params`.

~~~php
<?php

use League\Uri;

$parser = new Uri\QueryParser();
$arr = $parser->convert(['foo.bar' => ['2', 3, true]]);
//or
$arr = Uri\pairs_to_params(['foo.bar' => ['2', 3, true]]);
//in both cases $arr = ['foo.bar' => 'true'];
~~~


## QueryBuilder::build

~~~php
<?php

public QueryBuilder::build(iterable $pairs[, string $separator = '&' [, int $enc_type = PHP_QUERY_RFC3986]]): array
~~~

The `QueryBuilder::build` restores the query string from the result of the `QueryBuilder::parse` method. The method expects at most 3 arguments:

- A valid `iterable` of key/value pairs to convert;
- The query string separator, by default it is set to `&`;
- The query string encoding using one of the `ComponentInterface` constant

<p class="message-info">By default the encoding is set to <code>EncodingInterface::RFC3986_ENCODING</code></p>
<p class="message-info">Since version <code>1.3.0</code> The method accepts any iterable construct.</p>

~~~php
<?php

use League\Uri\QueryBuilder;
use League\Uri\QueryParser;

$builder = new QueryBuilder();
$parser = new QueryParser();


$query_string = 'foo[]=bar&foo[]=baz';
$arr = $parser->parse($query_string, '&', Query::RFC3986_ENCODING);
// $arr include the following data ["foo[]" => ['bar', 'baz']];

$res = $builder->build($arr, '&', false);
// $res = 'foo[]=bar&foo[]=baz'
~~~

<p class="message-warning"><code>QueryBuilder::build</code> is not similar to <code>http_build_query</code>.</p>
<p class="message-info">Since version <code>1.2.0</code> The alias function <code>Uri\build_query</code> is available</p>
<p class="message-info">Since version <code>1.3.0</code> The function accepts any iterable construct.</p>

~~~php
<?php

use League\Uri;

$query_string = 'foo[]=bar&foo[]=baz';
$arr = Query::parse($query_string, '&', Query::RFC3986_ENCODING);
var_export($arr);
// $arr include the following data ["foo[]" => ['bar', 'baz']];

$res = Uri\build_query($arr, '&', false);
// $res = 'foo[]=bar&foo[]=baz'
~~~
Loading

0 comments on commit f1e4470

Please sign in to comment.