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 | 106 | 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 | 9 | 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) |
|
107 | |||
108 | /** |
||
109 | * Determines whether a given authority should begin with a slash provided an Authority. |
||
110 | * |
||
111 | * @see Path::toUriString |
||
112 | * |
||
113 | * @param Authority|null $authority [optional] An authority against which to derive starting slash rules |
||
114 | * |
||
115 | * @return string The path string with appropriate starting slash rules applied |
||
116 | */ |
||
117 | 9 | private function normalizePathWithAuthority(Authority $authority = null) |
|
131 | |||
132 | /** |
||
133 | * Collapses starting slashes within a path if necessary given rules associated with an optional Authority. |
||
134 | * |
||
135 | * @see Path::toUriString |
||
136 | * |
||
137 | * @param string $path_string The path string to proceess |
||
138 | * @param Authority|null $authority [optional] An authority against which to derive starting slash rules |
||
139 | * |
||
140 | * @return string The path string with appropriate starting slash rules applied |
||
141 | */ |
||
142 | 7 | private function collapseStartingSlashes($path_string, Authority $authority = null) |
|
152 | } |
||
153 |