controller->Auth(): one more lazy-loading helper
Not sure about the capital A, but doesn't look so bad - and similar to Config().
This commit is contained in:
parent
373e1c5ecb
commit
a4955df1a9
|
@ -86,6 +86,8 @@ class ActionController extends Zend_Controller_Action
|
||||||
|
|
||||||
protected $params;
|
protected $params;
|
||||||
|
|
||||||
|
private $auth;
|
||||||
|
|
||||||
public function Config($file = null)
|
public function Config($file = null)
|
||||||
{
|
{
|
||||||
if ($file === null) {
|
if ($file === null) {
|
||||||
|
@ -102,6 +104,14 @@ class ActionController extends Zend_Controller_Action
|
||||||
return $this->config;
|
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
|
* The constructor starts benchmarking, loads the configuration and sets
|
||||||
* other useful controller properties
|
* other useful controller properties
|
||||||
|
@ -211,7 +221,7 @@ class ActionController extends Zend_Controller_Action
|
||||||
*/
|
*/
|
||||||
public function getRestrictions($name)
|
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)
|
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)
|
public function assertPermission($name)
|
||||||
{
|
{
|
||||||
if (! AuthManager::getInstance()->hasPermission($name)) {
|
if (! $this->Auth()->hasPermission($name)) {
|
||||||
// TODO: Shall this be an Auth Exception? Or a 404?
|
// TODO: Shall this be an Auth Exception? Or a 404?
|
||||||
throw new Exception(sprintf('Auth error, no permission for "%s"', $name));
|
throw new Exception(sprintf('Auth error, no permission for "%s"', $name));
|
||||||
}
|
}
|
||||||
|
@ -280,7 +290,7 @@ class ActionController extends Zend_Controller_Action
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !AuthManager::getInstance()->isAuthenticated();
|
return !$this->Auth()->isAuthenticated();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue