LdapTools\Utilities\LdapUtilities::escapeValue PHP Метод

escapeValue() публичный статический Метод

Escape any special characters for LDAP to their hexadecimal representation.
public static escapeValue ( mixed $value, null | string $ignore = null, null | integer $flags = null ) : string
$value mixed The value to escape.
$ignore null | string The characters to ignore.
$flags null | integer The context for the escaped string. LDAP_ESCAPE_FILTER or LDAP_ESCAPE_DN.
Результат string The escaped value.
    public static function escapeValue($value, $ignore = null, $flags = null)
    {
        // If this is a hexadecimal escaped string, then do not escape it.
        $value = preg_match('/^(\\\\[0-9a-fA-F]{2})+$/', (string) $value) ? $value : ldap_escape($value, $ignore, $flags);
        // Per RFC 4514, leading/trailing spaces should be encoded in DNs, as well as carriage returns.
        if ((int) $flags & LDAP_ESCAPE_DN) {
            if (!empty($value) && $value[0] === ' ') {
                $value = '\\20' . substr($value, 1);
            }
            if (!empty($value) && $value[strlen($value) - 1] === ' ') {
                $value = substr($value, 0, -1) . '\\20';
            }
            // Only carriage returns seem to be valid, not line feeds (per testing of AD anyway).
            $value = str_replace("\r", '\\0d', $value);
        }
        return $value;
    }

Usage Example

Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function toLdapFilter($alias = null)
 {
     if ($this->skipFilterForAlias($alias)) {
         return '';
     }
     if (!LdapUtilities::isValidAttributeFormat($this->oid)) {
         throw new LdapQueryException(sprintf('Matching rule "%s" is not a valid format.', $this->oid));
     }
     if ($this->getValueForQuery($alias) instanceof BaseOperator) {
         return $this->getValueForQuery($alias)->toLdapFilter($alias);
     }
     return self::SEPARATOR_START . $this->getAttributeToQuery($alias) . ':' . $this->oid . ':' . $this->operatorSymbol . LdapUtilities::escapeValue($this->getValueForQuery($alias), null, LDAP_ESCAPE_FILTER) . self::SEPARATOR_END;
 }
All Usage Examples Of LdapTools\Utilities\LdapUtilities::escapeValue