Example #1
0
 public function testHex2asc()
 {
     $expected = '';
     for ($i = 0; $i < 127; $i++) {
         $expected .= chr($i);
     }
     $str = '\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f\\10\\11\\12\\13\\14\\15\\16\\17\\18\\19\\1a\\1b' . '\\1c\\1d\\1e\\1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefg' . 'hijklmnopqrstuvwxyz{|}~';
     $this->assertEquals($expected, Zend_Ldap_Converter::hex32ToAsc($str));
 }
Example #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 = array())
 {
     /**
      * @see Zend_Ldap_Converter
      */
     require_once 'Zend/Ldap/Converter.php';
     if (!is_array($values)) {
         $values = array($values);
     }
     foreach ($values as $key => $val) {
         // strip slashes from special chars
         $val = str_replace(array('\\\\', '\\,', '\\+', '\\"', '\\<', '\\>', '\\;', '\\#', '\\='), array('\\', ',', '+', '"', '<', '>', ';', '#', '='), $val);
         $values[$key] = Zend_Ldap_Converter::hex32ToAsc($val);
     }
     return count($values) == 1 ? $values[0] : $values;
 }
Example #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())
 {
     /**
      * @see Zend_Ldap_Converter
      */
     require_once 'Zend/Ldap/Converter.php';
     if (!is_array($values)) {
         $values = array($values);
     }
     foreach ($values as $key => $value) {
         // Translate hex code into ascii
         $values[$key] = Zend_Ldap_Converter::hex32ToAsc($value);
     }
     return count($values) == 1 ? $values[0] : $values;
 }
Example #4
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 Zend_Ldap_Converter::fromLdapDateTime($value, false)->format('U');
             } catch (InvalidArgumentException $e) {
                 return null;
             }
         } else {
             return null;
         }
     }
 }
Example #5
0
 /**
  * @dataProvider fromLdapProvider
  */
 public function testFromLdap($expect, $value, $type, $dateTimeAsUtc)
 {
     $this->assertSame($expect, Zend_Ldap_Converter::fromLdap($value, $type, $dateTimeAsUtc));
 }
 /**
  * @expectedException	InvalidArgumentException
  * @dataProvider		fromLdapDateTimeException
  */
 public function testFromLdapDateTimeThrowsException($value)
 {
     Zend_Ldap_Converter::fromLdapDatetime($value);
 }