You are here

public function HeaderBag::__toString in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/HeaderBag.php \Symfony\Component\HttpFoundation\HeaderBag::__toString()

Returns the headers as a string.

Return value

string The headers

1 call to HeaderBag::__toString()
ResponseHeaderBag::__toString in vendor/symfony/http-foundation/ResponseHeaderBag.php
Returns the headers as a string.
1 method overrides HeaderBag::__toString()
ResponseHeaderBag::__toString in vendor/symfony/http-foundation/ResponseHeaderBag.php
Returns the headers as a string.

File

vendor/symfony/http-foundation/HeaderBag.php, line 41

Class

HeaderBag
HeaderBag is a container for HTTP headers.

Namespace

Symfony\Component\HttpFoundation

Code

public function __toString() {
  if (!$this->headers) {
    return '';
  }
  $max = max(array_map('strlen', array_keys($this->headers))) + 1;
  $content = '';
  ksort($this->headers);
  foreach ($this->headers as $name => $values) {
    $name = implode('-', array_map('ucfirst', explode('-', $name)));
    foreach ($values as $value) {
      $content .= sprintf("%-{$max}s %s\r\n", $name . ':', $value);
    }
  }
  return $content;
}