Exemplo n.º 1
0
 /**
  * @dataProvider fromLdapProvider
  */
 public function testFromLdap($expect, $value, $type, $dateTimeAsUtc)
 {
     $this->assertSame($expect, Converter::fromLdap($value, $type, $dateTimeAsUtc));
 }
Exemplo n.º 2
0
 /**
  * Undoes the conversion done by {@link escapeValue()}.
  *
  * Any escape sequence starting with a baskslash - hexpair or special character -
  * will be transformed back to the corresponding character.
  * @see    Net_LDAP2_Util::escape_dn_value() from Benedikt Hallinger <*****@*****.**>
  * @link   http://pear.php.net/package/Net_LDAP2
  * @author Benedikt Hallinger <*****@*****.**>
  *
  * @param  string|array $values Array of DN Values
  * @return array Same as $values, but unescaped
  */
 public static function unescapeValue($values = [])
 {
     if (!is_array($values)) {
         $values = [$values];
     }
     foreach ($values as $key => $val) {
         // strip slashes from special chars
         $val = str_replace(['\\\\', '\\,', '\\+', '\\"', '\\<', '\\>', '\\;', '\\#', '\\='], ['\\', ',', '+', '"', '<', '>', ';', '#', '='], $val);
         $values[$key] = Converter\Converter::hex32ToAsc($val);
     }
     return count($values) == 1 ? $values[0] : $values;
 }
Exemplo n.º 3
0
 /**
  * Undoes the conversion done by {@link escapeValue()}.
  *
  * Converts any sequences of a backslash followed by two hex digits into the corresponding character.
  * @see    Net_LDAP2_Util::escape_filter_value() from Benedikt Hallinger <*****@*****.**>
  * @link   http://pear.php.net/package/Net_LDAP2
  * @author Benedikt Hallinger <*****@*****.**>
  *
  * @param  string|array $values Array of values to escape
  * @return array Array $values, but unescaped
  */
 public static function unescapeValue($values = array())
 {
     if (!is_array($values)) {
         $values = array($values);
     }
     foreach ($values as $key => $value) {
         // Translate hex code into ascii
         $values[$key] = Converter::hex32ToAsc($value);
     }
     return count($values) == 1 ? $values[0] : $values;
 }
Exemplo n.º 4
0
 /**
  * Parse the given tokens into a data structure
  *
  * @param  array $data
  * @param  array $tokens
  * @return void
  */
 protected function parseLdapSchemaSyntax(array &$data, array $tokens)
 {
     // tokens that have no value associated
     $noValue = array('single-value', 'obsolete', 'collective', 'no-user-modification', 'abstract', 'structural', 'auxiliary');
     // tokens that can have multiple values
     $multiValue = array('must', 'may', 'sup');
     while (count($tokens) > 0) {
         $token = strtolower(array_shift($tokens));
         if (in_array($token, $noValue)) {
             $data[$token] = true;
             // single value token
         } else {
             $data[$token] = array_shift($tokens);
             // this one follows a string or a list if it is multivalued
             if ($data[$token] == '(') {
                 // this creates the list of values and cycles through the tokens
                 // until the end of the list is reached ')'
                 $data[$token] = array();
                 $tmp = array_shift($tokens);
                 while ($tmp) {
                     if ($tmp == ')') {
                         break;
                     }
                     if ($tmp != '$') {
                         $data[$token][] = Converter\Converter::fromLdap($tmp);
                     }
                     $tmp = array_shift($tokens);
                 }
             } else {
                 $data[$token] = Converter\Converter::fromLdap($data[$token]);
             }
             // create a array if the value should be multivalued but was not
             if (in_array($token, $multiValue) && !is_array($data[$token])) {
                 $data[$token] = array($data[$token]);
             }
         }
     }
 }
Exemplo n.º 5
0
    /**
     * @param  string|DateTime $value
     * @return integer|null
     */
    private static function valueFromLdapDateTime($value)
    {
        if ($value instanceof DateTime) {
            return $value->format('U');
        } else if (is_string($value)) {
            try {
                return Converter\Converter::fromLdapDateTime($value, false)->format('U');
            } catch (Converter\Exception\InvalidArgumentException $e) {
                return null;
            }
        }

        return null;
    }