encode() public static method

Encode a string for LDAP with a specific encoding type.
public static encode ( string $value, string $toEncoding ) : string
$value string The value to encode.
$toEncoding string The encoding type to use (ie. UTF-8)
return string The encoded value.
Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function toLdap($password)
 {
     $this->validateConfiguration();
     if (!is_null($this->getLdapConnection())) {
         $password = LdapUtilities::encode($password, $this->getLdapConnection()->getConfig()->getEncoding());
     }
     return iconv("UTF-8", "UTF-16LE", '"' . $password . '"');
 }
Ejemplo n.º 2
0
 /**
  * Binds to LDAP with the supplied credentials or anonymously if specified.
  *
  * @param string $username The username to bind with.
  * @param string $password The password to bind with.
  * @param bool $anonymous Whether this is an anonymous bind attempt.
  * @throws LdapBindException
  */
 protected function bind($username, $password, $anonymous = false)
 {
     if ($anonymous) {
         $this->isBound = @ldap_bind($this->connection);
     } else {
         $this->isBound = @ldap_bind($this->connection, LdapUtilities::encode($username, $this->config->getEncoding()), LdapUtilities::encode($password, $this->config->getEncoding()));
     }
     if (!$this->isBound) {
         throw new LdapBindException(sprintf('Unable to bind to LDAP: %s', $this->getLastError()), $this->getExtendedErrorNumber());
     }
 }
Ejemplo n.º 3
0
 /**
  * Encodes any values with the needed type for LDAP.
  *
  * @param array|string $values
  * @return array
  */
 protected function encodeValues($values)
 {
     if (is_null($this->connection) || $this->type == AttributeConverterInterface::TYPE_SEARCH_FROM) {
         return $values;
     }
     $encoded = is_array($values) ? $values : [$values];
     foreach ($encoded as $index => $value) {
         if (is_string($value)) {
             $encoded[$index] = LdapUtilities::encode($value, $this->connection->getConfig()->getEncoding());
         }
     }
     // This is to pass it back the same way it was received. ldap_modify_batch is picky about values being an array.
     return is_array($values) ? $encoded : reset($encoded);
 }