Removing comments from Set::merge()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4796 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-04-05 21:29:00 +00:00
parent 69da631d61
commit 924a235ec3

View file

@ -73,53 +73,35 @@ class Set extends Object {
* @access public * @access public
*/ */
function merge($arr1, $arr2 = null) { function merge($arr1, $arr2 = null) {
// Get all arguments that were passed to the function
$args = func_get_args(); $args = func_get_args();
// If $this is a Set class if(is_a($this, 'set')) {
if (is_a($this, 'set')) {
// Get the call stack
$backtrace = debug_backtrace(); $backtrace = debug_backtrace();
// And the previous call
$previousCall = low($backtrace[1]['class'].'::'.$backtrace[1]['function']); $previousCall = low($backtrace[1]['class'].'::'.$backtrace[1]['function']);
// If this is not a recursive call
if ($previousCall != 'set::merge') { if ($previousCall != 'set::merge') {
// Reference this Set's value as our resulting $r array
$r =& $this->value; $r =& $this->value;
// And push an empty args at the beginning of the $args array which will be discarded later on
array_unshift($args, null); array_unshift($args, null);
} }
} }
if(!isset($r)) {
// If $r has not been set yet
if (!isset($r)) {
// Tpecast the first argument into an array and use it as our resulting $r array
$r = (array)current($args); $r = (array)current($args);
} }
// Loop through all $args we were given
while(($arg = next($args)) !== false) { while(($arg = next($args)) !== false) {
// If a Set object was passed in
if (is_a($arg, 'set')) { if (is_a($arg, 'set')) {
// Use it's value for the merging
$arg = $arg->get(); $arg = $arg->get();
} }
// Loop through all $key / $val pairs of our current $arg
foreach ((array)$arg as $key => $val) { foreach((array)$arg as $key => $val) {
// If the current $key holds an array and the current $arg and all previous ones ($r) if(is_array($val) && isset($r[$key]) && is_array($r[$key])) {
if (is_array($val) && isset($r[$key]) && is_array($r[$key])) {
// Go for recursive merging
$r[$key] = Set::merge($r[$key], $val); $r[$key] = Set::merge($r[$key], $val);
} elseif (is_int($key)) { } elseif(is_int($key)) {
// If it's a numerical index go for auto-incremeting
$r[] = $val; $r[] = $val;
} else { } else {
// And in case of an associative one do an overwrite
$r[$key] = $val; $r[$key] = $val;
} }
} }
} }
// Return the merged array
return $r; return $r;
} }
/** /**