Exemplo n.º 1
0
 /**
  * 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 LeanACL($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 LeanBytes::createFromBase64Data($value["base64"]);
     }
     if ($type === "GeoPoint") {
         return new GeoPoint($value["latitude"], $value["longitude"]);
     }
     if ($type === "File") {
         $file = new LeanFile($value["name"]);
         $file->mergeAfterFetch($value);
         return $file;
     }
     if ($type === "Pointer" || $type === "Object") {
         $obj = LeanObject::create($value["className"], $value["objectId"]);
         unset($value["__type"]);
         unset($value["className"]);
         if (!empty($value)) {
             $obj->mergeAfterFetch($value);
         }
         return $obj;
     }
     if ($type === "Relation") {
         return new LeanRelation(null, $key, $value["className"]);
     }
 }
Exemplo n.º 2
0
 /**
  * Decode value from LeanCloud response.
  *
  * @param mixed $value
  * @return mixed
  */
 public static function decode($value)
 {
     if (is_null($value) || is_scalar($value)) {
         return $value;
     }
     if (isset($value["*"]) && isset($value["*"]["read"])) {
         // skip ACL for now
         return null;
     }
     if (!isset($value["__type"])) {
         $out = array();
         foreach ($value as $key => $val) {
             $out[$key] = self::decode($val);
         }
         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 LeanBytes::createFromBase64Data($value["base64"]);
     }
     if ($type == "GeoPoint") {
     }
     if ($type == "File") {
         $file = new LeanFile($value["name"]);
         $file->mergeAfterFetch($value);
         return $file;
     }
     if ($type == "Pointer" || $type == "Object") {
         $obj = LeanObject::create($value["className"], $value["objectId"]);
         unset($value["__type"]);
         unset($value["className"]);
         if (!empty($value)) {
             $obj->mergeAfterFetch($value);
         }
         return $obj;
     }
     if ($type == "Relation") {
         return new LeanRelation(null, null, $value["className"]);
     }
 }
Exemplo n.º 3
0
 public function testEncodeCreateFromBase64()
 {
     $bytes = LeanBytes::createFromBase64Data(base64_encode("Hello"));
     $out = $bytes->encode();
     $this->assertEquals(base64_encode("Hello"), $out["base64"]);
 }