LSldapObject->getValue(): add $first and $default parameters

This commit is contained in:
Benjamin Renard 2020-08-26 12:56:58 +02:00
parent 6ed225be8f
commit 4c1c7b2fae

View file

@ -865,47 +865,48 @@ class LSldapObject extends LSlog_staticLoggerClass {
} }
/** /**
* Retourne une valeur de l'objet * Return an objet value
* *
* Retourne une valeur en fonction du paramètre. Si la valeur est inconnue, la valeur retourné est ' '. * The value returned depends of the $val parameter. If the requested value is unknown, the returned value
* tableau d'objet correspond au resultat de la recherche. * will be $default (default: a space caracter = ' ').
* *
* Valeurs possibles : * Supported values:
* - 'dn' ou '%{dn} : DN de l'objet * - 'dn' ou '%{dn} : The object DN
* - [nom d'un attribut] : valeur de l'attribut * - [attribute name] : the value of the corresponding attribute
* - [clef de $this -> other_values] : valeur de $this -> other_values * - [key of $this -> other_values] : the value of corresponding key in $this -> other_values
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @param[in] $val string Le nom de la valeur demandée * @param[in] $val string The requested value
* @param[in] $first boolean If true and the result is an array, return only the first value (optional, default: false)
* @param[in] $default mixed Default value if unknown (optional, default: a space caracter = ' ')
* *
* @retval mixed la valeur demandé ou ' ' si celle-ci est inconnue. * @retval mixed The requested value or $default if unknown
*/ */
public function getValue($val) { public function getValue($val, $first=false, $default=' ') {
$return = $default;
if(($val=='dn')||($val=='%{dn}')) { if(($val=='dn')||($val=='%{dn}')) {
return $this -> dn; $return = $this -> dn;
} }
else if(($val=='rdn')||($val=='%{rdn}')) { else if(($val=='rdn')||($val=='%{rdn}')) {
return $this -> rdn; $return = $this -> rdn;
} }
else if(($val=='subDn')||($val=='%{subDn}')) { else if(($val=='subDn')||($val=='%{subDn}')) {
return $this -> subDnValue; $return = $this -> subDnValue;
} }
else if(($val=='subDnName')||($val=='%{subDnName}')) { else if(($val=='subDnName')||($val=='%{subDnName}')) {
return $this -> subDnName; $return = $this -> subDnName;
} }
else if(isset($this -> attrs[$val])){ else if(isset($this -> attrs[$val])){
if (method_exists($this -> attrs[$val],'getValue')) if (method_exists($this -> attrs[$val],'getValue'))
return $this -> attrs[$val] -> getValue(); $return = $this -> attrs[$val] -> getValue();
else
return ' ';
} }
else if(isset($this -> other_values[$val])){ else if(isset($this -> other_values[$val])){
return $this -> other_values[$val]; $return = $this -> other_values[$val];
}
else {
return ' ';
} }
if (is_array($return) && $first)
$return = (count($return) >= 1?$return[0]:null);
return $return;
} }
/** /**