Consolidate code run when switching applications
authorMichael M Slusarz <slusarz@curecanti.org>
Sun, 11 Apr 2010 01:42:24 +0000 (19:42 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sun, 11 Apr 2010 01:42:24 +0000 (19:42 -0600)
framework/Core/lib/Horde/Registry.php

index 10c7f94..b1a9973 100644 (file)
@@ -1090,22 +1090,8 @@ class Horde_Registry
          * with the current language, and reset the language later. */
         Horde_Nls::setLanguageEnvironment($GLOBALS['language'], $app);
 
-        /* Import this application's configuration values. */
-        $this->importConfig($app);
-
-        /* Load preferences after the configuration has been loaded to make
-         * sure the prefs file has all the information it needs. */
-        $this->loadPrefs($app);
-
-        /* Reset the language in case there is a different one selected in the
-         * preferences. */
-        $language = '';
-        if (isset($GLOBALS['prefs'])) {
-            $language = $GLOBALS['prefs']->getValue('language');
-            if ($language != $GLOBALS['language']) {
-                Horde_Nls::setLanguageEnvironment($language, $app);
-            }
-        }
+        /* Load config and prefs and set proper language from the prefs. */
+        $this->_onAppSwitch($app);
 
         /* Call post-push hook. */
         try {
@@ -1158,16 +1144,37 @@ class Horde_Registry
          * and set the gettext domain and the preferred language. */
         $app = $this->getApp();
         if ($app) {
-            $this->importConfig($app);
-            $this->loadPrefs($app);
-            $language = $GLOBALS['prefs']->getValue('language');
-            Horde_Nls::setLanguageEnvironment($language, $app);
+            $this->_onAppSwitch($app);
         }
 
         return $previous;
     }
 
     /**
+     * Code to run when switching to an application.
+     *
+     * @param string $app  The application name.
+     *
+     * @throws Horde_Exception
+     */
+    protected function _onAppSwitch($app)
+    {
+        /* Import this application's configuration values. */
+        $this->importConfig($app);
+
+        /* Load preferences after the configuration has been loaded to make
+         * sure the prefs file has all the information it needs. */
+        $this->loadPrefs($app);
+
+        /* Reset the language in case there is a different one selected in the
+         * preferences. */
+        $language = $GLOBALS['prefs']->getValue('language');
+        if ($language != $GLOBALS['language']) {
+            Horde_Nls::setLanguageEnvironment($language, $app);
+        }
+    }
+
+    /**
      * Return the current application - the app at the top of the application
      * stack.
      *