Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4658277
D2284.id5755.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D2284.id5755.diff
View Options
diff --git a/src/HTTP/Requests/WithURL.php b/src/HTTP/Requests/WithURL.php
--- a/src/HTTP/Requests/WithURL.php
+++ b/src/HTTP/Requests/WithURL.php
@@ -2,6 +2,7 @@
namespace Keruald\OmniTools\HTTP\Requests;
+use Keruald\OmniTools\HTTP\URL;
use Keruald\OmniTools\Strings\Multibyte\StringUtilities;
@@ -84,4 +85,22 @@
];
}
+ /**
+ * Create a URL object, using the current request server URL for protocol
+ * and domain name.
+ *
+ * @param string $query The query part of the URL [facultative]
+ * @param int $encodeMode Encoding to use for the query [facultative]
+ *
+ * @return \Keruald\OmniTools\HTTP\URL
+ */
+ public static function createLocalURL (string $query = "",
+ int $encodeMode = URL::ENCODE_RFC3986_SLASH_EXCEPTED
+ ) : URL {
+ $url = self::getServerURL();
+
+ return (new URL($url . "/"))
+ ->setQuery($query, $encodeMode);
+ }
+
}
diff --git a/tests/HTTP/Requests/RequestTest.php b/tests/HTTP/Requests/RequestTest.php
--- a/tests/HTTP/Requests/RequestTest.php
+++ b/tests/HTTP/Requests/RequestTest.php
@@ -79,6 +79,18 @@
$this->assertEquals($url, Request::getServerURL());
}
+ /**
+ * @backupGlobals enabled
+ * @dataProvider provideServerURLs
+ */
+ public function testCreateLocalURL (array $server, string $url) : void {
+ $_SERVER = $server;
+
+ $this->assertEquals($url . "/", Request::createLocalURL()->__toString());
+ $this->assertEquals($url . "/foo",
+ Request::createLocalURL("foo")->__toString());
+ }
+
///
/// Data providers
///
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Feb 25, 07:34 (18 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2439458
Default Alt Text
D2284.id5755.diff (1 KB)
Attached To
Mode
D2284: Build local URL
Attached
Detach File
Event Timeline
Log In to Comment