1 <?php namespace Modulework\Modules\Http\Utilities;
2 /*
3 * (c) Christian Gärtner <christiangaertner.film@googlemail.com>
4 * This file is part of the Modulework Framework
5 * License: View distributed LICENSE file
6 */
7
8
9 /**
10 * {@inheritdoc}
11 * Adds:
12 * - getDate()
13 */
14 class HeaderCase extends ArrayCase {
15
16 /**
17 * Get the header value converted to a date
18 * @param string $key The header name
19 * @param \DateTime $default The default value
20 * @return null|\DateTime The parsed DateTime or default
21 *
22 * @throws \RuntimeExecptopm when header not parseable by \DateTime
23 */
24 public function getDate($key, \DateTime $default = null)
25 {
26 if (null === $val = $this->get($key)) return $default;
27 if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $val)) throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $val));
28 return $date;
29 }
30
31 public function showForResponse()
32 {
33 return implode("\r\n", $this->all());
34 }
35 }