8000 feature #31658 [HTTP Foundation] Deprecate passing argument to method… · symfony/symfony@5c8fb7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c8fb7b

Browse files
committed
feature #31658 [HTTP Foundation] Deprecate passing argument to method Request::isMethodSafe() (dFayet)
This PR was squashed before being merged into the 4.4 branch (closes #31658). Discussion ---------- [HTTP Foundation] Deprecate passing argument to method Request::isMethodSafe() | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #31323 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | <!-- required for new features --> Passing argument to `Request::isMethodSafe()` should have been deprecated in 4.1. As mentionned there: https://github.com/symfony/http-foundation/blob/master/Request.php#L1435-L1452 We also remove Exceptions throwed when you call `Request::isMethodSafe()` or `Request::isMethodSafe(true)` Commits ------- 59fa1bd [HTTP Foundation] Deprecate passing argument to method Request::isMethodSafe()
2 parents 926ded8 + 59fa1bd commit 5c8fb7b

File tree

8 files changed

+14
-22
lines changed

8 files changed

+ 8000 14
-22
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function prepare(Request $request)
204204

205205
if (!$this->headers->has('Accept-Ranges')) {
206206
// Only accept ranges on safe HTTP methods
207-
$this->headers->set('Accept-Ranges', $request->isMethodSafe(false) ? 'bytes' : 'none');
207+
$this->headers->set('Accept-Ranges', $request->isMethodSafe() ? 'bytes' : 'none');
208208
}
209209

210210
if (self::$trustXSendfileTypeHeader && $request->headers->has('X-Sendfile-Type')) {

src/Symfony/Component/HttpFoundation/CHANGELOG.md

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

4+
4.4.0
5+
-----
6+
7+
* passing arguments to `Request::isMethodSafe()` is deprecated.
8+
49
4.3.0
510
-----
611

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,15 +1437,12 @@ public function isMethod($method)
14371437
*
14381438
* @see https://tools.ietf.org/html/rfc7231#section-4.2.1
14391439
*
1440-
* @param bool $andCacheable Adds the additional condition that the method should be cacheable. True by default.
1441-
*
14421440
* @return bool
14431441
*/
1444-
public function isMethodSafe(/* $andCacheable = true */)
1442+
public function isMethodSafe()
14451443
{
1446-
if (!\func_num_args() || func_get_arg(0)) {
1447-
// setting $andCacheable to false should be deprecated in 4.1
1448-
throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.');
1444+
if (\func_num_args() > 0) {
1445+
@trigger_error(sprintf('Passing arguments to "%s()" has been deprecated since Symfony 4.4; use "%s::isMethodCacheable() to check if the method is cacheable instead."', __METHOD__, __CLASS__), E_USER_DEPRECATED);
14491446
}
14501447

14511448
return \in_array($this->getMethod(), ['GET', 'HEAD', 'OPTIONS', 'TRACE']);

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ public function testMethodSafe($method, $safe)
21152115
{
21162116
$request = new Request();
21172117
$request->setMethod($method);
2118-
$this->assertEquals($safe, $request->isMethodSafe(false));
2118+
$this->assertEquals($safe, $request->isMethodSafe());
21192119
}
21202120

21212121
public function methodSafeProvider()
@@ -2134,16 +2134,6 @@ public function methodSafeProvider()
21342134
];
21352135
}
21362136

2137-
/**
2138-
* @expectedException \BadMethodCallException
2139-
*/
2140-
public function testMethodSafeChecksCacheable()
2141-
{
2142-
$request = new Request();
2143-
$request->setMethod('OPTIONS');
2144-
$request->isMethodSafe();
2145-
}
2146-
21472137
/**
21482138
* @dataProvider methodCacheableProvider
21492139
*/

src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function onKernelRequest(GetResponseEvent $event)
7979
protected function validateRequest(Request $request)
8080
{
8181
// is the Request safe?
82-
if (!$request->isMethodSafe(false)) {
82+
if (!$request->isMethodSafe()) {
8383
throw new AccessDeniedHttpException();
8484
}
8585

src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
207207

208208
$this->traces[$this->getTraceKey($request)] = [];
209209

210-
if (!$request->isMethodSafe(false)) {
210+
if (!$request->isMethodSafe()) {
211211
$response = $this->invalidate($request, $catch);
212212
} elseif ($request->headers->has('expect') || !$request->isMethodCacheable()) {
213213
$response = $this->pass($request, $catch);

src/Symfony/Component/HttpKernel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": "^7.1.3",
2020
"symfony/event-dispatcher": "^4.3",
21-
"symfony/http-foundation": "^4.1.1|^5.0",
21+
"symfony/http-foundation": "^4.4|^5.0",
2222
"symfony/debug": "^3.4|^4.0|^5.0",
2323
"symfony/polyfill-ctype": "^1.8",
2424
"symfony/polyfill-php73": "^1.9",

src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private function startAuthentication(Request $request, AuthenticationException $
208208
protected function setTargetPath(Request $request)
209209
{
210210
// session isn't required when using HTTP basic authentication mechanism for example
211-
if ($request->hasSession() && $request->isMethodSafe(false) && !$request->isXmlHttpRequest()) {
211+
if ($request->hasSession() && $request->isMethodSafe() && !$request->isXmlHttpRequest()) {
212212
$this->saveTargetPath($request->getSession(), $this->providerKey, $request->getUri());
213213
}
214214
}

0 commit comments

Comments
 (0)
0