/** * Create LDAPEntry from a given DN and associative * array * * @param string dn * @param [:string] data * @return peer.ldap.LDAPEntry */ protected static function _create($dn, array $data) { $e = new self($dn); foreach ($data as $key => $value) { if ('count' == $key || is_int($key)) { continue; } // Store case-preserved version of key name in _ans array $lkey = strtolower($key); $e->_ans[$lkey] = $key; if (is_array($value)) { $e->attributes[$lkey] = array_map(array($e, '_decode'), $value); } else { $e->attributes[$lkey] = $e->_decode($value); } unset($e->attributes[$lkey]['count']); } return $e; }
/** * Decodes the string $string into an array of LDIF items * * @param string $string * @return array */ public static function decode($string) { $encoder = new self(array()); return $encoder->_decode($string); }
/** * Takes a bencode encoded string and converts it to an array. * * @param string $source The bencode encoded string * @param string $decodeType Return an array or an object * @return array * @throws Rych_Bencode_Exception * * @todo Convert resulting array to object if $decodeType is object */ static public function decode($source, $decodeType = Rych_Bencode::TYPE_ARRAY) { if (!is_string($source)) { require_once 'Rych/Bencode/Exception.php'; throw new Rych_Bencode_Exception( 'Argument expected to be a string; Got ' . gettype($source) ); } $decoder = new self($source, $decodeType); $decoded = $decoder->_decode(); if ($decoder->_offset != $decoder->_sourceLength) { require_once 'Rych/Bencode/Exception.php'; throw new Rych_Bencode_Exception( 'Found multiple entities outside list or dict definitions' ); } return $decoded; }
/** * Decode a JSON source string. * * Decodes a JSON encoded string. The value returned will be one of the * following: * - integer * - float * - boolean * - null * - StdClass * - array * - array of one or more of the above types * * @param string $source String to be decoded. * * @return mixed The decoded source. */ public function decode($source) { $decoder = new self($source); $decoder->setOptions($this->getOptions()); return $decoder->_decode(); }