public function HeaderBag::get

Returns a header value by name.

@api

Parameters

string $key The header name:

mixed $default The default value:

Boolean $first Whether to return the first value or all header values:

Return value

string|array The first header value if $first is true, an array of values otherwise

2 calls to HeaderBag::get()
HeaderBag::contains in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/HeaderBag.php
Returns true if the given HTTP header contains the given value.
HeaderBag::getDate in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/HeaderBag.php
Returns the HTTP header value converted to a date.

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/HeaderBag.php, line 128

Class

HeaderBag
HeaderBag is a container for HTTP headers.

Namespace

Symfony\Component\HttpFoundation

Code

public function get($key, $default = null, $first = true) {
  $key = strtr(strtolower($key), '_', '-');
  if (!array_key_exists($key, $this->headers)) {
    if (null === $default) {
      return $first ? null : array();
    }
    return $first ? $default : array(
      $default,
    );
  }
  if ($first) {
    return count($this->headers[$key]) ? $this->headers[$key][0] : $default;
  }
  return $this->headers[$key];
}