Horde_Ldap_Util::_correctDNSplitting PHP Method

_correctDNSplitting() protected static method

Corrects splitting of DN parts.
protected static _correctDNSplitting ( array $dn = [], array $separator = ',' ) : array
$dn array Raw DN array.
$separator array Separator that was used when splitting.
return array Corrected array.
    protected static function _correctDNSplitting($dn = array(), $separator = ',')
    {
        foreach ($dn as $key => $dn_value) {
            // Refresh value (foreach caches!)
            $dn_value = $dn[$key];
            // If $dn_value is not in attr=value format, we had an unescaped
            // separator character inside the attr name or the value. We assume
            // that it was the attribute value.
            // TODO: To solve this, we might ask the schema. The
            //       Horde_Ldap_Util class must remain independent from the
            //       other classes or connections though.
            if (!preg_match('/.+(?<!\\\\)=.+/', $dn_value)) {
                unset($dn[$key]);
                if (array_key_exists($key - 1, $dn)) {
                    // Append to previous attribute value.
                    $dn[$key - 1] = $dn[$key - 1] . $separator . $dn_value;
                } elseif (array_key_exists($key + 1, $dn)) {
                    // First element: prepend to next attribute name.
                    $dn[$key + 1] = $dn_value . $separator . $dn[$key + 1];
                } else {
                    $dn[$key] = $dn_value;
                }
            }
        }
        return array_values($dn);
    }