From 8437c679756b7d03fba7c15f5155e42f55bd33b3 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 7 Jun 2010 22:52:56 -0600 Subject: [PATCH] Places where we don't need to use a global variable --- framework/Core/lib/Horde/Registry.php | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 279edb9ac..e27988541 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -174,15 +174,15 @@ class Horde_Registry } $classname = __CLASS__; - $GLOBALS['registry'] = new $classname($s_ctrl); + $registry = $GLOBALS['registry'] = new $classname($s_ctrl); - $appob = $GLOBALS['registry']->getApiInstance($app, 'application'); + $appob = $registry->getApiInstance($app, 'application'); $appob->initParams = $args; try { - $GLOBALS['registry']->pushApp($app, array('check_perms' => ($args['authentication'] != 'none'), 'logintasks' => !$args['nologintasks'])); + $registry->pushApp($app, array('check_perms' => ($args['authentication'] != 'none'), 'logintasks' => !$args['nologintasks'])); - if ($args['admin'] && !$GLOBALS['registry']->isAdmin()) { + if ($args['admin'] && !$registry->isAdmin()) { throw new Horde_Exception('Not an admin'); } } catch (Horde_Exception $e) { @@ -192,10 +192,10 @@ class Horde_Registry throw $e; } - $GLOBALS['registry']->authenticateFailure($app, $e); + $registry->authenticateFailure($app, $e); } - $GLOBALS['registry']->initialApp = $app; + $registry->initialApp = $app; if (!$args['nocompress']) { Horde::compressOutput(); @@ -205,7 +205,7 @@ class Horde_Registry if (empty($GLOBALS['conf']['auth']['admins'])) { throw new Horde_Exception('No admin users defined in configuration.'); } - Horde_Auth::setAuth(reset($GLOBALS['conf']['auth']['admins']), array()); + $registry->setAuth(reset($GLOBALS['conf']['auth']['admins']), array()); } $appob->init(); @@ -1088,7 +1088,7 @@ class Horde_Registry * - To all authenticated users if no permission is set on $app. * - To anyone who is allowed by an explicit ACL on $app. */ if ($checkPerms) { - if ($GLOBALS['registry']->getAuth() && !Horde_Auth::checkExistingAuth()) { + if ($this->getAuth() && !Horde_Auth::checkExistingAuth()) { throw new Horde_Exception('User is not authorized', self::AUTH_FAILURE); } if (!$this->hasPermission($app, Horde_Perms::READ)) { @@ -1096,8 +1096,8 @@ class Horde_Registry throw new Horde_Exception('User is not authorized', self::AUTH_FAILURE); } - Horde::logMessage(sprintf('%s does not have READ permission for %s', $GLOBALS['registry']->getAuth() ? 'User ' . $GLOBALS['registry']->getAuth() : 'Guest user', $app), 'DEBUG'); - throw new Horde_Exception(sprintf(_('%s is not authorized for %s.'), $GLOBALS['registry']->getAuth() ? 'User ' . $GLOBALS['registry']->getAuth() : 'Guest user', $this->applications[$app]['name']), self::PERMISSION_DENIED); + Horde::logMessage(sprintf('%s does not have READ permission for %s', $this->getAuth() ? 'User ' . $this->getAuth() : 'Guest user', $app), 'DEBUG'); + throw new Horde_Exception(sprintf(_('%s is not authorized for %s.'), $this->getAuth() ? 'User ' . $this->getAuth() : 'Guest user', $this->applications[$app]['name']), self::PERMISSION_DENIED); } } @@ -1230,8 +1230,8 @@ class Horde_Registry * explicit permissions, or for apps that allow the given permission. */ return $this->isAdmin() || ($GLOBALS['injector']->getInstance('Horde_Perms')->exists($app) - ? $GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission($app, $GLOBALS['registry']->getAuth(), $perms) - : (bool)$GLOBALS['registry']->getAuth()); + ? $GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission($app, $this->getAuth(), $perms) + : (bool)$this->getAuth()); } /** @@ -1272,12 +1272,12 @@ class Horde_Registry /* If there is no logged in user, return an empty Horde_Prefs:: * object with just default preferences. */ - if (!$GLOBALS['registry']->getAuth()) { + if (!$this->getAuth()) { $GLOBALS['prefs'] = Horde_Prefs::factory('Session', $app, '', '', null, false); } else { if (!isset($GLOBALS['prefs']) || - ($GLOBALS['prefs']->getUser() != $GLOBALS['registry']->getAuth())) { - $GLOBALS['prefs'] = Horde_Prefs::factory($GLOBALS['conf']['prefs']['driver'], $app, $GLOBALS['registry']->getAuth(), Horde_Auth::getCredential('password')); + ($GLOBALS['prefs']->getUser() != $this->getAuth())) { + $GLOBALS['prefs'] = Horde_Prefs::factory($GLOBALS['conf']['prefs']['driver'], $app, $this->getAuth(), Horde_Auth::getCredential('password')); } else { $GLOBALS['prefs']->retrieve($app); } @@ -1463,7 +1463,7 @@ class Horde_Registry /* Using cache while not authenticated isn't possible because, * although storage is possible, retrieval isn't since there is no * MD5 sum in the session to use to build the cache IDs. */ - if (!$GLOBALS['registry']->getAuth()) { + if (!$this->getAuth()) { return; } @@ -1499,7 +1499,7 @@ class Horde_Registry /* Using cache while not authenticated isn't possible because, * although storage is possible, retrieval isn't since there is no * MD5 sum in the session to use to build the cache IDs. */ - if ($GLOBALS['registry']->getAuth() && + if ($this->getAuth() && ($id = $this->_getCacheId($name))) { $result = $GLOBALS['injector']->getInstance('Horde_Cache')->get($id, 86400); if ($result !== false) { @@ -1641,7 +1641,7 @@ class Horde_Registry { $user = isset($options['user']) ? $options['user'] - : $GLOBALS['registry']->getAuth(); + : $this->getAuth(); if ($user && @is_array($GLOBALS['conf']['auth']['admins']) && -- 2.11.0