/
Normalize.php
47 lines (43 loc) · 1.17 KB
/
Normalize.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* League.Uri (http://uri.thephpleague.com)
*
* @package League.uri
* @author Ignace Nyamagana Butera <nyamsprod@gmail.com>
* @copyright 2013-2015 Ignace Nyamagana Butera
* @license https://github.com/thephpleague/uri/blob/master/LICENSE (MIT License)
* @version 4.2.0
* @link https://github.com/thephpleague/uri/
*/
namespace League\Uri\Modifiers;
use League\Uri\Interfaces\Uri;
use Psr\Http\Message\UriInterface;
/**
* A class to normalize URI objects
*
* @package League.uri
* @author Ignace Nyamagana Butera <nyamsprod@gmail.com>
* @since 4.0.0
*/
class Normalize extends AbstractUriModifier
{
/**
* Return a Uri object modified according to the modifier
*
* @param Uri|UriInterface $uri
*
* @return Uri|UriInterface
*/
public function __invoke($uri)
{
$modifier = new Pipeline([
new HostToAscii(),
new KsortQuery(),
]);
$path = $uri->getPath();
if (!\League\Uri\uri_getinfo($uri)['relative_path']) {
$modifier = $modifier->pipe(new RemoveDotSegments());
}
return $modifier($uri)->withScheme($uri->getScheme());
}
}