comparison vendor/symfony/http-foundation/ResponseHeaderBag.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents 5311817fb629
children 12f9dff5fda9
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
22 const COOKIES_ARRAY = 'array'; 22 const COOKIES_ARRAY = 'array';
23 23
24 const DISPOSITION_ATTACHMENT = 'attachment'; 24 const DISPOSITION_ATTACHMENT = 'attachment';
25 const DISPOSITION_INLINE = 'inline'; 25 const DISPOSITION_INLINE = 'inline';
26 26
27 protected $computedCacheControl = array(); 27 protected $computedCacheControl = [];
28 protected $cookies = array(); 28 protected $cookies = [];
29 protected $headerNames = array(); 29 protected $headerNames = [];
30 30
31 public function __construct(array $headers = array()) 31 public function __construct(array $headers = [])
32 { 32 {
33 parent::__construct($headers); 33 parent::__construct($headers);
34 34
35 if (!isset($this->headers['cache-control'])) { 35 if (!isset($this->headers['cache-control'])) {
36 $this->set('Cache-Control', ''); 36 $this->set('Cache-Control', '');
47 * 47 *
48 * @return array An array of headers 48 * @return array An array of headers
49 */ 49 */
50 public function allPreserveCase() 50 public function allPreserveCase()
51 { 51 {
52 $headers = array(); 52 $headers = [];
53 foreach ($this->all() as $name => $value) { 53 foreach ($this->all() as $name => $value) {
54 $headers[isset($this->headerNames[$name]) ? $this->headerNames[$name] : $name] = $value; 54 $headers[isset($this->headerNames[$name]) ? $this->headerNames[$name] : $name] = $value;
55 } 55 }
56 56
57 return $headers; 57 return $headers;
68 } 68 }
69 69
70 /** 70 /**
71 * {@inheritdoc} 71 * {@inheritdoc}
72 */ 72 */
73 public function replace(array $headers = array()) 73 public function replace(array $headers = [])
74 { 74 {
75 $this->headerNames = array(); 75 $this->headerNames = [];
76 76
77 parent::replace($headers); 77 parent::replace($headers);
78 78
79 if (!isset($this->headers['cache-control'])) { 79 if (!isset($this->headers['cache-control'])) {
80 $this->set('Cache-Control', ''); 80 $this->set('Cache-Control', '');
105 { 105 {
106 $uniqueKey = str_replace('_', '-', strtolower($key)); 106 $uniqueKey = str_replace('_', '-', strtolower($key));
107 107
108 if ('set-cookie' === $uniqueKey) { 108 if ('set-cookie' === $uniqueKey) {
109 if ($replace) { 109 if ($replace) {
110 $this->cookies = array(); 110 $this->cookies = [];
111 } 111 }
112 foreach ((array) $values as $cookie) { 112 foreach ((array) $values as $cookie) {
113 $this->setCookie(Cookie::fromString($cookie)); 113 $this->setCookie(Cookie::fromString($cookie));
114 } 114 }
115 $this->headerNames[$uniqueKey] = $key; 115 $this->headerNames[$uniqueKey] = $key;
120 $this->headerNames[$uniqueKey] = $key; 120 $this->headerNames[$uniqueKey] = $key;
121 121
122 parent::set($key, $values, $replace); 122 parent::set($key, $values, $replace);
123 123
124 // ensure the cache-control header has sensible defaults 124 // ensure the cache-control header has sensible defaults
125 if (\in_array($uniqueKey, array('cache-control', 'etag', 'last-modified', 'expires'), true)) { 125 if (\in_array($uniqueKey, ['cache-control', 'etag', 'last-modified', 'expires'], true)) {
126 $computed = $this->computeCacheControlValue(); 126 $computed = $this->computeCacheControlValue();
127 $this->headers['cache-control'] = array($computed); 127 $this->headers['cache-control'] = [$computed];
128 $this->headerNames['cache-control'] = 'Cache-Control'; 128 $this->headerNames['cache-control'] = 'Cache-Control';
129 $this->computedCacheControl = $this->parseCacheControl($computed); 129 $this->computedCacheControl = $this->parseCacheControl($computed);
130 } 130 }
131 } 131 }
132 132
137 { 137 {
138 $uniqueKey = str_replace('_', '-', strtolower($key)); 138 $uniqueKey = str_replace('_', '-', strtolower($key));
139 unset($this->headerNames[$uniqueKey]); 139 unset($this->headerNames[$uniqueKey]);
140 140
141 if ('set-cookie' === $uniqueKey) { 141 if ('set-cookie' === $uniqueKey) {
142 $this->cookies = array(); 142 $this->cookies = [];
143 143
144 return; 144 return;
145 } 145 }
146 146
147 parent::remove($key); 147 parent::remove($key);
148 148
149 if ('cache-control' === $uniqueKey) { 149 if ('cache-control' === $uniqueKey) {
150 $this->computedCacheControl = array(); 150 $this->computedCacheControl = [];
151 } 151 }
152 152
153 if ('date' === $uniqueKey) { 153 if ('date' === $uniqueKey) {
154 $this->initDate(); 154 $this->initDate();
155 } 155 }
214 * 214 *
215 * @throws \InvalidArgumentException When the $format is invalid 215 * @throws \InvalidArgumentException When the $format is invalid
216 */ 216 */
217 public function getCookies($format = self::COOKIES_FLAT) 217 public function getCookies($format = self::COOKIES_FLAT)
218 { 218 {
219 if (!in_array($format, array(self::COOKIES_FLAT, self::COOKIES_ARRAY))) { 219 if (!\in_array($format, [self::COOKIES_FLAT, self::COOKIES_ARRAY])) {
220 throw new \InvalidArgumentException(sprintf('Format "%s" invalid (%s).', $format, implode(', ', array(self::COOKIES_FLAT, self::COOKIES_ARRAY)))); 220 throw new \InvalidArgumentException(sprintf('Format "%s" invalid (%s).', $format, implode(', ', [self::COOKIES_FLAT, self::COOKIES_ARRAY])));
221 } 221 }
222 222
223 if (self::COOKIES_ARRAY === $format) { 223 if (self::COOKIES_ARRAY === $format) {
224 return $this->cookies; 224 return $this->cookies;
225 } 225 }
226 226
227 $flattenedCookies = array(); 227 $flattenedCookies = [];
228 foreach ($this->cookies as $path) { 228 foreach ($this->cookies as $path) {
229 foreach ($path as $cookies) { 229 foreach ($path as $cookies) {
230 foreach ($cookies as $cookie) { 230 foreach ($cookies as $cookie) {
231 $flattenedCookies[] = $cookie; 231 $flattenedCookies[] = $cookie;
232 } 232 }
265 * 265 *
266 * @see RFC 6266 266 * @see RFC 6266
267 */ 267 */
268 public function makeDisposition($disposition, $filename, $filenameFallback = '') 268 public function makeDisposition($disposition, $filename, $filenameFallback = '')
269 { 269 {
270 if (!in_array($disposition, array(self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE))) { 270 if (!\in_array($disposition, [self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE])) {
271 throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE)); 271 throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
272 } 272 }
273 273
274 if ('' == $filenameFallback) { 274 if ('' == $filenameFallback) {
275 $filenameFallback = $filename; 275 $filenameFallback = $filename;