Skip to content

Commit

Permalink
Remove Object::_mergeVars.
Browse files Browse the repository at this point in the history
Update Model mergeVars usage as well.
  • Loading branch information
markstory committed Oct 14, 2012
1 parent fb37e21 commit 6cc0046
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 41 deletions.
30 changes: 0 additions & 30 deletions lib/Cake/Core/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,34 +174,4 @@ protected function _set($properties = array()) {
}
}

/**
* Merges this objects $property with the property in $class' definition.
* This classes value for the property will be merged on top of $class'
*
* This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine
* this method as an empty function.
*
* @param array $properties The name of the properties to merge.
* @param string $class The class to merge the property with.
* @param boolean $normalize Set to true to run the properties through Hash::normalize() before merging.
* @return void
*/
protected function _mergeVars($properties, $class, $normalize = true) {
$classProperties = get_class_vars($class);
foreach ($properties as $var) {
if (
isset($classProperties[$var]) &&
!empty($classProperties[$var]) &&
is_array($this->{$var}) &&
$this->{$var} != $classProperties[$var]
) {
if ($normalize) {
$classProperties[$var] = Hash::normalize($classProperties[$var]);
$this->{$var} = Hash::normalize($this->{$var});
}
$this->{$var} = Hash::merge($classProperties[$var], $this->{$var});
}
}
}

}
19 changes: 8 additions & 11 deletions lib/Cake/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* @since CakePHP(tm) v 0.10.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

namespace Cake\Model;

use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Object;
Expand All @@ -30,6 +30,7 @@
use Cake\Utility\ClassRegistry;
use Cake\Utility\Hash;
use Cake\Utility\Inflector;
use Cake\Utility\MergeVariablesTrait;
use Cake\Utility\Set;
use Cake\Utility\Xml;

Expand All @@ -46,6 +47,8 @@
*/
class Model extends Object implements EventListener {

use MergeVariablesTrait;

/**
* The name of the DataSource connection that this Model uses
*
Expand Down Expand Up @@ -714,16 +717,10 @@ public function __construct($id = false, $table = null, $ds = null) {
$this->useDbConfig = $ds;
}

$appModelClass = App::classname('Model', 'Model');
if (is_subclass_of($this, $appModelClass)) {
$merge = array('actsAs', 'findMethods');
$parentClass = get_parent_class($this);
if ($parentClass !== $appModelClass) {
$this->_mergeVars($merge, $parentClass);
}
$this->_mergeVars($merge, $appModelClass);
}
$this->_mergeVars(array('findMethods'), 'Model');
$this->_mergeVars(
['actsAs', 'findMethods'],
['associative' => ['actsAs', 'findMethods']]
);

$this->Behaviors = new BehaviorCollection();

Expand Down

0 comments on commit 6cc0046

Please sign in to comment.