8000 Deprecate passing argument to method Request::isMethodSafe() · symfony/symfony@d3e0689 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3e0689

Browse files
author
dFayet
committed
Deprecate passing argument to method Request::isMethodSafe()
1 parent 2d72ec1 commit d3e0689

File tree

7 files changed

+9
-21
lines changed

7 files changed

+9
-21
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
will respectively change from "false" to "null" and from "null" to "lax" in Symfony
99
5.0, you should define their values explicitly or use "Cookie::create()" instead.
1010
* added `matchPort()` in RequestMatcher
11+
* passing arguments to `Request::isMethodSafe()` is deprecated.
1112

1213
4.1.3
1314
-----

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('Passing arguments to Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported. To check if method is cacheable, use Symfony\Component\HttpFoundation\Request::isMethodCacheable() instead.', 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
@@ -77,7 +77,7 @@ public function onKernelRequest(GetResponseEvent $event)
7777
protected function validateRequest(Request $request)
7878
{
7979
// is the Request safe?
80-
if (!$request->isMethodSafe(false)) {
80+
if (!$request->isMethodSafe()) {
8181
throw new AccessDeniedHttpException();
8282
}
8383

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

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

178178
$this->traces[$this->getTraceKey($request)] = [];
179179

180-
if (!$request->isMethodSafe(false)) {
180+
if (!$request->isMethodSafe()) {
181181
$response = $this->invalidate($request, $catch);
182182
} elseif ($request->headers->has('expect') || !$request->isMethodCacheable()) {
183183
$response = $this->pass($request, $catch);

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

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

0 commit comments

Comments
 (0)