From 3af9c55c8151d96dae79facb7272f40f0907bfe3 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sat, 10 Apr 2010 19:42:24 -0600 Subject: [PATCH] Consolidate code run when switching applications --- framework/Core/lib/Horde/Registry.php | 47 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 10c7f9412..b1a997353 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -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. * -- 2.11.0