diff options
Diffstat (limited to 'misc')
| -rw-r--r-- | misc/json_response.php | 11 | ||||
| -rw-r--r-- | misc/path_to_uri.php | 16 |
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 |
