1 | <?php |
||
10 | class Path extends AbstractUriPart |
||
11 | { |
||
12 | protected static $unencoded_characters = array('/'); |
||
13 | |||
14 | protected static $compositions = array( |
||
15 | "unreserved_characters", |
||
16 | "sub_delims_characters", |
||
17 | "pchar_characters", |
||
18 | ); |
||
19 | |||
20 | protected static $part_pattern; |
||
21 | |||
22 | /** |
||
23 | * Host constructor. Accepts a string representing a URI host component. Construction will throw an exception if |
||
24 | * the host is not a string. |
||
25 | * |
||
26 | * path-abempty = *( "/" segment ) |
||
27 | * path-absolute = "/" [ segment-nz *( "/" segment ) ] |
||
28 | * path-noscheme = segment-nz-nc *( "/" segment ) |
||
29 | * path-rootless = segment-nz *( "/" segment ) |
||
30 | * path-empty = 0<pchar> |
||
31 | * |
||
32 | * segment = *pchar |
||
33 | * segment-nz = 1*pchar |
||
34 | * segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) |
||
35 | * ; non-zero-length segment without any colon ":" |
||
36 | * |
||
37 | * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" |
||
38 | * |
||
39 | * @param string $path |
||
40 | */ |
||
41 | 87 | public function __construct($path) |
|
45 | |||
46 | /** |
||
47 | * Returns a string representation of the path formatted so that it can be compiled into a complete URI string |
||
48 | * per the Uri object's string specification. |
||
49 | * |
||
50 | * If the path is empty, toUriString returns an empty string; if the path is not empty, toUriString returns the |
||
51 | * path with one or more rules applied against an optional Authority to determine starting slashes: |
||
52 | * |
||
53 | * - If the path is rootless and an authority is present, the path MUST be prefixed by "/". |
||
54 | * - If the path is starting with more than one "/" and no authority is present, the starting slashes MUST be |
||
55 | * reduced to one. |
||
56 | * |
||
57 | * @see Uri::__toString |
||
58 | * |
||
59 | * @param Authority|null $authority [optional] An authority against which to derive starting slash rules |
||
60 | * |
||
61 | * @return string A string representation of the path formatted for a complete URI string |
||
62 | */ |
||
63 | 25 | public function toUriString(Authority $authority = null) |
|
73 | |||
74 | /** |
||
75 | * Validates whether a given path string conforms to the URI specification for a path provided an optional |
||
76 | * authority. If a non-empty path is provide along with a non-empty authority, the path must begin with a slash. |
||
77 | * |
||
78 | * Note that validatePathAgainstAuthority only validates that a path conforms to the slash requirement and not the |
||
79 | * validity of the path in general. For general path validation, use Path::isValid. |
||
80 | * |
||
81 | * @see Path::isValid |
||
82 | * @see Uri::withPath |
||
83 | * |
||
84 | * @throws \InvalidArgumentException provided a non-string path. |
||
85 | * |
||
86 | * @param string $path_string A path string |
||
87 | * @param Authority|null $authority [optional] An authority against which to check the path for validity |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | 30 | public static function validatePathAgainstAuthority($path_string, Authority $authority = null) |
|
101 | |||
102 | /** |
||
103 | * Throws an InvalidArgumentException if the given path is not a string. |
||
104 | * |
||
105 | * @throws \InvalidArgumentException given a non-string path. |
||
106 | * |
||
107 | * @param string $path The path to be checked |
||
108 | * |
||
109 | * @return void |
||
110 | */ |
||
111 | 30 | private static function checkPathIsString($path) |
|
117 | |||
118 | /** |
||
119 | * Checks whether a given path string starts with a slash. |
||
120 | * |
||
121 | * @throws \InvalidArgumentException given a non-string path. |
||
122 | * |
||
123 | * @param string $path The path to be checked |
||
124 | * |
||
125 | * @return bool Returns true if the path starts with a slash |
||
126 | * Returns false if the path does not start with a slash |
||
127 | */ |
||
128 | 25 | private static function startsWithSlash($path) |
|
136 | |||
137 | /** |
||
138 | * Determines whether a given authority should begin with a slash provided an Authority. |
||
139 | * |
||
140 | * @see Path::toUriString |
||
141 | * |
||
142 | * @param Authority|null $authority [optional] An authority against which to derive starting slash rules |
||
143 | * |
||
144 | * @return string The path string with appropriate starting slash rules applied |
||
145 | */ |
||
146 | 22 | private function normalizePathWithAuthority(Authority $authority = null) |
|
160 | |||
161 | /** |
||
162 | * Collapses starting slashes within a path if necessary given rules associated with an optional Authority. |
||
163 | * |
||
164 | * @see Path::toUriString |
||
165 | * |
||
166 | * @param string $path_string The path string to process |
||
167 | * @param Authority|null $authority [optional] An authority against which to derive starting slash rules |
||
168 | * |
||
169 | * @return string The path string with appropriate starting slash rules applied |
||
170 | */ |
||
171 | 22 | private function collapseStartingSlashes($path_string, Authority $authority = null) |
|
181 | } |
||
182 |