Skip to content

Commit

Permalink
Remove reverse merged properties.
Browse files Browse the repository at this point in the history
CakePHP no longer needs this feature so it makes sense to remove it.
  • Loading branch information
markstory committed Dec 7, 2013
1 parent 14a6e01 commit d633532
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
11 changes: 0 additions & 11 deletions Cake/Test/TestCase/Utility/MergeVariablesTraitTest.php
Expand Up @@ -121,15 +121,4 @@ public function testMergeVarsWithBoolean() {
$this->assertEquals(['test'], $object->hasBoolean);
}

/**
* Test that merging reversed works.
*
* @return void
*/
public function testMergeVariablesReversed() {
$object = new Grandchild();
$object->mergeVars(['listProperty'], ['reverse' => ['listProperty']]);
$expected = ['Four', 'Five', 'Two', 'Three', 'One'];
$this->assertSame($expected, $object->listProperty);
}
}
18 changes: 2 additions & 16 deletions Cake/Utility/MergeVariablesTrait.php
Expand Up @@ -29,10 +29,6 @@ trait MergeVariablesTrait {
*
* - `associative` - A list of properties that should be treated as associative arrays.
* Properties in this list will be passed through Hash::normalize() before merging.
* - `reverse` - A list of properties that should be merged in reverse. Reverse merging
* allows the parent properties to follow the child classes. Generally this option is only
* useful when merging list properties that need to maintain the child property values
* as the first elements in the merged list.
*
* @param array $properties An array of properties and the merge strategy for them.
* @param array $options The options to use when merging properties.
Expand Down Expand Up @@ -71,19 +67,13 @@ protected function _mergeVars($properties, $options = []) {
*/
protected function _mergeProperty($property, $parentClasses, $options) {
$thisValue = $this->{$property};
$isAssoc = $isReversed = false;
$isAssoc = false;
if (
isset($options['associative']) &&
in_array($property, (array)$options['associative'])
) {
$isAssoc = true;
}
if (
isset($options['reverse']) &&
in_array($property, (array)$options['reverse'])
) {
$isReversed = true;
}

if ($isAssoc) {
$thisValue = Hash::normalize($thisValue);
Expand All @@ -100,11 +90,7 @@ protected function _mergeProperty($property, $parentClasses, $options) {
if ($isAssoc) {
$parentProperty = Hash::normalize($parentProperty);
}
if ($isReversed) {
$thisValue = Hash::merge($thisValue, $parentProperty);
} else {
$thisValue = Hash::merge($parentProperty, $thisValue);
}
$thisValue = Hash::merge($parentProperty, $thisValue);
}
$this->{$property} = $thisValue;
}
Expand Down

0 comments on commit d633532

Please sign in to comment.