aboutsummaryrefslogtreecommitdiffhomepage
path: root/misc
diff options
context:
space:
mode:
authorwinter2024-12-06 20:43:26 +0000
committerwinter2024-12-06 20:43:26 +0000
commite1ad307b531c27ec6bfaf8b4d018991b0d4a78f3 (patch)
tree4ef08af2b4051d433bb929d5162474ac6777cab1 /misc
initial commit
hardcoded functionality mostly!
Diffstat (limited to 'misc')
-rw-r--r--misc/json_response.php11
-rw-r--r--misc/path_to_uri.php16
2 files changed, 27 insertions, 0 deletions
diff --git a/misc/json_response.php b/misc/json_response.php
new file mode 100644
index 0000000..4244b64
--- /dev/null
+++ b/misc/json_response.php
@@ -0,0 +1,11 @@
+<?php
+
+function json_response(
+ mixed $value,
+ string $contentType = 'application/json',
+ int $flags = 0,
+ int $depth = 512
+) {
+ header("Content-Type: $contentType");
+ echo json_encode($value, $flags, $depth);
+} \ No newline at end of file
diff --git a/misc/path_to_uri.php b/misc/path_to_uri.php
new file mode 100644
index 0000000..756640e
--- /dev/null
+++ b/misc/path_to_uri.php
@@ -0,0 +1,16 @@
+<?php
+
+use WpfTest\GlobalConfig;
+
+
+/**
+ * Converts an absolute path into an absolute URI based on the instance's base path
+ * @param string $path absolute path (i.e. must start with a `/`)
+ * @return string absolute URI
+ */
+function path_to_uri(string $path): string {
+ if (!str_starts_with($path, '/')) {
+ throw new InvalidArgumentException('path must be absolute (start with a `/`');
+ }
+ return GlobalConfig::getInstance()->getBasePath() . $path;
+} \ No newline at end of file