Merge branch '2.0' into 2.1

This commit is contained in:
mark_story 2012-02-18 22:19:38 -05:00
commit 943d928084
3 changed files with 32 additions and 3 deletions

View file

@ -146,7 +146,14 @@ class CakeRequest implements ArrayAccess {
/**
* process the post data and set what is there into the object.
* processed data is available at $this->data
* processed data is available at `$this->data`
*
* Will merge POST vars prefixed with `data`, and ones without
* into a single array. Variables prefixed with `data` will overwrite those without.
*
* If you have mixed POST values be careful not to make any top level keys numeric
* containing arrays. Set::merge() is used to merge data, and it has possibly
* unexpected behavior in this situation.
*
* @return void
*/
@ -166,8 +173,14 @@ class CakeRequest implements ArrayAccess {
}
unset($this->data['_method']);
}
$data = $this->data;
if (isset($this->data['data'])) {
$data = $this->data['data'];
}
if (count($this->data) <= 1) {
$this->data = $data;
}
if (count($this->data) > 1) {
unset($this->data['data']);
$this->data = Set::merge($this->data, $data);
}

View file

@ -177,6 +177,19 @@ class CakeRequestTest extends CakeTestCase {
$_POST = array('one' => 1, 'two' => 'three');
$request = new CakeRequest('some/path');
$this->assertEquals($_POST, $request->data);
$_POST = array(
'data' => array(
'Article' => array('title' => 'Testing'),
),
'action' => 'update'
);
$request = new CakeRequest('some/path');
$expected = array(
'Article' => array('title' => 'Testing'),
'action' => 'update'
);
$this->assertEquals($expected, $request->data);
}
/**

View file

@ -30,9 +30,12 @@ class Set {
* This function can be thought of as a hybrid between PHP's array_merge and array_merge_recursive. The difference
* to the two is that if an array key contains another array then the function behaves recursive (unlike array_merge)
* but does not do if for keys containing strings (unlike array_merge_recursive).
* See the unit test for more information.
*
* Note: This function will work with an unlimited amount of arguments and typecasts non-array parameters into arrays.
* Since this method emulates `array_merge`, it will re-order numeric keys. When combined with out of
* order numeric keys containing arrays, results can be lossy.
*
* Note: This function will work with an unlimited amount of arguments and typecasts non-array
* parameters into arrays.
*
* @param array $arr1 Array to be merged
* @param array $arr2 Array to merge with