|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* League.Uri (http://uri.thephpleague.com) |
|
4
|
|
|
* |
|
5
|
|
|
* @package League.uri |
|
6
|
|
|
* @author Ignace Nyamagana Butera <[email protected]> |
|
7
|
|
|
* @copyright 2013-2015 Ignace Nyamagana Butera |
|
8
|
|
|
* @license https://github.com/thephpleague/uri/blob/master/LICENSE (MIT License) |
|
9
|
|
|
* @version 4.1.0 |
|
10
|
|
|
* @link https://github.com/thephpleague/uri/ |
|
11
|
|
|
*/ |
|
12
|
|
|
namespace League\Uri\Schemes\Generic; |
|
13
|
|
|
|
|
14
|
|
|
use League\Uri\Components\Fragment; |
|
15
|
|
|
use League\Uri\Components\HierarchicalPath as Path; |
|
16
|
|
|
use League\Uri\Components\Host; |
|
17
|
|
|
use League\Uri\Components\Pass; |
|
18
|
|
|
use League\Uri\Components\Port; |
|
19
|
|
|
use League\Uri\Components\Query; |
|
20
|
|
|
use League\Uri\Components\Scheme; |
|
21
|
|
|
use League\Uri\Components\User; |
|
22
|
|
|
use League\Uri\Components\UserInfo; |
|
23
|
|
|
use League\Uri\Interfaces\Fragment as FragmentInterface; |
|
24
|
|
|
use League\Uri\Interfaces\HierarchicalPath as PathInterface; |
|
25
|
|
|
use League\Uri\Interfaces\Host as HostInterface; |
|
26
|
|
|
use League\Uri\Interfaces\Port as PortInterface; |
|
27
|
|
|
use League\Uri\Interfaces\Query as QueryInterface; |
|
28
|
|
|
use League\Uri\Interfaces\Scheme as SchemeInterface; |
|
29
|
|
|
use League\Uri\Interfaces\UserInfo as UserInfoInterface; |
|
30
|
|
|
use League\Uri\UriParser; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Value object representing a Hierarchical URI. |
|
34
|
|
|
* |
|
35
|
|
|
* @package League.uri |
|
36
|
|
|
* @author Ignace Nyamagana Butera <[email protected]> |
|
37
|
|
|
* @since 4.0.0 |
|
38
|
|
|
* |
|
39
|
|
|
* @property-read SchemeInterface $scheme |
|
40
|
|
|
* @property-read UserInfoInterface $userInfo |
|
41
|
|
|
* @property-read HostInterface $host |
|
42
|
|
|
* @property-read PortInterface $port |
|
43
|
|
|
* @property-read PathInterface $path |
|
44
|
|
|
* @property-read QueryInterface $query |
|
45
|
|
|
* @property-read FragmentInterface $fragment |
|
46
|
|
|
*/ |
|
47
|
|
|
abstract class AbstractHierarchicalUri extends AbstractUri |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* Create a new instance of URI |
|
51
|
|
|
* |
|
52
|
|
|
* @param SchemeInterface $scheme |
|
53
|
|
|
* @param UserInfoInterface $userInfo |
|
54
|
|
|
* @param HostInterface $host |
|
55
|
|
|
* @param PortInterface $port |
|
56
|
|
|
* @param PathInterface $path |
|
57
|
|
|
* @param QueryInterface $query |
|
58
|
350 |
|
* @param FragmentInterface $fragment |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __construct( |
|
61
|
|
|
SchemeInterface $scheme, |
|
62
|
|
|
UserInfoInterface $userInfo, |
|
63
|
|
|
HostInterface $host, |
|
64
|
|
|
PortInterface $port, |
|
65
|
|
|
PathInterface $path, |
|
66
|
|
|
QueryInterface $query, |
|
67
|
350 |
|
FragmentInterface $fragment |
|
68
|
350 |
|
) { |
|
69
|
350 |
|
$this->scheme = $scheme; |
|
70
|
350 |
|
$this->userInfo = $userInfo; |
|
71
|
350 |
|
$this->host = $host; |
|
72
|
350 |
|
$this->port = $port; |
|
73
|
350 |
|
$this->path = $path; |
|
74
|
350 |
|
$this->query = $query; |
|
75
|
322 |
|
$this->fragment = $fragment; |
|
76
|
|
|
$this->assertValidObject(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Create a new instance from a string |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $uri |
|
83
|
|
|
* |
|
84
|
350 |
|
* @return static |
|
85
|
|
|
*/ |
|
86
|
350 |
|
public static function createFromString($uri = '') |
|
87
|
|
|
{ |
|
88
|
|
|
return static::createFromComponents((new UriParser())->__invoke($uri)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Create a new instance from a hash of parse_url parts |
|
93
|
|
|
* |
|
94
|
|
|
* @param array $components a hash representation of the URI similar to PHP parse_url function result |
|
95
|
|
|
* |
|
96
|
350 |
|
* @return static |
|
97
|
|
|
*/ |
|
98
|
350 |
|
public static function createFromComponents(array $components) |
|
99
|
|
|
{ |
|
100
|
350 |
|
$components = self::normalizeUriHash($components); |
|
101
|
350 |
|
|
|
102
|
350 |
|
return new static( |
|
103
|
350 |
|
new Scheme($components['scheme']), |
|
104
|
350 |
|
new UserInfo(new User($components['user']), new Pass($components['pass'])), |
|
105
|
350 |
|
new Host($components['host']), |
|
106
|
350 |
|
new Port($components['port']), |
|
107
|
350 |
|
new Path($components['path']), |
|
108
|
350 |
|
new Query($components['query']), |
|
109
|
|
|
new Fragment($components['fragment']) |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @inheritdoc |
|
115
|
|
|
*/ |
|
116
|
|
|
public static function __set_state(array $components) |
|
117
|
|
|
{ |
|
118
|
|
|
return new static( |
|
119
|
|
|
$components['scheme'], |
|
120
|
|
|
$components['userInfo'], |
|
121
|
|
|
$components['host'], |
|
122
|
|
|
$components['port'], |
|
123
|
|
|
$components['path'], |
|
124
|
|
|
$components['query'], |
|
125
|
|
|
$components['fragment'] |
|
126
|
|
|
); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|