mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-12-20 23:43:49 +01:00
LSsearch: Add option to disable cache on customInfos
This commit is contained in:
parent
2ed985324e
commit
cb83311bd0
2 changed files with 27 additions and 5 deletions
|
@ -518,7 +518,8 @@ class LSsearch {
|
||||||
if (is_callable($data['function'])) {
|
if (is_callable($data['function'])) {
|
||||||
$this -> params['customInfos'][$name] = array (
|
$this -> params['customInfos'][$name] = array (
|
||||||
'function' => &$data['function'],
|
'function' => &$data['function'],
|
||||||
'args' => $data['args']
|
'args' => (isset($data['args'])?$data['args']:null),
|
||||||
|
'cache' => (isset($data['cache'])?boolval($data['cache']):true),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -39,7 +39,7 @@ class LSsearchEntry extends LSlog_staticLoggerClass {
|
||||||
private $dn;
|
private $dn;
|
||||||
|
|
||||||
// The parameters of the search
|
// The parameters of the search
|
||||||
private $params=array ();
|
private $params = array();
|
||||||
|
|
||||||
// The hash of the search parameters
|
// The hash of the search parameters
|
||||||
private $hash = NULL;
|
private $hash = NULL;
|
||||||
|
@ -237,16 +237,24 @@ class LSsearchEntry extends LSlog_staticLoggerClass {
|
||||||
return (isset($this -> attrs[$key])?$this -> attrs[$key]:null);
|
return (isset($this -> attrs[$key])?$this -> attrs[$key]:null);
|
||||||
}
|
}
|
||||||
elseif (array_key_exists($key,$this->params['customInfos'])) {
|
elseif (array_key_exists($key,$this->params['customInfos'])) {
|
||||||
if(isset($this -> cache['customInfos'][$key])) {
|
$cache = $this -> getConfig("customInfos.$key.cache", true, 'bool');
|
||||||
|
if($cache && isset($this -> cache['customInfos'][$key])) {
|
||||||
|
self :: log_debug("__get($key): custom info retreived from cache");
|
||||||
return $this -> cache['customInfos'][$key];
|
return $this -> cache['customInfos'][$key];
|
||||||
}
|
}
|
||||||
if(is_array($this->params['customInfos'][$key]['function']) && is_string($this->params['customInfos'][$key]['function'][0])) {
|
if(is_array($this->params['customInfos'][$key]['function']) && is_string($this->params['customInfos'][$key]['function'][0])) {
|
||||||
|
self :: log_debug("__get($key): load class '".$this->params['customInfos'][$key]['function'][0]."'");
|
||||||
LSsession::loadLSclass($this->params['customInfos'][$key]['function'][0]);
|
LSsession::loadLSclass($this->params['customInfos'][$key]['function'][0]);
|
||||||
}
|
}
|
||||||
if(is_callable($this->params['customInfos'][$key]['function'])) {
|
if(is_callable($this->params['customInfos'][$key]['function'])) {
|
||||||
$this -> cache['customInfos'][$key]=call_user_func($this->params['customInfos'][$key]['function'],$this,$this->params['customInfos'][$key]['args']);
|
self :: log_debug("__get($key): call ".varDump($this->params['customInfos'][$key]['function'])."");
|
||||||
return $this -> cache['customInfos'][$key];
|
$value = call_user_func($this->params['customInfos'][$key]['function'], $this, $this->params['customInfos'][$key]['args']);
|
||||||
|
if ($cache)
|
||||||
|
$this -> cache['customInfos'][$key] = $value;
|
||||||
|
return $value;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
self :: log_error("__get($key): custom info function is not callable: ".varDump($this->params['customInfos'][$key]['function']));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self :: log_warning('LSsearchEntry : '.$this -> dn.' => Unknown property '.$key.' !');
|
self :: log_warning('LSsearchEntry : '.$this -> dn.' => Unknown property '.$key.' !');
|
||||||
|
@ -254,6 +262,19 @@ class LSsearchEntry extends LSlog_staticLoggerClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a configuration parameter (or default value)
|
||||||
|
*
|
||||||
|
* @param[] $param The configuration parameter
|
||||||
|
* @param[] $default The default value (default : null)
|
||||||
|
* @param[] $cast Cast resulting value in specific type (default : disabled)
|
||||||
|
*
|
||||||
|
* @retval mixed The configuration parameter value or default value if not set
|
||||||
|
**/
|
||||||
|
function getConfig($param, $default=null, $cast=null) {
|
||||||
|
return LSconfig :: get($param, $default, $cast, $this -> params);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue