1. <?php
  2. /**
  3. * Binds arguments for headers metadata.
  4. *
  5. * This function simplifies the process of setting header metadata,
  6. * particularly for internal tooling.
  7. *
  8. * @param array $args An associative array of arguments. Keys are header names,
  9. * values are the corresponding header values.
  10. * @return array An associative array containing the headers to be set.
  11. */
  12. function bindHeadersMetadata(array $args): array
  13. {
  14. $headers = [];
  15. foreach ($args as $headerName => $headerValue) {
  16. // Ensure headerName is a string
  17. if (!is_string($headerName)) {
  18. continue; // Skip if not a string
  19. }
  20. // Ensure headerValue is a string
  21. if (!is_string($headerValue)) {
  22. continue; // Skip if not a string
  23. }
  24. // Set the header
  25. header($headerName . ': ' . $headerValue, true); // true to bypass content-type check
  26. $headers[$headerName] = $headerValue; // store for logging or debugging
  27. }
  28. return $headers;
  29. }
  30. ?>

Add your comment