Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Add Request::isMethodIdempotent method #19322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[HttpFoundation] Add Request::isMethodIdempotent method
  • Loading branch information
dunglas committed Jul 9, 2016
commit 3ea9e18b33ec48ac87bba1223a7821b10aa3d992
18 changes: 18 additions & 0 deletions 18 src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,24 @@ public function isMethodSafe()
return in_array($this->getMethod(), array('GET', 'HEAD'));
}

/**
* Checks whether the method is idempotent or not.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go for "Checks whether or not the method is idempotent." or "Checks if the method is idempotent."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same text than in isMethodSafe

*
* @return bool
*/
public function isMethodIdempotent()
{
return in_array($this->getMethod(), array(
self::METHOD_HEAD,
self::METHOD_GET,
self::METHOD_PUT,
self::METHOD_DELETE,
self::METHOD_TRACE,
self::METHOD_OPTIONS,
self::METHOD_PURGE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the strings here directly as done for the isMethodSafe method.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, why use strings instead of constants here?

));
}

/**
* Returns the request body content.
*
Expand Down
26 changes: 26 additions & 0 deletions 26 src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,32 @@ public function getLongHostNames()
array(str_repeat(':', 101)),
);
}

/**
* @dataProvider methodProvider
*/
public function testMethodIdempotent($method, $idempotent)
{
$request = new Request();
$request->setMethod($method);
$this->assertEquals($idempotent, $request->isMethodIdempotent());
}

public function methodProvider()
{
return array(
array(Request::METHOD_HEAD, true),
array(Request::METHOD_GET, true),
array(Request::METHOD_POST, false),
array(Request::METHOD_PUT, true),
array(Request::METHOD_PATCH, false),
array(Request::METHOD_DELETE, true),
array(Request::METHOD_PURGE, true),
array(Request::METHOD_OPTIONS, true),
array(Request::METHOD_TRACE, true),
array(Request::METHOD_CONNECT, false),
);
}
}

class RequestContentProxy extends Request
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.