Merge pull request #3644 from eileenmcnaughton/e-notice-ps
[civicrm-core.git] / CRM / Utils / GlobalStack.php
index 6dedf152a0a3904ba40e16fd4d4d4f7f78957882..2e7c133a929631a5bb9a408133f5c87be9fa8987 100644 (file)
@@ -1,8 +1,8 @@
 <?php /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -64,6 +64,9 @@ class CRM_Utils_GlobalStack {
     return self::$_singleton;
   }
 
+  /**
+   * @param $newFrame
+   */
   public function push($newFrame) {
     $this->backups[] = $this->createBackup($newFrame);
     $this->applyFrame($newFrame);
@@ -80,18 +83,29 @@ class CRM_Utils_GlobalStack {
   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;
   }
 
+  /**
+   * @param $newFrame
+   */
   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;
       }
     }
   }
-}
\ No newline at end of file
+}