[HttpFoundation] Add Request::isMethodIdempotent method

This commit is contained in:
Kévin Dunglas 2016-07-09 11:14:35 +02:00 committed by Fabien Potencier
parent 473263a00b
commit 44df6a4677
2 changed files with 37 additions and 1 deletions

View File

@ -1473,7 +1473,7 @@ class Request
}
/**
* Checks whether the method is safe or not.
* Checks whether or not the method is safe.
*
* @return bool
*/
@ -1482,6 +1482,16 @@ class Request
return in_array($this->getMethod(), array('GET', 'HEAD'));
}
/**
* Checks whether or not the method is idempotent.
*
* @return bool
*/
public function isMethodIdempotent()
{
return in_array($this->getMethod(), array('HEAD', 'GET', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', 'PURGE'));
}
/**
* Returns the request body content.
*

View File

@ -1951,6 +1951,32 @@ class RequestTest extends \PHPUnit_Framework_TestCase
array(str_repeat(':', 101)),
);
}
/**
* @dataProvider methodIdempotentProvider
*/
public function testMethodIdempotent($method, $idempotent)
{
$request = new Request();
$request->setMethod($method);
$this->assertEquals($idempotent, $request->isMethodIdempotent());
}
public function methodIdempotentProvider()
{
return array(
array('HEAD', true),
array('GET', true),
array('POST', false),
array('PUT', true),
array('PATCH', false),
array('DELETE', true),
array('PURGE', true),
array('OPTIONS', true),
array('TRACE', true),
array('CONNECT', false),
);
}
}
class RequestContentProxy extends Request