8000 [HttpFoundation] remove deprecations · symfony/symfony@8312f90 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8312f90

Browse files
azjezznicolas-grekas
authored andcommitted
[HttpFoundation] remove deprecations
Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent 526144a commit 8312f90

23 files changed

+77
-724
lines changed

UPGRADE-6.0.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,15 @@ HttpFoundation
9696
* Removed `Response::create()`, `JsonResponse::create()`,
9797
`RedirectResponse::create()`, `StreamedResponse::create()` and
9898
`BinaryFileResponse::create()` methods (use `__construct()` instead)
99-
* Not passing a `Closure` together with `FILTER_CALLBACK` to `ParameterBag::filter()` throws an `InvalidArgumentException`; wrap your filter in a closure instead.
100-
* Removed the `Request::HEADER_X_FORWARDED_ALL` constant, use either `Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO` or `Request::HEADER_X_FORWARDED_AWS_ELB` or `Request::HEADER_X_FORWARDED_TRAEFIK`constants instead.
99+
* Not passing a `Closure` together with `FILTER_CALLBACK` to `ParameterBag::filter()` throws an `\InvalidArgumentException`; wrap your filter in a closure instead
100+
* Not passing a `Closure` together with `FILTER_CALLBACK` to `InputBag::filter()` throws an `\InvalidArgumentException`; wrap your filter in a closure instead
101+
* Removed the `Request::HEADER_X_FORWARDED_ALL` constant, use either `Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO` or `Request::HEADER_X_FORWARDED_AWS_ELB` or `Request::HEADER_X_FORWARDED_TRAEFIK`constants instead
101102
* Rename `RequestStack::getMasterRequest()` to `getMainRequest()`
103+
* Not passing `FILTER_REQUIRE_ARRAY` or `FILTER_FORCE_ARRAY` flags to `InputBag::filter()` when filtering an array will throw `BadRequestException`
104+
* Removed the `Request::HEADER_X_FORWARDED_ALL` constant
105+
* Retrieving non-scalar values using `InputBag::get()` will throw `BadRequestException` (use `InputBad::all()` instead to retrieve an array)
106+
* Passing non-scalar default value as the second argument `InputBag::get()` will throw `\InvalidArgumentException`
107+
* Passing non-scalar, non-array value as the second argument `InputBag::set()` will throw `\InvalidArgumentException`
102108

103109
HttpKernel
104110
----------

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,6 @@ public function __construct($file, int $status = 200, array $headers = [], bool
5555
}
5656
}
5757

