10000 merged branch drak/ismethod (PR #3800) · marcw/symfony@c392f74 · GitHub
[go: up one dir, main page]

Skip to content

Commit c392f74

Browse files
committed
merged branch drak/ismethod (PR symfony#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
2 parents 0ccb6fa + 33881dd commit c392f74

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG-2.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
325325
to the client.
326326
* Request::getClientIp() method doesn't take a parameter anymore but bases
327327
itself on the trustProxy parameter.
328+
* Added isMethod() to Request object.
328329

329330
### HttpKernel
330331

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 12 additions & 0 deletions
< 10000 div data-testid="addition diffstat" class="DiffSquares-module__diffSquare--h5kjy DiffSquares-module__addition--jeNtt">
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,18 @@ public function getLocale()
10161016
return null === $this->locale ? $this->defaultLocale : $this->locale;
10171017
}
10181018

1019+
/**
1020+
* Checks if the request method is of specified type.
1021+
*
1022+
* @param string $method Uppercase request method (GET, POST etc).
1023+
*
1024+
* @return Boolean
1025+
*/
1026+
public function isMethod($method)
1027+
{
1028+
return $this->getMethod() === strtoupper($method);
1029+
}
1030+
10191031
/**
10201032
* Checks whether the method is safe or not.
10211033
*

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,22 @@ public function testIsProxyTrusted()
925925
$this->assertFalse(Request::isProxyTrusted());
926926
}
927927

928+
public function testIsMethod()
929+
{
930+
$request = new Request();
931+
$request->setMethod('POST');
932+
$this->assertTrue($request->isMethod('POST'));
933+
$this->assertTrue($request->isMethod('post'));
934+
$this->assertFalse($request->isMethod('GET'));
935+
$this->assertFalse($request->isMethod('get'));
936+
937+
$request->setMethod('GET');
938+
$this->assertTrue($request->isMethod('GET'));
939+
$this->assertTrue($request->isMethod('get'));
940+
$this->assertFalse($request->isMethod('POST'));
941+
$this->assertFalse($request->isMethod('post'));
942+
}
943+
928944
private function startTrustingProxyData()
929945
{
930946
Request::trustProxyData();

0 commit comments

Comments
 (0)
0