Schema Attribute: add $one_value parameter to php2ldap() method

This commit is contained in:
Benjamin Renard 2023-03-21 16:53:46 +01:00
parent bb68b10ec4
commit 39dd48e0df
2 changed files with 33 additions and 27 deletions

View file

@ -111,29 +111,32 @@ class Attribute extends SchemaEntry {
}
/**
* Convert LDAP value to PHP value
* @param array<int,string> $value
* Convert LDAP values to PHP value
* @param array<int,string> $values
* @return string|array<string>|null
*/
public function ldap2php($value) {
if ($value)
return $this->single?$value[0]:$value;
public function ldap2php($values) {
if ($values)
return $this->single?$values[0]:$values;
return $this->single?null:array();
}
/**
* Convert LDAP value to PHP value
* Convert PHP value to LDAP values
* @param mixed $value
* @return array<int,string>
* @param bool $one_value Convert one value of the attribute (optional, default: false)
* @return ( $one_value is True ? string|null : array<int,string> )
*/
public function php2ldap($value) {
public function php2ldap($value, $one_value=false) {
if (is_null($value))
return array();
return $one_value?null:array();
if ($one_value)
return strval($value);
if (!is_array($value))
$value = array($value);
$ldap_value = array();
$ldap_values = array();
foreach($value as $v)
$ldap_value[] = strval($v);
return $ldap_value;
$ldap_values[] = strval($v);
return $ldap_values;
}
}

View file

@ -34,35 +34,38 @@ class BooleanAttribute extends \EesyLDAP\Schema\Attribute {
return null;
}
/**
* Convert LDAP value to PHP value
* @param array<int,string> $value
* Convert LDAP values to PHP value
* @param array<int,string> $values
* @return bool|null|array<bool|null>
*/
public function ldap2php($value) {
$value = parent::ldap2php($value);
if (is_string($value))
return self :: _ldap2php($value);
if (is_array($value)) {
public function ldap2php($values) {
$values = parent::ldap2php($values);
if (is_string($values))
return self :: _ldap2php($values);
if (is_array($values)) {
$php_value = array();
foreach($value as $v)
$php_value[] = self :: _ldap2php($v);
foreach($values as $value)
$php_value[] = self :: _ldap2php($value);
return $php_value;
}
return $this->single?null:array();
}
/**
* Convert LDAP value to PHP value
* Convert PHP value to LDAP values
* @param mixed $value
* @return array<int,string>
* @param bool $one_value Convert one value value of the attribute (optional, default: false)
* @return ( $one_value is True ? string : array<int,string> )
*/
public function php2ldap($value) {
public function php2ldap($value, $one_value=false) {
if (is_null($value))
return array();
if ($one_value)
return $value?self :: TRUE_VALUE:self :: FALSE_VALUE;
$value = is_array($value)?$value:array($value);
$ldap_value = array();
$ldap_values = array();
foreach(parent::php2ldap($value) as $value)
$ldap_value[] = $value?self :: TRUE_VALUE:self :: FALSE_VALUE;
return $ldap_value;
$ldap_values[] = $value?self :: TRUE_VALUE:self :: FALSE_VALUE;
return $ldap_values;
}
}