[HttpFoundation] Allow to not pass a parameter to Request::isMethodSafe()

This commit is contained in:
Kévin Dunglas 2019-10-29 14:42:59 +01:00 committed by Nicolas Grekas
parent ee4b99f227
commit e819256ea0
2 changed files with 3 additions and 6 deletions

View File

@ -1447,14 +1447,11 @@ class Request
* *
* @see https://tools.ietf.org/html/rfc7231#section-4.2.1 * @see https://tools.ietf.org/html/rfc7231#section-4.2.1
* *
* @param bool $andCacheable Adds the additional condition that the method should be cacheable. True by default.
*
* @return bool * @return bool
*/ */
public function isMethodSafe(/* $andCacheable = true */) public function isMethodSafe()
{ {
if (!\func_num_args() || func_get_arg(0)) { if (\func_num_args() > 0 && func_get_arg(0)) {
// setting $andCacheable to false should be deprecated in 4.1
throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.'); throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.');
} }

View File

@ -2132,7 +2132,7 @@ class RequestTest extends TestCase
$this->expectException('BadMethodCallException'); $this->expectException('BadMethodCallException');
$request = new Request(); $request = new Request();
$request->setMethod('OPTIONS'); $request->setMethod('OPTIONS');
$request->isMethodSafe(); $request->isMethodSafe(true);
} }
/** /**