protected function exportExtractedData(array $info) { foreach ($info['globals'] as $key => $val) { // If a merge strategy is set, read it and remove it from the value // so it doesn't accidentally end up getting set. // Need to check $val is an array for PHP 5.3 which will return // true on isset( 'string'['foo'] ). if (isset($val[self::MERGE_STRATEGY]) && is_array($val)) { $mergeStrategy = $val[self::MERGE_STRATEGY]; unset($val[self::MERGE_STRATEGY]); } else { $mergeStrategy = 'array_merge'; } // Optimistic: If the global is not set, or is an empty array, replace it entirely. // Will be O(1) performance. if (!isset($GLOBALS[$key]) || is_array($GLOBALS[$key]) && !$GLOBALS[$key]) { $GLOBALS[$key] = $val; continue; } if (!is_array($GLOBALS[$key]) || !is_array($val)) { // config setting that has already been overridden, don't set it continue; } switch ($mergeStrategy) { case 'array_merge_recursive': $GLOBALS[$key] = array_merge_recursive($GLOBALS[$key], $val); break; case 'array_plus_2d': $GLOBALS[$key] = wfArrayPlus2d($GLOBALS[$key], $val); break; case 'array_plus': $GLOBALS[$key] += $val; break; case 'array_merge': $GLOBALS[$key] = array_merge($val, $GLOBALS[$key]); break; default: throw new UnexpectedValueException("Unknown merge strategy '{$mergeStrategy}'"); } } foreach ($info['defines'] as $name => $val) { define($name, $val); } foreach ($info['callbacks'] as $cb) { call_user_func($cb); } $this->loaded += $info['credits']; if ($info['attributes']) { if (!$this->attributes) { $this->attributes = $info['attributes']; } else { $this->attributes = array_merge_recursive($this->attributes, $info['attributes']); } } }
/** * @dataProvider provideArrays */ public function testWfArrayPlus2d($baseArray, $newValues, $expected, $testName) { $this->assertEquals($expected, wfArrayPlus2d($baseArray, $newValues), $testName); }