Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 85033ff

Browse filesBrowse files
committed
bug #20603 [HttpKernel] Deprecate checking for cacheable HTTP methods in Request::isMethodSafe() (nicolas-grekas)
This PR was merged into the 3.2 branch. Discussion ---------- [HttpKernel] Deprecate checking for cacheable HTTP methods in Request::isMethodSafe() | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | no | Fixed tickets | - | License | MIT | Doc PR | - Late deprecation for 3.2, see #20602. Commits ------- 34e7b95 [HttpKernel] Deprecate checking for cacheable HTTP methods in Request::isMethodSafe()
2 parents 02b1e75 + 34e7b95 commit 85033ff
Copy full SHA for 85033ff

File tree

2 files changed

+20
-1
lines changed
Filter options

2 files changed

+20
-1
lines changed

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,15 @@ public function isMethod($method)
14811481
*/
14821482
public function isMethodSafe(/* $andCacheable = true */)
14831483
{
1484-
return in_array($this->getMethod(), 0 < func_num_args() && !func_get_arg(0) ? array('GET', 'HEAD', 'OPTIONS', 'TRACE') : array('GET', 'HEAD'));
1484+
if (!func_num_args() || func_get_arg(0)) {
1485+
// This deprecation should be turned into a BadMethodCallException in 4.0 (without adding the argument in the signature)
1486+
// then setting $andCacheable to false should be deprecated in 4.1
1487+
@trigger_error('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is deprecated since version 3.2 and will throw an exception in 4.0. Disable checking only for cacheable methods by calling the method with `false` as first argument or use the Request::isMethodCacheable() instead.', E_USER_DEPRECATED);
1488+
1489+
return in_array($this->getMethod(), array('GET', 'HEAD'));
1490+
}
1491+
1492+
return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
14851493
}
14861494

14871495
/**

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,17 @@ public function testMethodSafeChecksCacheable()
20202020
$this->assertFalse($request->isMethodSafe());
20212021
}
20222022

2023+
/**
2024+
* @group legacy
2025+
* @expectedDeprecation Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is deprecated since version 3.2 and will throw an exception in 4.0. Disable checking only for cacheable methods by calling the method with `false` as first argument or use the Request::isMethodCacheable() instead.
2026+
*/
2027+
public function testMethodSafeChecksCacheable()
2028+
{
2029+
$request = new Request();
2030+
$request->setMethod('OPTION');
2031+
$this->assertFalse($request->isMethodSafe());
2032+
}
2033+
20232034
/**
20242035
* @dataProvider methodCacheableProvider
20252036
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.