/** * Create a ParseRole object with a given name and ACL. * * @param string $name * @param ParseACL $acl * * @return ParseRole */ public static function createRole($name, ParseACL $acl) { $role = ParseObject::create(static::$parseClassName); $role->setName($name); $role->setACL($acl); return $role; }
/** * Logs in with Facebook details, or throws if invalid. * * @param string $id the Facebook user identifier * @param string $access_token the access token for this session * @param \DateTime $expiration_date defaults to 60 days * * @throws ParseException * * @return ParseUser */ public static function logInWithFacebook($id, $access_token, $expiration_date = null) { if (!$id) { throw new ParseException("Cannot log in Facebook user without an id."); } if (!$access_token) { throw new ParseException("Cannot log in Facebook user without an access token."); } if (!$expiration_date) { $expiration_date = new \DateTime(); $expiration_date->setTimestamp(time() + 86400 * 60); } $data = ["authData" => ["facebook" => ["id" => $id, "access_token" => $access_token, "expiration_date" => ParseClient::getProperDateFormat($expiration_date)]]]; $result = ParseClient::_request("POST", "/1/users", "", json_encode($data)); $user = ParseObject::create('_User'); $user->_mergeAfterFetch($result); $user->handleSaveResult(true); ParseClient::getStorage()->set("user", $user); return $user; }
/** * Execute a find query and return the results. * * @param boolean $useMasterKey * * @return array */ public function find($useMasterKey = false) { $sessionToken = null; if (ParseUser::getCurrentUser()) { $sessionToken = ParseUser::getCurrentUser()->getSessionToken(); } $queryString = $this->buildQueryString($this->_getOptions()); $result = ParseClient::_request('GET', '/1/classes/' . $this->className . '?' . $queryString, $sessionToken, null, $useMasterKey); $output = array(); foreach ($result['results'] as $row) { $obj = ParseObject::create($this->className, $row['objectId']); $obj->_mergeAfterFetchWithSelectedKeys($row, $this->selectedKeys); $output[] = $obj; } return $result; }
/** * Logs in with Facebook details, or throws if invalid. * * @param string $id the Facebook user identifier * @param string $access_token the access token for this session * @param \DateTime $expiration_date defaults to 60 days * * @throws ParseException * * @return ParseUser */ public static function logInWithFacebook($id, $access_token, $expiration_date = null) { if (!$id) { throw new ParseException('Cannot log in Facebook user without an id.'); } if (!$access_token) { throw new ParseException('Cannot log in Facebook user without an access token.'); } if (!$expiration_date) { $expiration_date = new \DateTime(); $expiration_date->setTimestamp(time() + 86400 * 60); } $data = ['authData' => ['facebook' => ['id' => $id, 'access_token' => $access_token, 'expiration_date' => ParseClient::getProperDateFormat($expiration_date)]]]; $result = ParseClient::_request('POST', 'users', '', json_encode($data)); $user = ParseObject::create('_User'); $user->_mergeAfterFetch($result); $user->handleSaveResult(true); ParseClient::getStorage()->set('user', $user); return $user; }
/** * ParseClient::_decode, internal method for decoding server responses. * * @param mixed $data The value to decode * * @return mixed * @ignore */ public static function _decode($data) { // The json decoded response from Parse will make JSONObjects into stdClass // objects. We'll change it to an associative array here. if ($data instanceof \stdClass) { $tmp = (array) $data; if (!empty($tmp)) { return self::_decode(get_object_vars($data)); } } if (!$data && !is_array($data)) { return null; } if (is_array($data)) { $typeString = isset($data['__type']) ? $data['__type'] : null; if ($typeString === 'Date') { return new \DateTime($data['iso']); } if ($typeString === 'Bytes') { return base64_decode($data['base64']); } if ($typeString === 'Pointer') { return ParseObject::create($data['className'], $data['objectId']); } if ($typeString === 'File') { return ParseFile::_createFromServer($data['name'], $data['url']); } if ($typeString === 'GeoPoint') { return new ParseGeoPoint($data['latitude'], $data['longitude']); } if ($typeString === 'Object') { $output = ParseObject::create($data['className']); $output->_mergeAfterFetch($data); return $output; } if ($typeString === 'Relation') { return $data; } $newDict = array(); foreach ($data as $key => $value) { $newDict[$key] = static::_decode($value); } return $newDict; } return $data; }