public function toLdap($sid)
{
if (!LdapUtilities::isValidSid($sid)) {
throw new AttributeConverterException(sprintf('Expected a string SID but got "%s".', $sid));
}
$sid = (new SID($sid))->toBinary();
if ($this->getOperationType() == self::TYPE_SEARCH_TO) {
// All hex parts must have a leading backslash for the search.
$sid = '\\' . implode('\\', str_split(bin2hex($sid), '2'));
}
return $sid;
}