예제 #1
0
파일: Client.php 프로젝트: juvenn/php-sdk
 /**
  * Decode value from LeanCloud response.
  *
  * @param mixed  $value Value to decode
  * @param string $key   Field key for the value
  * @return mixed
  */
 public static function decode($value, $key)
 {
     if (!is_array($value)) {
         return $value;
     }
     if ($key === 'ACL') {
         return new ACL($value);
     }
     if (!isset($value["__type"])) {
         $out = array();
         foreach ($value as $k => $v) {
             $out[$k] = self::decode($v, $k);
         }
         return $out;
     }
     // Parse different data type from server.
     $type = $value["__type"];
     if ($type === "Date") {
         // return time in default time zone
         return new \DateTime($value["iso"]);
     }
     if ($type === "Bytes") {
         return Bytes::createFromBase64Data($value["base64"]);
     }
     if ($type === "GeoPoint") {
         return new GeoPoint($value["latitude"], $value["longitude"]);
     }
     if ($type === "File") {
         $file = new File($value["name"]);
         $file->mergeAfterFetch($value);
         return $file;
     }
     if ($type === "Pointer" || $type === "Object") {
         $obj = Object::create($value["className"], $value["objectId"]);
         unset($value["__type"]);
         unset($value["className"]);
         if (!empty($value)) {
             $obj->mergeAfterFetch($value);
         }
         return $obj;
     }
     if ($type === "Relation") {
         return new Relation(null, $key, $value["className"]);
     }
 }
예제 #2
0
 public function testEncodeCreateFromBase64()
 {
     $bytes = Bytes::createFromBase64Data(base64_encode("Hello"));
     $out = $bytes->encode();
     $this->assertEquals(base64_encode("Hello"), $out["base64"]);
 }