58-
/**
59-
* @param \SplFileInfo|string $file The file to stream
60-
* @param int $status The response status code
61-
* @param array $headers An array of response headers
62-
* @param bool $public Files are public by default
63-
* @param string|null $contentDisposition The type of Content-Disposition to set automatically with the filename
64-
* @param bool $autoEtag Whether the ETag header should be automatically set
65-
* @param bool $autoLastModified Whether the Last-Modified header should be automatically set
66-
*
67-
* @return static
68-
*
69-
* @deprecated since Symfony 5.2, use __construct() instead.
70-
*/
71-
public static function create($file = null, int $status = 200, array $headers = [], bool $public = true, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)
72-
{
73-
trigger_deprecation('symfony/http-foundation', '5.2', 'The "%s()" method is deprecated, use "new %s()" instead.', __METHOD__, static::class);
74-
75-
return new static($file, $status, $headers, $public, $contentDisposition, $autoEtag, $autoLastModified);
76-
}
77-
7858
/**
7959
* Sets the file to stream.
8060
*

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
CHANGELOG
22
=========
33

4+
6.0
5+
---
6+
7+
* Remove the `NamespacedAttributeBag` class
8+
* Removed `Response::create()`, `JsonResponse::create()`,
9+
`RedirectResponse::create()`, `StreamedResponse::create()` and
10+
`BinaryFileResponse::create()` methods (use `__construct()` instead)
11+
* Not passing a `Closure` together with `FILTER_CALLBACK` to `ParameterBag::filter()` throws an `\InvalidArgumentException`; wrap your filter in a closure instead
12+
* Not passing a `Closure` together with `FILTER_CALLBACK` to `InputBag::filter()` throws an `\InvalidArgumentException`; wrap your filter in a closure instead
13+
* Removed the `Request::HEADER_X_FORWARDED_ALL` constant, use either `Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO` or `Request::HEADER_X_FORWARDED_AWS_ELB` or `Request::HEADER_X_FORWARDED_TRAEFIK`constants instead
14+
* Rename `RequestStack::getMasterRequest()` to `getMainRequest()`
15+
* Not passing `FILTER_REQUIRE_ARRAY` or `FILTER_FORCE_ARRAY` flags to `InputBag::filter()` when filtering an array will throw `BadRequestException`
16+
* Removed the `Request::HEADER_X_FORWARDED_ALL` constant
17+
* Retrieving non-scalar values using `InputBag::get()` will throw `BadRequestException` (use `InputBad::all()` instead to retrieve an array)
18+
* Passing non-scalar default value as the second argument `InputBag::get()` will throw `\InvalidArgumentException`
19+
* Passing non-scalar, non-array value as the second argument `InputBag::set()` will throw `\InvalidArgumentException`
20+
421
5.3
522
---
623

src/Symfony/Component/HttpFoundation/InputBag.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* InputBag is a container for user input values such as $_GET, $_POST, $_REQUEST, and $_COOKIE.
1818
*
19-
* @author Saif Eddin Gmati <saif.gmati@symfony.com>
19+
* @author Saif Eddin Gmati <azjezz@protonmail.com>
2020
*/
2121
final class InputBag extends ParameterBag
2222
{
@@ -30,13 +30,13 @@ final class InputBag extends ParameterBag
3030
public function get(string $key, $default = null)
3131
{
3232
if (null !== $default && !is_scalar($default) && !(\is_object($default) && method_exists($default, '__toString'))) {
33-
trigger_deprecation('symfony/http-foundation', '5.1', 'Passing a non-scalar value as 2nd argument to "%s()" is deprecated, pass a scalar or null instead.', __METHOD__);
33+
throw new \InvalidArgumentException(sprintf('Excepted a scalar value as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($default)));
3434
}
3535

3636
$value = parent::get($key, $this);
3737

38-
if (null !== $value && $this !== $value && !is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
39-
trigger_deprecation('symfony/http-foundation', '5.1', 'Retrieving a non-string value from "%s()" is deprecated, and will throw a "%s" exception in Symfony 6.0, use "%s::all($key)" instead.', __METHOD__, BadRequestException::class, __CLASS__);
38+
if (null !== $value && $this !== $value && !is_scalar($value)) {
39+
throw new BadRequestException(sprintf('Input value "%s" contains a non-scalar value.', $key));
4040
}
4141

4242
return $this === $value ? $default : $value;
@@ -76,8 +76,8 @@ public function add(array $inputs = [])
7676
*/
7777
public function set(string $key, $value)
7878
{
79-
if (null !== $value && !is_scalar($value) && !\is_array($value) && !method_exists($value, '__toString')) {
80-
trigger_deprecation('symfony/http-foundation', '5.1', 'Passing "%s" as a 2nd Argument to "%s()" is deprecated, pass a scalar, array, or null instead.', get_debug_type($value), __METHOD__);
79+
if (null !== $value && !is_scalar($value) && !\is_array($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
80+
throw new \InvalidArgumentException(sprintf('Excepted a scalar, or an array as a 2nd argument to "%s()", "%s" given.', __METHOD__, get_debug_type($value)));
8181
}
8282

8383
$this->parameters[$key] = $value;
@@ -96,16 +96,11 @@ public function filter(string $key, $default = null, int $filter = \FILTER_DEFAU
9696
}
9797

9898
if (\is_array($value) && !(($options['flags'] ?? 0) & (\FILTER_REQUIRE_ARRAY | \FILTER_FORCE_ARRAY))) {
99-
trigger_deprecation('symfony/http-foundation', '5.1', 'Filtering an array value with "%s()" without passing the FILTER_REQUIRE_ARRAY or FILTER_FORCE_ARRAY flag is deprecated', __METHOD__);
100-
101-
if (!isset($options['flags'])) {
102-
$options['flags'] = \FILTER_REQUIRE_ARRAY;
103-
}
99+
throw new BadRequestException(sprintf('Input value "%s" contains an array, but "FILTER_REQUIRE_ARRAY" or "FILTER_FORCE_ARRAY" flags were not set.', $key));
104100
}
105101

106102
if ((\FILTER_CALLBACK & $filter) && !(($options['options'] ?? null) instanceof \Closure)) {
107-
trigger_deprecation('symfony/http-foundation', '5.2', 'Not passing a Closure together with FILTER_CALLBACK to "%s()" is deprecated. Wrap your filter in a closure instead.', __METHOD__);
108-
// throw new \InvalidArgumentException(sprintf('A Closure must be passed to "%s()" when FILTER_CALLBACK is used, "%s" given.', __METHOD__, get_debug_type($options['options'] ?? null)));
103+
throw new \InvalidArgumentException(sprintf('A Closure must be passed to "%s()" when FILTER_CALLBACK is used, "%s" given.', __METHOD__, get_debug_type($options['options'] ?? null)));
109104
}
110105

111106
return filter_var($value, $filter, $options);

src/Symfony/Component/HttpFoundation/JsonResponse.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,6 @@ public function __construct($data = null, int $status = 200, array $headers = []
5454
$json ? $this->setJson($data) : $this->setData($data);
5555
}
5656

57-
/**
58-
* Factory method for chainability.
59-
*
60-
* Example:
61-
*
62-
* return JsonResponse::create(['key' => 'value'])
63-
* ->setSharedMaxAge(300);
64-
*
65-
* @param mixed $data The JSON response data
66-
* @param int $status The response status code
67-
* @param array $headers An array of response headers
68-
*
69-
* @return static
70-
*
71-
* @deprecated since Symfony 5.1, use __construct() instead.
72-
*/
73-
public static function create($data = null, int $status = 200, array $headers = [])
74-
{
75-
trigger_deprecation('symfony/http-foundation', '5.1', 'The "%s()" method is deprecated, use "new %s()" instead.', __METHOD__, static::class);
76-
77-
return new static($data, $status, $headers);
78-
}
79-
8057
/**
8158
* Factory method for chainability.
8259
*

src/Symfony/Component/HttpFoundation/ParameterBag.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ public function filter(string $key, $default = null, int $filter = \FILTER_DEFAU
195195
}
196196

197197
if ((\FILTER_CALLBACK & $filter) && !(($options['options'] ?? null) instanceof \Closure)) {
198-
trigger_deprecation('symfony/http-foundation', '5.2', 'Not passing a Closure together with FILTER_CALLBACK to "%s()" is deprecated. Wrap your filter in a closure instead.', __METHOD__);
199-
// throw new \InvalidArgumentException(sprintf('A Closure must be passed to "%s()" when FILTER_CALLBACK is used, "%s" given.', __METHOD__, get_debug_type($options['options'] ?? null)));
198+
throw new \InvalidArgumentException(sprintf('A Closure must be passed to "%s()" when FILTER_CALLBACK is used, "%s" given.', __METHOD__, get_debug_type($options['options'] ?? null)));
200199
}
201200

202201
return filter_var($value, $filter, $options);

src/Symfony/Component/HttpFoundation/RedirectResponse.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,6 @@ public function __construct(string $url, int $status = 302, array $headers = [])
4747
}
4848
}
4949

50-
/**
51-
* Factory method for chainability.
52-
*
53-
* @param string $url The URL to redirect to
54-
*
55-
* @return static
56-
*
57-
* @deprecated since Symfony 5.1, use __construct() instead.
58-
*/
59-
public static function create($url = '', int $status = 302, array $headers = [])
60-
{
61-
trigger_deprecation('symfony/http-foundation', '5.1', 'The "%s()" method is deprecated, use "new %s()" instead.', __METHOD__, static::class);
62-
63-
return new static($url, $status, $headers);
64-
}
65-
6650
/**
6751
* Returns the target URL.
6852
*

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class Request
4848
public const HEADER_X_FORWARDED_PORT = 0b010000;
4949
public const HEADER_X_FORWARDED_PREFIX = 0b100000;
5050

51-
/** @deprecated since Symfony 5.2, use either "HEADER_X_FORWARDED_FOR | HEADER_X_FORWARDED_HOST | HEADER_X_FORWARDED_PORT | HEADER_X_FORWARDED_PROTO" or "HEADER_X_FORWARDED_AWS_ELB" or "HEADER_X_FORWARDED_TRAEFIK" constants instead. */
52-
public const HEADER_X_FORWARDED_ALL = 0b1011110; // All "X-Forwarded-*" headers sent by "usual" reverse proxy
5351
public const HEADER_X_FORWARDED_AWS_ELB = 0b0011010; // AWS ELB doesn't send X-Forwarded-Host
5452
public const HEADER_X_FORWARDED_TRAEFIK = 0b0111110; // All "X-Forwarded-*" headers sent by Traefik reverse proxy
5553

@@ -584,9 +582,6 @@ public function overrideGlobals()
584582
*/
585583
public static function setTrustedProxies(array $proxies, int $trustedHeaderSet)
586584
{
587-
if (self::HEADER_X_FORWARDED_ALL === $trustedHeaderSet) {
588-
trigger_deprecation('symfony/http-foundation', '5.2', 'The "HEADER_X_FORWARDED_ALL" constant is deprecated, use either "HEADER_X_FORWARDED_FOR | HEADER_X_FORWARDED_HOST | HEADER_X_FORWARDED_PORT | HEADER_X_FORWARDED_PROTO" or "HEADER_X_FORWARDED_AWS_ELB" or "HEADER_X_FORWARDED_TRAEFIK" constants instead.');
589-
}
590585
self::$trustedProxies = array_reduce($proxies, function ($proxies, $proxy) {
591586
if ('REMOTE_ADDR' !== $proxy) {
592587
$proxies[] = $proxy;

src/Symfony/Component/HttpFoundation/RequestStack.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,6 @@ public function getMainRequest(): ?Request
8080
return $this->requests[0];
8181
}
8282

83-
/**
84-
* Gets the master request.
85-
*
86-
* @return Request|null
87-
*
88-
* @deprecated since symfony/http-foundation 5.3, use getMainRequest() instead
89-
*/
90-
public function getMasterRequest()
91-
{
92-
trigger_deprecation('symfony/http-foundation', '5.3', '"%s()" is deprecated, use "getMainRequest()" instead.', __METHOD__);
93-
94-
return $this->getMainRequest();
95-
}
96-
9783
/**
9884
* Returns the parent request of the current.
9985
*

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,6 @@ public function __construct(?string $content = '', int $ E46E status = 200, array $hea
220220
$this->setProtocolVersion('1.0');
221221
}
222222

223-
/**
224-
* Factory method for chainability.
225-
*
226-
* Example:
227-
*
228-
* return Response::create($body, 200)
229-
* ->setSharedMaxAge(300);
230-
*
231-
* @return static
232-
*
233-
* @deprecated since Symfony 5.1, use __construct() instead.
234-
*/
235-
public static function create(?string $content = '', int $status = 200, array $headers = [])
236-
{
237-
trigger_deprecation('symfony/http-foundation', '5.1', 'The "%s()" method is deprecated, use "new %s()" instead.', __METHOD__, static::class);
238-
239-
return new static($content, $status, $headers);
240-
}
241-
242223
/**
243224
* Returns the Response as an HTTP string.
244225
*

0 commit comments

Comments
 (0)
0