Add isMethod() to Request object
This commit is contained in:
parent
0ccb6fa48d
commit
3dc72cdf21
@ -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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user