encode() 공개 정적인 메소드

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)
리턴 string The encoded value.
예제 #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 . '"');
 }
예제 #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());
     }
 }
예제 #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);
 }