/** * Determines whether the current session token is revocable. * This method is useful for migrating an existing app to use * revocable sessions. * * @return boolean */ public static function isCurrentSessionRevocable() { $user = ParseUser::getCurrentUser(); if ($user) { return self::_isRevocable($user->getSessionToken()); } }
/** * Makes a call to a Cloud function * * @param string $name Cloud function name * @param array $data Parameters to pass * @param boolean $useMasterKey Whether to use the Master Key * * @return mixed */ public static function run($name, $data = array(), $useMasterKey = false) { $sessionToken = null; if (ParseUser::getCurrentUser()) { $sessionToken = ParseUser::getCurrentUser()->getSessionToken(); } $response = ParseClient::_request('POST', '/1/functions/' . $name, $sessionToken, json_encode(ParseClient::_encode($data, null, false)), $useMasterKey); return ParseClient::_decode($response['result']); }
/** * 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; }
/** * Returns true if this user is the current user. * * @return boolean */ public function isCurrent() { if (ParseUser::getCurrentUser() && $this->getObjectId()) { if ($this->getObjectId() == ParseUser::getCurrentUser()->getObjectId()) { return true; } } return false; }
/** * Save Object and unsaved children within. * * @param $target * @param bool $useMasterKey Whether to use the Master Key. * * @return null * * @throws ParseException */ private static function deepSave($target, $useMasterKey = false) { $unsavedChildren = array(); $unsavedFiles = array(); static::findUnsavedChildren($target, $unsavedChildren, $unsavedFiles); $sessionToken = null; if (ParseUser::getCurrentUser()) { $sessionToken = ParseUser::getCurrentUser()->getSessionToken(); } foreach ($unsavedFiles as &$file) { $file->save(); } $objects = array(); // Get the set of unique objects among the children. foreach ($unsavedChildren as &$obj) { if (!in_array($obj, $objects, true)) { $objects[] = $obj; } } $remaining = $objects; while (count($remaining) > 0) { $batch = array(); $newRemaining = array(); foreach ($remaining as $key => &$object) { if (count($batch) > 40) { $newRemaining[] = $object; continue; } if ($object->canBeSerialized()) { $batch[] = $object; } else { $newRemaining[] = $object; } } $remaining = $newRemaining; if (count($batch) === 0) { throw new Exception("Tried to save a batch with a cycle."); } $requests = array(); foreach ($batch as $obj) { $json = $obj->getSaveJSON(); $method = 'POST'; $path = '/1/classes/' . $obj->getClassName(); if ($obj->getObjectId()) { $path .= '/' . $obj->getObjectId(); $method = 'PUT'; } $requests[] = array('method' => $method, 'path' => $path, 'body' => $json); } if (count($requests) === 1) { $req = $requests[0]; $result = ParseClient::_request($req['method'], $req['path'], $sessionToken, json_encode($req['body']), $useMasterKey); $batch[0]->mergeAfterSave($result); } else { $result = ParseClient::_request('POST', '/1/batch', $sessionToken, json_encode(array("requests" => $requests)), $useMasterKey); $errorCollection = array(); foreach ($batch as $key => &$obj) { if (isset($result[$key]['success'])) { $obj->mergeAfterSave($result[$key]['success']); } else { if (isset($result[$key]['error'])) { $response = $result[$key]; $error = $response['error']['error']; $code = isset($response['error']['code']) ? $response['error']['code'] : -1; $errorCollection[] = array('error' => $error, 'code' => $code, 'object' => $obj); } else { $errorCollection[] = array('error' => 'Unknown error in batch save.', 'code' => -1, 'object' => $obj); } } } if (count($errorCollection)) { throw new ParseAggregateException("Errors during batch save.", $errorCollection); } } } }
/** * Get the defaultACL. * * @return ParseACL * @ignore */ public static function _getDefaultACL() { if (self::$defaultACLUsesCurrentUser && self::$defaultACL) { $last = self::$lastCurrentUser ? clone self::$lastCurrentUser : null; if (!ParseUser::getCurrentUser()) { return self::$defaultACL; } if ($last != ParseUser::getCurrentUser()) { self::$defaultACLWithCurrentUser = clone self::$defaultAC; self::$defaultACLWithCurrentUser->_setShared(true); self::$defaultACLWithCurrentUser->setUserReadAccess(ParseUser::getCurrentUser(), true); self::$defaultACLWithCurrentUser->setUserWriteAccess(ParseUser::getCurrentUser(), true); self::$lastCurrentUser = clone ParseUser::getCurrentUser(); } return self::$defaultACLWithCurrentUser; } return self::$defaultACL; }