escapeValue() public static method

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.
return string The escaped value.
Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * Returns the operator translated to its LDAP filter string value.
  *
  * @param string|null $alias
  * @return string
  */
 public function toLdapFilter($alias = null)
 {
     if ($this->skipFilterForAlias($alias)) {
         return '';
     }
     if ($this->getValueForQuery($alias) instanceof BaseOperator) {
         return $this->getValueForQuery($alias)->toLdapFilter($alias);
     }
     return self::SEPARATOR_START . $this->getAttributeToQuery($alias) . $this->operatorSymbol . LdapUtilities::escapeValue($this->getValueForQuery($alias), null, LDAP_ESCAPE_FILTER) . self::SEPARATOR_END;
 }
Ejemplo n.º 3
0
 /**
  * Builds the DN based off of the "name" attribute. The name attribute should be mapped to the "cn" attribute in
  * pretty much all cases except for creating an OU object. Then the "name" attribute should be mapped to "ou".
  *
  * @param AddOperation $operation
  */
 protected function setDnToUse(AddOperation $operation)
 {
     // If the DN was explicitly set, don't do anything.
     if ($operation->getDn()) {
         return;
     }
     if (!$this->schema) {
         throw new LogicException("You must explicitly set the DN or specify a schema type.");
     }
     if (!$this->schema->hasAttribute('name')) {
         throw new LogicException('To create an object you must specify the name attribute in the schema. That attribute should typically' . ' map to the "cn" attribute, as it will use that as the base of the distinguished name.');
     }
     $location = $operation->getLocation() ?: $this->schema->getDefaultContainer();
     if (empty($location)) {
         throw new LogicException('You must specify a container or OU to place this LDAP object in.');
     }
     $attribute = $this->schema->getAttributeToLdap('name');
     $rdnValue = LdapUtilities::escapeValue($operation->getAttributes()[$attribute], null, LDAP_ESCAPE_DN);
     $location = $this->resolveParameters(['container' => $location])['container'];
     $operation->setDn($attribute . '=' . $rdnValue . ',' . $location);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function toLdapFilter($alias = null)
 {
     if ($this->skipFilterForAlias($alias)) {
         return '';
     }
     if ($this->getValueForQuery($alias) instanceof BaseOperator) {
         return $this->getValueForQuery($alias)->toLdapFilter($alias);
     }
     if ($this->wildcardType == self::CONTAINS) {
         $value = '*' . LdapUtilities::escapeValue($this->getValueForQuery($alias), null, LDAP_ESCAPE_FILTER) . '*';
     } elseif ($this->wildcardType == self::STARTS_WITH) {
         $value = LdapUtilities::escapeValue($this->getValueForQuery($alias), null, LDAP_ESCAPE_FILTER) . '*';
     } elseif ($this->wildcardType == self::ENDS_WITH) {
         $value = '*' . LdapUtilities::escapeValue($this->getValueForQuery($alias), null, LDAP_ESCAPE_FILTER);
     } elseif ($this->wildcardType == self::LIKE) {
         $value = LdapUtilities::escapeValue($this->getValueForQuery($alias), '*', LDAP_ESCAPE_FILTER);
     } else {
         $value = '*';
     }
     return self::SEPARATOR_START . $this->getAttributeToQuery($alias) . $this->operatorSymbol . $value . self::SEPARATOR_END;
 }