<?php
/**
* Binds arguments for headers metadata.
*
* This function simplifies the process of setting header metadata,
* particularly for internal tooling.
*
* @param array $args An associative array of arguments. Keys are header names,
* values are the corresponding header values.
* @return array An associative array containing the headers to be set.
*/
function bindHeadersMetadata(array $args): array
{
$headers = [];
foreach ($args as $headerName => $headerValue) {
// Ensure headerName is a string
if (!is_string($headerName)) {
continue; // Skip if not a string
}
// Ensure headerValue is a string
if (!is_string($headerValue)) {
continue; // Skip if not a string
}
// Set the header
header($headerName . ': ' . $headerValue, true); // true to bypass content-type check
$headers[$headerName] = $headerValue; // store for logging or debugging
}
return $headers;
}
?>
Add your comment