Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/http-foundation/HeaderBag.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/vendor/symfony/http-foundation/HeaderBag.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/symfony/http-foundation/HeaderBag.php Mon Apr 23 09:46:53 2018 +0100 @@ -22,8 +22,6 @@ protected $cacheControl = array(); /** - * Constructor. - * * @param array $headers An array of HTTP headers */ public function __construct(array $headers = array()) @@ -40,14 +38,14 @@ */ public function __toString() { - if (!$this->headers) { + if (!$headers = $this->all()) { return ''; } - $max = max(array_map('strlen', array_keys($this->headers))) + 1; + ksort($headers); + $max = max(array_map('strlen', array_keys($headers))) + 1; $content = ''; - ksort($this->headers); - foreach ($this->headers as $name => $values) { + foreach ($headers as $name => $values) { $name = implode('-', array_map('ucfirst', explode('-', $name))); foreach ($values as $value) { $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value); @@ -74,7 +72,7 @@ */ public function keys() { - return array_keys($this->headers); + return array_keys($this->all()); } /** @@ -103,17 +101,18 @@ /** * Returns a header value by name. * - * @param string $key The header name - * @param mixed $default The default value - * @param bool $first Whether to return the first value or all header values + * @param string $key The header name + * @param string|string[] $default The default value + * @param bool $first Whether to return the first value or all header values * - * @return string|array The first header value if $first is true, an array of values otherwise + * @return string|string[] The first header value or default value if $first is true, an array of values otherwise */ public function get($key, $default = null, $first = true) { $key = str_replace('_', '-', strtolower($key)); + $headers = $this->all(); - if (!array_key_exists($key, $this->headers)) { + if (!array_key_exists($key, $headers)) { if (null === $default) { return $first ? null : array(); } @@ -122,33 +121,41 @@ } if ($first) { - return count($this->headers[$key]) ? $this->headers[$key][0] : $default; + return \count($headers[$key]) ? $headers[$key][0] : $default; } - return $this->headers[$key]; + return $headers[$key]; } /** * Sets a header by name. * - * @param string $key The key - * @param string|array $values The value or an array of values - * @param bool $replace Whether to replace the actual value or not (true by default) + * @param string $key The key + * @param string|string[] $values The value or an array of values + * @param bool $replace Whether to replace the actual value or not (true by default) */ public function set($key, $values, $replace = true) { $key = str_replace('_', '-', strtolower($key)); - $values = array_values((array) $values); + if (\is_array($values)) { + $values = array_values($values); - if (true === $replace || !isset($this->headers[$key])) { - $this->headers[$key] = $values; + if (true === $replace || !isset($this->headers[$key])) { + $this->headers[$key] = $values; + } else { + $this->headers[$key] = array_merge($this->headers[$key], $values); + } } else { - $this->headers[$key] = array_merge($this->headers[$key], $values); + if (true === $replace || !isset($this->headers[$key])) { + $this->headers[$key] = array($values); + } else { + $this->headers[$key][] = $values; + } } if ('cache-control' === $key) { - $this->cacheControl = $this->parseCacheControl($values[0]); + $this->cacheControl = $this->parseCacheControl(implode(', ', $this->headers[$key])); } } @@ -161,7 +168,7 @@ */ public function has($key) { - return array_key_exists(str_replace('_', '-', strtolower($key)), $this->headers); + return array_key_exists(str_replace('_', '-', strtolower($key)), $this->all()); } /**