Exemple #1
0
 /**
  * Fetch file object by id
  *
  * Note it fetches descriptive data from LeanCloud, but not file content.
  * The content should be fetched from file URL.
  *
  * @return LeanFile
  */
 public static function fetch($objectId)
 {
     $file = new LeanFile("");
     $resp = LeanClient::get("/files/{$objectId}");
     $file->mergeAfterFetch($resp);
     return $file;
 }
Exemple #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"]);
     }
 }
Exemple #3
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"]);
     }
 }