protected static function escapeManualWithFlags($value, $ignore = '', $flags = 0)
{
// Convert ignore string into an array
$ignores = static::ignoreStrToArray($ignore);
// The escape characters for search filters
$escapeFilter = ['\\', '*', '(', ')'];
// The escape characters for distinguished names
$escapeDn = ['\\', ',', '=', '+', '<', '>', ';', '"', '#'];
switch ($flags) {
case 1:
// Int 1 equals to LDAP_ESCAPE_FILTER
$escapes = $escapeFilter;
break;
case 2:
// Int 2 equals to LDAP_ESCAPE_DN
$escapes = $escapeDn;
break;
case 3:
// If both LDAP_ESCAPE_FILTER and LDAP_ESCAPE_DN are used
$escapes = array_unique(array_merge($escapeDn, $escapeFilter));
break;
default:
// We've been given an invalid flag, we'll escape everything to be safe.
return static::escapeManual($value, $ignore);
}
foreach ($escapes as $escape) {
// Make sure the escaped value isn't being ignored.
if (!in_array($escape, $ignores)) {
$hexed = static::escape($escape);
$value = str_replace($escape, $hexed, $value);
}
}
return $value;
}