public function createBackup($new) {
$frame = array();
foreach ($new as $globalKey => $values) {
- foreach ($values as $key => $value) {
- $frame[$globalKey][$key] = CRM_Utils_Array::value($key, $GLOBALS[$globalKey]);
+ if (is_array($values)) {
+ foreach ($values as $key => $value) {
+ $frame[$globalKey][$key] = CRM_Utils_Array::value($key, $GLOBALS[$globalKey]);
+ }
+ } else {
+ $frame[$globalKey] = CRM_Utils_Array::value($globalKey, $GLOBALS);
}
}
return $frame;
public function applyFrame($newFrame) {
foreach ($newFrame as $globalKey => $values) {
- foreach ($values as $key => $value) {
- $GLOBALS[$globalKey][$key] = $value;
+ if (is_array($values)) {
+ foreach ($values as $key => $value) {
+ $GLOBALS[$globalKey][$key] = $value;
+ }
+ } else {
+ $GLOBALS[$globalKey] = $values;
}
}
}
class CRM_Utils_GlobalStackTest extends CiviUnitTestCase {
public function testPushPop() {
- global $FOO;
+ global $FOO, $EXTRA;
$FOO['bar'] = 1;
$FOO['whiz'] = 1;
+ $EXTRA = 1;
$this->assertEquals(1, $FOO['bar']);
$this->assertEquals(1, $FOO['whiz']);
$this->assertFalse(isset($FOO['bang']));
+ $this->assertEquals(1, $EXTRA);
CRM_Utils_GlobalStack::singleton()->push(array(
'FOO' => array(
'bar' => 2,
'bang' => 2,
),
+ 'EXTRA' => 2,
));
$this->assertEquals(2, $FOO['bar']);
$this->assertEquals(1, $FOO['whiz']);
$this->assertEquals(2, $FOO['bang']);
+ $this->assertEquals(2, $EXTRA);
CRM_Utils_GlobalStack::singleton()->pop();
$this->assertEquals(1, $FOO['bar']);
$this->assertEquals(1, $FOO['whiz']);
$this->assertEquals(NULL, $FOO['bang']);
+ $this->assertEquals(1, $EXTRA);
}
}