Add isMethod() to Request object

This commit is contained in:
Drak 2012-04-06 06:48:49 +00:00
parent 0ccb6fa48d
commit 3dc72cdf21
2 changed files with 27 additions and 0 deletions

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 $type Uppercase request type (GET, POST etc).
*
* @return Boolean
*/
public function isMethod($type)
{
return ($this->getMethod() === strtoupper($type));
}
/**
* Checks whether the method is safe or not.
*

View File

@ -925,6 +925,21 @@ 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->assertFalse($request->isMethod('GET'));
$request->setMethod('GET');
$this->assertTrue($request->isMethod('GET'));
$this->assertFalse($request->isMethod('POST'));
$this->assertSame(true, $request->isMethod('GET'));
$this->assertSame(false, $request->isMethod('POST'));
}
private function startTrustingProxyData()
{
Request::trustProxyData();