diff --git a/api/db.php b/api/db.php index e976618..e3b08d9 100644 --- a/api/db.php +++ b/api/db.php @@ -1,8 +1,8 @@ $message], $status_code); @@ -33,7 +37,7 @@ function error_response($message, $status_code = 400) { // --------------------------------------------------------------------- // Validate Required Fields -// Checks if all specified Fields exist in the given Data Array and are +// Checks if specified Fields exist in the given Data Array and are // non-empty. Returns an Array of missing Field Names, or an empty // Array if all Fields are present. // --------------------------------------------------------------------- @@ -41,28 +45,28 @@ function validate_required($data, $fields) { $missing = []; foreach ($fields as $field) { + // Checks if Fields exists in Data Array and are not empty if (!isset($data[$field]) || trim($data[$field]) === '') { $missing[] = $field; } } - + // Returns Array of missing Fields or emty Array return $missing; } // --------------------------------------------------------------------- // Get POST Input -// Reads and trims all POST Parameters. Returns an associative Array. -// Falls back to JSON Request Body if no POST Data is present -// (for Clients that send JSON instead of Form Data). +// Reads POST Parameters. Returns an associative Array. +// Fallback to JSON Request Body if no POST Data is present. // --------------------------------------------------------------------- function get_input() { - // Check for standard POST Form Data first + // Checks for standard POST Requests if (!empty($_POST)) { return array_map('trim', $_POST); } - // Fall back to JSON Request Body + // Fall back for JSON POST Requests $json = file_get_contents('php://input'); $data = json_decode($json, true); @@ -76,8 +80,8 @@ function get_input() { // --------------------------------------------------------------------- // Get PDO Connection -// Returns the PDO Instance created in init.php. Wrapped in a Function -// to avoid global Variable Dependencies in Endpoint Files. +// Returns PDO Instance wrapped in a Function to prevent global +// Variable Dependencies in Endpoint Files. // --------------------------------------------------------------------- function get_db() { global $pdo;