Add PHPDocs generated by ChatGPT,

add additional clarification to some functions,
add addNewsComment function and API, currently untested and not implemented in the client,
fix a bunch of stuff that PHPStorm pointed out
This commit is contained in:
2024-04-28 22:37:23 +02:00
parent 6e7df7f034
commit 1c9f5cf3c0
17 changed files with 659 additions and 142 deletions

View File

@@ -1,6 +1,16 @@
<?php
function runEndpoint($endpoint_file): ?array
/**
* Executes an endpoint script and returns the results.
*
* This function includes an endpoint PHP file that defines a function named `endpoint` which
* is expected to accept an array parameter and return an array result.
* It simply scopes an external file into a function to prevent variable conflicts.
*
* @param string $endpoint_file The path to the endpoint PHP file.
* @return array|null Returns the result of the endpoint function if successful, or null if the
* endpoint function or file does not behave as expected.
*/
function runEndpoint(string $endpoint_file): ?array
{
$endpoint_data = $_POST;
@@ -9,8 +19,20 @@ function runEndpoint($endpoint_file): ?array
return endpoint($endpoint_data);
}
function getEndpoint($endpoint_name): string
/**
* Retrieves and processes the output of a specified endpoint.
*
* This function determines the appropriate endpoint PHP file based on the provided endpoint name,
* executes the endpoint, and returns its results as a JSON-encoded string. It handles and
* translates different return types into a JSON format and manages HTTP response codes based on
* success or failure of the endpoint execution.
*
* @param string $endpoint_name The name of the endpoint, which is used to construct the file path to the endpoint script.
* @return string A JSON-encoded string representing the result of the endpoint, including a status indicator and any relevant data or error messages.
*@global array $routerRequest Current request data that might influence the endpoint processing.
* @global array $routerConfig Global configuration that contains paths and settings.
*/
function getEndpoint(string $endpoint_name): string
{
$output = array();
$output["Status"] = "Fail";