merged branch drak/ismethod (PR #3800)

Commits
-------

33881dd [HttpFoundation] Add more tests for casing
aec1339 [HttpFoundation] Coding standards.
bf33bd4 update changelog
3dc72cd Add isMethod() to Request object

Discussion
----------

[HttpFoundation] Add isMethod() to Request object.

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

Justification is for convenience.

---------------------------------------------------------------------------

by hhamon at 2012-04-06T07:14:44Z

+1
This commit is contained in:
Fabien Potencier 2012-04-06 14:11:35 +02:00
commit c392f747b8
3 changed files with 29 additions and 0 deletions

View File

@ -325,6 +325,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
to the client.
* Request::getClientIp() method doesn't take a parameter anymore but bases
itself on the trustProxy parameter.
* Added isMethod() to Request object.
### HttpKernel

View File

@ -1016,6 +1016,18 @@ class Request
return null === $this->locale ? $this->defaultLocale : $this->locale;
}
/**
* Checks if the request method is of specified type.
*
* @param string $method Uppercase request method (GET, POST etc).
*
* @return Boolean
*/
public function isMethod($method)
{
return $this->getMethod() === strtoupper($method);
}
/**
* Checks whether the method is safe or not.
*

View File

@ -925,6 +925,22 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertFalse(Request::isProxyTrusted());
}
public function testIsMethod()
{
$request = new Request();
$request->setMethod('POST');
$this->assertTrue($request->isMethod('POST'));
$this->assertTrue($request->isMethod('post'));
$this->assertFalse($request->isMethod('GET'));
$this->assertFalse($request->isMethod('get'));
$request->setMethod('GET');
$this->assertTrue($request->isMethod('GET'));
$this->assertTrue($request->isMethod('get'));
$this->assertFalse($request->isMethod('POST'));
$this->assertFalse($request->isMethod('post'));
}
private function startTrustingProxyData()
{
Request::trustProxyData();