function HeaderBag::getDate
Returns the HTTP header value converted to a date.
Throws
\RuntimeException When the HTTP header is not parseable
File
-
vendor/
symfony/ http-foundation/ HeaderBag.php, line 190
Class
- HeaderBag
- HeaderBag is a container for HTTP headers.
Namespace
Symfony\Component\HttpFoundationCode
public function getDate(string $key, ?\DateTimeInterface $default = null) : ?\DateTimeImmutable {
if (null === ($value = $this->get($key))) {
return null !== $default ? \DateTimeImmutable::createFromInterface($default) : null;
}
if (false === ($date = \DateTimeImmutable::createFromFormat(\DATE_RFC2822, $value))) {
throw new \RuntimeException(\sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value));
}
return $date;
}