[HttpFoundation] Add Request::isMethodIdempotent method
This commit is contained in:
parent
473263a00b
commit
44df6a4677
@ -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.
|
||||
*
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user