Skip to content

Commit 63a4a2d

Browse files
committed
deprecate HeaderBag::get and fix tests and dependencies
1 parent 6650234 commit 63a4a2d

14 files changed

+143
-132
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function prepare(Request $request)
209209

210210
if (self::$trustXSendfileTypeHeader && $request->headers->has('X-Sendfile-Type')) {
211211
// Use X-Sendfile, do not send any content.
212-
$type = $request->headers->get('X-Sendfile-Type');
212+
$type = $request->headers->getValue('X-Sendfile-Type');
213213
$path = $this->file->getRealPath();
214214
// Fall back to scheme://path for stream wrapped locations.
215215
if (false === $path) {
@@ -218,7 +218,7 @@ public function prepare(Request $request)
218218
if ('x-accel-redirect' === strtolower($type)) {
219219
// Do X-Accel-Mapping substitutions.
220220
// @link http://wiki.nginx.org/X-accel#X-Accel-Redirect
221-
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping', ''), ',=');
221+
$parts = HeaderUtils::split($request->headers->getValue('X-Accel-Mapping', ''), ',=');
222222
foreach ($parts as $part) {
223223
list($pathPrefix, $location) = $part;
224224
if (substr($path, 0, \strlen($pathPrefix)) === $pathPrefix) {
@@ -236,8 +236,8 @@ public function prepare(Request $request)
236236
}
237237
} elseif ($request->headers->has('Range')) {
238238
// Process the range headers.
239-
if (!$request->headers->has('If-Range') || $this->hasValidIfRangeHeader($request->headers->get('If-Range'))) {
240-
$range = $request->headers->get('Range');
239+
if (!$request->headers->has('If-Range') || $this->hasValidIfRangeHeader($request->headers->getValue('If-Range'))) {
240+
$range = $request->headers->getValue('Range');
241241

242242
list($start, $end) = explode('-', substr($range, 6), 2) + [0];
243243

src/Symfony/Component/HttpFoundation/HeaderBag.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ public function add(array $headers)
109109
*/
110110
public function get($key, $default = null, $first = true)
111111
{
112-
@trigger_error(sprintf('%s::%s is deprecated since Symfony 4.4, use %s::getFirst() or %s::getAll() instead.', __CLASS__, __METHOD__, __CLASS__, __CLASS__), E_USER_DEPRECATED);
112+
@trigger_error(sprintf('%s::%s is deprecated since Symfony 4.4 and will be removed in Symfony 5.0, use %s::getValue() or %s::getValues() instead.', __CLASS__, __METHOD__, __CLASS__, __CLASS__), E_USER_DEPRECATED);
113113
if (true === $first) {
114-
return $this->getFirst($key, $default);
114+
return $this->getValue($key, $default);
115115
}
116116

117-
return $this->getAll($key, $default);
117+
return $this->getValues($key, $default);
118118
}
119119

120-
public function getFirst($key, $default = null)
120+
public function getValue($key, ?string $default = null)
121121
{
122-
$all = $this->getAll($key, $default);
122+
$all = $this->getValues($key, $default);
123123

124124
if (\count($all)) {
125125
return isset($all[0]) ? $all[0] : null;
@@ -128,7 +128,10 @@ public function getFirst($key, $default = null)
128128
return $default;
129129
}
130130

131-
public function getAll($key, $default = null): array
131+
/**
132+
* @return string[]
133+
*/
134+
public function getValues($key, ?string $default = null): array
132135
{
133136
$key = str_replace('_', '-', strtolower($key));
134137
$headers = $this->all();
@@ -198,7 +201,7 @@ public function has($key)
198201
*/
199202
public function contains($key, $value)
200203
{
201-
return \in_array($value, $this->get($key, null, false));
204+
return \in_array($value, $this->getValues($key, null));
202205
}
203206

204207
/**
@@ -229,7 +232,7 @@ public function remove($key)
229232
*/
230233
public function getDate($key, \DateTime $default = null)
231234
{
232-
if (null === $value = $this->get($key)) {
235+
if (null === $value = $this->getValue($key)) {
233236
return $default;
234237
}
235238

src/Symfony/Component/HttpFoundation/JsonResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ protected function update()
210210

211211
// Only set the header when there is none or when it equals 'text/javascript' (from a previous update with callback)
212212
// in order to not overwrite a custom definition.
213-
if (!$this->headers->has('Content-Type') || 'text/javascript' === $this->headers->get('Content-Type')) {
213+
if (!$this->headers->has('Content-Type') || 'text/javascript' === $this->headers->getValue('Content-Type')) {
214214
$this->headers->set('Content-Type', 'application/json');
215215
}
216216

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public static function createFromGlobals()
280280
{
281281
$request = self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
282282

283-
if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
283+
if (0 === strpos($request->headers->getValue('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
284284
&& \in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])
285285
) {
286286
parse_str($request->getContent(), $data);
@@ -903,7 +903,7 @@ public function getPort()
903903
$host = $host[0];
904904
} elseif ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_X_FORWARDED_HOST)) {
905905
$host = $host[0];
906-
} elseif (!$host = $this->headers->get('HOST')) {
906+
} elseif (!$host = $this->headers->getValue('HOST')) {
907907
return $this->server->get('SERVER_PORT');
908908
}
909909

@@ -927,7 +927,7 @@ public function getPort()
927927
*/
928928
public function getUser()
929929
{
930-
return $this->headers->get('PHP_AUTH_USER');
930+
return $this->headers->getValue('PHP_AUTH_USER');
931931
}
932932

933933
/**
@@ -937,7 +937,7 @@ public function getUser()
937937
*/
938938
public function getPassword()
939939
{
940-
return $this->headers->get('PHP_AUTH_PW');
940+
return $this->headers->getValue('PHP_AUTH_PW');
941941
}
942942

943943
/**
@@ -1138,7 +1138,7 @@ public function getHost()
11381138
{
11391139
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_X_FORWARDED_HOST)) {
11401140
$host = $host[0];
1141-
} elseif (!$host = $this->headers->get('HOST')) {
1141+
} elseif (!$host = $this->headers->getValue('HOST')) {
11421142
if (!$host = $this->server->get('SERVER_NAME')) {
11431143
$host = $this->server->get('SERVER_ADDR', '');
11441144
}
@@ -1224,7 +1224,7 @@ public function getMethod()
12241224
return $this->method;
12251225
}
12261226

1227-
$method = $this->headers->get('X-HTTP-METHOD-OVERRIDE');
1227+
$method = $this->headers->getValue('X-HTTP-METHOD-OVERRIDE');
12281228

12291229
if (!$method && self::$httpMethodParameterOverride) {
12301230
$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
@@ -1373,7 +1373,7 @@ public function setRequestFormat($format)
13731373
*/
13741374
public function getContentType()
13751375
{
1376-
return $this->getFormat($this->headers->get('CONTENT_TYPE'));
1376+
return $this->getFormat($this->headers->getValue('CONTENT_TYPE'));
13771377
}
13781378

13791379
/**
@@ -1484,7 +1484,7 @@ public function isMethodCacheable()
14841484
public function getProtocolVersion()
14851485
{
14861486
if ($this->isFromTrustedProxy()) {
1487-
preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->get('Via'), $matches);
1487+
preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->getValue('Via'), $matches);
14881488

14891489
if ($matches) {
14901490
return 'HTTP/'.$matches[2];
@@ -1548,15 +1548,15 @@ public function getContent($asResource = false)
15481548
*/
15491549
public function getETags()
15501550
{
1551-
return preg_split('/\s*,\s*/', $this->headers->get('if_none_match'), null, PREG_SPLIT_NO_EMPTY);
1551+
return preg_split('/\s*,\s*/', $this->headers->getValue('if_none_match'), null, PREG_SPLIT_NO_EMPTY);
15521552
}
15531553

15541554
/**
15551555
* @return bool
15561556
*/
15571557
public function isNoCache()
15581558
{
1559-
return $this->headers->hasCacheControlDirective('no-cache') || 'no-cache' == $this->headers->get('Pragma');
1559+
return $this->headers->hasCacheControlDirective('no-cache') || 'no-cache' == $this->headers->getValue('Pragma');
15601560
}
15611561

15621562
/**
@@ -1605,7 +1605,7 @@ public function getLanguages()
16051605
return $this->languages;
16061606
}
16071607

1608-
$languages = AcceptHeader::fromString($this->headers->get('Accept-Language'))->all();
1608+
$languages = AcceptHeader::fromString($this->headers->getValue('Accept-Language'))->all();
16091609
$this->languages = [];
16101610
foreach ($languages as $lang => $acceptHeaderItem) {
16111611
if (false !== strpos($lang, '-')) {
@@ -1645,7 +1645,7 @@ public function getCharsets()
16451645
return $this->charsets;
16461646
}
16471647

1648-
return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all());
1648+
return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->getValue('Accept-Charset'))->all());
16491649
}
16501650

16511651
/**
@@ -1659,7 +1659,7 @@ public function getEncodings()
16591659
return $this->encodings;
16601660
}
16611661

1662-
return $this->encodings = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all());
1662+
return $this->encodings = array_keys(AcceptHeader::fromString($this->headers->getValue('Accept-Encoding'))->all());
16631663
}
16641664

16651665
/**
@@ -1673,7 +1673,7 @@ public function getAcceptableContentTypes()
16731673
return $this->acceptableContentTypes;
16741674
}
16751675

1676-
return $this->acceptableContentTypes = array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all());
1676+
return $this->acceptableContentTypes = array_keys(AcceptHeader::fromString($this->headers->getValue('Accept'))->all());
16771677
}
16781678

16791679
/**
@@ -1688,7 +1688,7 @@ public function getAcceptableContentTypes()
16881688
*/
16891689
public function isXmlHttpRequest()
16901690
{
1691-
return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
1691+
return 'XMLHttpRequest' == $this->headers->getValue('X-Requested-With');
16921692
}
16931693

16941694
/*
@@ -1959,13 +1959,13 @@ private function getTrustedValues($type, $ip = null)
19591959
$forwardedValues = [];
19601960

19611961
if ((self::$trustedHeaderSet & $type) && $this->headers->has(self::$trustedHeaders[$type])) {
1962-
foreach (explode(',', $this->headers->get(self::$trustedHeaders[$type])) as $v) {
1962+
foreach (explode(',', $this->headers->getValue(self::$trustedHeaders[$type])) as $v) {
19631963
$clientValues[] = (self::HEADER_X_FORWARDED_PORT === $type ? '0.0.0.0:' : '').trim($v);
19641964
}
19651965
}
19661966

19671967
if ((self::$trustedHeaderSet & self::HEADER_FORWARDED) && $this->headers->has(self::$trustedHeaders[self::HEADER_FORWARDED])) {
1968-
$forwarded = $this->headers->get(self::$trustedHeaders[self::HEADER_FORWARDED]);
1968+
$forwarded = $this->headers->getValue(self::$trustedHeaders[self::HEADER_FORWARDED]);
19691969
$parts = HeaderUtils::split($forwarded, ',;=');
19701970
$forwardedValues = [];
19711971
$param = self::$forwardedParams[$type];

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ public function prepare(Request $request)
280280
$charset = $this->charset ?: 'UTF-8';
281281
if (!$headers->has('Content-Type')) {
282282
$headers->set('Content-Type', 'text/html; charset='.$charset);
283-
} elseif (0 === stripos($headers->get('Content-Type'), 'text/') && false === stripos($headers->get('Content-Type'), 'charset')) {
283+
} elseif (0 === stripos($headers->getValue('Content-Type'), 'text/') && false === stripos($headers->getValue('Content-Type'), 'charset')) {
284284
// add the charset
285-
$headers->set('Content-Type', $headers->get('Content-Type').'; charset='.$charset);
285+
$headers->set('Content-Type', $headers->getValue('Content-Type').'; charset='.$charset);
286286
}
287287

288288
// Fix Content-Length
@@ -292,7 +292,7 @@ public function prepare(Request $request)
292292

293293
if ($request->isMethod('HEAD')) {
294294
// cf. RFC2616 14.13
295-
$length = $headers->get('Content-Length');
295+
$length = $headers->getValue('Content-Length');
296296
$this->setContent(null);
297297
if ($length) {
298298
$headers->set('Content-Length', $length);
@@ -306,7 +306,7 @@ public function prepare(Request $request)
306306
}
307307

308308
// Check if we need to send extra expire info headers
309-
if ('1.0' == $this->getProtocolVersion() && false !== strpos($headers->get('Cache-Control'), 'no-cache')) {
309+
if ('1.0' == $this->getProtocolVersion() && false !== strpos($headers->getValue('Cache-Control'), 'no-cache')) {
310310
$headers->set('pragma', 'no-cache');
311311
$headers->set('expires', -1);
312312
}
@@ -680,7 +680,7 @@ public function setDate(\DateTimeInterface $date)
680680
*/
681681
public function getAge(): int
682682
{
683-
if (null !== $age = $this->headers->get('Age')) {
683+
if (null !== $age = $this->headers->getValue('Age')) {
684684
return (int) $age;
685685
}
686686

@@ -898,7 +898,7 @@ public function setLastModified(\DateTimeInterface $date = null)
898898
*/
899899
public function getEtag(): ?string
900900
{
901-
return $this->headers->get('ETag');
901+
return $this->headers->getValue('ETag');
902902
}
903903

904904
/**
@@ -1014,7 +1014,7 @@ public function setNotModified()
10141014
*/
10151015
public function hasVary(): bool
10161016
{
1017-
return null !== $this->headers->get('Vary');
1017+
return null !== $this->headers->getValue('Vary');
10181018
}
10191019

10201020
/**
@@ -1024,7 +1024,7 @@ public function hasVary(): bool
10241024
*/
10251025
public function getVary(): array
10261026
{
1027-
if (!$vary = $this->headers->get('Vary', null, false)) {
1027+
if (!$vary = $this->headers->getValues('Vary', null)) {
10281028
return [];
10291029
}
10301030

@@ -1071,8 +1071,8 @@ public function isNotModified(Request $request): bool
10711071
}
10721072

10731073
$notModified = false;
1074-
$lastModified = $this->headers->get('Last-Modified');
1075-
$modifiedSince = $request->headers->get('If-Modified-Since');
1074+
$lastModified = $this->headers->getValue('Last-Modified');
1075+
$modifiedSince = $request->headers->getValue('If-Modified-Since');
10761076

10771077
if ($etags = $request->getETags()) {
10781078
$notModified = \in_array($this->getEtag(), $etags) || \in_array('*', $etags);
@@ -1188,7 +1188,7 @@ public function isNotFound(): bool
11881188
*/
11891189
public function isRedirect(string $location = null): bool
11901190
{
1191-
return \in_array($this->statusCode, [201, 301, 302, 303, 307, 308]) && (null === $location ?: $location == $this->headers->get('Location'));
1191+
return \in_array($this->statusCode, [201, 301, 302, 303, 307, 308]) && (null === $location ?: $location == $this->headers->getValue('Location'));
11921192
}
11931193

11941194
/**
@@ -1232,7 +1232,7 @@ public static function closeOutputBuffers(int $targetLevel, bool $flush)
12321232
*/
12331233
protected function ensureIEOverSSLCompatibility(Request $request)
12341234
{
1235-
if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && 1 == preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) && true === $request->isSecure()) {
1235+
if (false !== stripos($this->headers->getValue('Content-Disposition'), 'attachment') && 1 == preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) && true === $request->isSecure()) {
12361236
if ((int) preg_replace('/(MSIE )(.*?);/', '$2', $match[0]) < 9) {
12371237
$this->headers->remove('Cache-Control');
12381238
}

src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseHeaderSame.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function toString(): string
4040
*/
4141
protected function matches($response): bool
4242
{
43-
return $this->expectedValue === $response->headers->get($this->headerName, null, true);
43+
return $this->expectedValue === $response->headers->getValue($this->headerName, null, true);
4444
}
4545

4646
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy