Merge branch 'request-set-input' into 2.6

Fixes #3764
This commit is contained in:
mark_story 2014-06-29 22:57:35 -04:00
commit b06d297216
2 changed files with 28 additions and 1 deletions

View file

@ -915,6 +915,17 @@ class CakeRequest implements ArrayAccess {
return $input;
}
/**
* Modify data originally from `php://input`. Useful for altering json/xml data
* in middleware or DispatcherFilters before it gets to RequestHandlerComponent
*
* @param string $input A string to replace original parsed data from input()
* @return void
*/
public function setInput($input) {
$this->_input = $input;
}
/**
* Allow only certain HTTP request methods. If the request method does not match
* a 405 error will be shown and the required "Allow" response header will be set.

View file

@ -2081,7 +2081,7 @@ class CakeRequestTest extends CakeTestCase {
/**
* Data provider for testing reading values with CakeRequest::param()
*
*
* @return array
*/
public function paramReadingDataProvider() {
@ -2218,6 +2218,22 @@ class CakeRequestTest extends CakeTestCase {
$this->assertEquals('/posts/base_path/1/name:value?test=value', $result);
}
/**
* Test the input() method.
*
* @return void
*/
public function testSetInput() {
$request = new CakeRequest('/');
$request->setInput('I came from setInput');
$result = $request->input();
$this->assertEquals('I came from setInput', $result);
$result = $request->input();
$this->assertEquals('I came from setInput', $result);
}
/**
* Test the input() method.
*