1 | <?php |
||
9 | class Uri |
||
10 | { |
||
11 | /** |
||
12 | * @var string $uri The boxed uri string. |
||
13 | */ |
||
14 | private $uri; |
||
15 | |||
16 | |||
17 | |||
18 | /** |
||
19 | * Uri constructor. |
||
20 | * |
||
21 | * @param string $uri Initial uri-string. |
||
22 | */ |
||
23 | 33 | public function __construct($uri) |
|
27 | |||
28 | |||
29 | |||
30 | /** |
||
31 | * Check if uri is empty by php standards with exception "0" string |
||
32 | * (see http://php.net/manual/en/function.empty.php). |
||
33 | * |
||
34 | * @return bool |
||
35 | */ |
||
36 | 9 | public function isEmpty() |
|
40 | |||
41 | |||
42 | |||
43 | /** |
||
44 | * Check if uri starts with string. |
||
45 | * |
||
46 | * Private helper class helper. |
||
47 | * |
||
48 | * @param string $string String to check for in start of uri. |
||
49 | * |
||
50 | * @return bool True if uri strarts with $string. |
||
51 | */ |
||
52 | 1 | private function uriBeginsWith($string) |
|
57 | |||
58 | |||
59 | |||
60 | /** |
||
61 | * Check if uri starts with one or more strings. |
||
62 | * |
||
63 | * @param string ...$string Strings to check for in start of uri. |
||
64 | * |
||
65 | * @return bool True if uri strarts with $string. |
||
66 | */ |
||
67 | public function startsWith(...$strings) |
||
73 | |||
74 | |||
75 | |||
76 | /** |
||
77 | * Prepend this uri with another uri with a slash inbetween. |
||
78 | * |
||
79 | * Example: |
||
80 | * $relativeUri = new Uri("about"); // $relativeUrl->uri() == "about" |
||
81 | * $baseUrl = new Uri("http://dbwebb.se"); // $baseUrl->uri() == "http://dbwebb.se" |
||
82 | * $urlString = $relativeUri->prepend($baseUrl)->uri(); // $urlString == "http://dbwebb.se/about" |
||
83 | * |
||
84 | * @param Uri $uri Uri to prepend this uri |
||
85 | * |
||
86 | * @return Uri self Reference to this Uri for chaining. |
||
87 | */ |
||
88 | 7 | public function prepend(Uri $uri) |
|
93 | |||
94 | |||
95 | |||
96 | /** |
||
97 | * Appends supplied $uri to this uri with a slash inbetween. |
||
98 | * |
||
99 | * Example: |
||
100 | * $relativeUri = new Uri("about"); // $relativeUrl->uri() == "about" |
||
101 | * $baseUrl = new Uri("http://dbwebb.se"); // $baseUrl->uri() == "http://dbwebb.se" |
||
102 | * $urlString = $baseUri->append($relativeUri)->uri(); // $urlString == "http://dbwebb.se/about" |
||
103 | * |
||
104 | * @param Uri $uri Uri to append this uri |
||
105 | * |
||
106 | * @return Uri self Reference to this Uri for chaining. |
||
107 | */ |
||
108 | 7 | public function append(Uri $uri) |
|
113 | |||
114 | |||
115 | |||
116 | /** |
||
117 | * Remove the basename part of uri if it is same as argument. |
||
118 | * |
||
119 | * Example: |
||
120 | * $theUri = new Uri("http://dbwebb.se/about/this.html"); |
||
121 | * theUri->removeBasename("index.html"); // theUri->uri() == "http://dbwebb.se/about/this.html" |
||
122 | * theUri->removeBasename("this.html"); // theUri->uri() == "http://dbwebb.se/about" |
||
123 | * |
||
124 | * @param string $basename The basename to remove. |
||
125 | * |
||
126 | * @return Uri self Reference to this Uri for chaining. |
||
127 | */ |
||
128 | 9 | public function removeBasename($basename) |
|
135 | |||
136 | |||
137 | |||
138 | /** |
||
139 | * Get the boxed uri as string without any trailing slash. |
||
140 | * |
||
141 | * @return string The uri |
||
142 | */ |
||
143 | 22 | public function uri() |
|
147 | } |
||
148 |