From a4955df1a9c7e889f6abd9392560bdb3f2257a36 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 22 Jun 2014 12:06:09 +0200 Subject: [PATCH] controller->Auth(): one more lazy-loading helper Not sure about the capital A, but doesn't look so bad - and similar to Config(). --- .../Icinga/Web/Controller/ActionController.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index d9bb1d483..9d1017c80 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -86,6 +86,8 @@ class ActionController extends Zend_Controller_Action protected $params; + private $auth; + public function Config($file = null) { if ($file === null) { @@ -102,6 +104,14 @@ class ActionController extends Zend_Controller_Action return $this->config; } + public function Auth() + { + if ($this->auth === null) { + $this->auth = AuthManager::getInstance(); + } + return $this->auth; + } + /** * The constructor starts benchmarking, loads the configuration and sets * other useful controller properties @@ -211,7 +221,7 @@ class ActionController extends Zend_Controller_Action */ public function getRestrictions($name) { - return AuthManager::getInstance()->getRestrictions($name); + return $this->Auth()->getRestrictions($name); } /** @@ -222,7 +232,7 @@ class ActionController extends Zend_Controller_Action */ public function hasPermission($name) { - return AuthManager::getInstance()->hasPermission($name); + return $this->Auth()->hasPermission($name); } /** @@ -233,7 +243,7 @@ class ActionController extends Zend_Controller_Action */ public function assertPermission($name) { - if (! AuthManager::getInstance()->hasPermission($name)) { + if (! $this->Auth()->hasPermission($name)) { // TODO: Shall this be an Auth Exception? Or a 404? throw new Exception(sprintf('Auth error, no permission for "%s"', $name)); } @@ -280,7 +290,7 @@ class ActionController extends Zend_Controller_Action return false; } - return !AuthManager::getInstance()->isAuthenticated(); + return !$this->Auth()->isAuthenticated(); } /**