/** * 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']); }
/** * Merges data received from the server. * * @param array $data Data retrieved from server. * @param bool $completeData Fetch all data or not. * * @return null */ private function mergeFromServer($data, $completeData = true) { $this->hasBeenFetched = $this->hasBeenFetched || $completeData ? true : false; $this->mergeMagicFields($data); foreach ($data as $key => $value) { if ($key === '__type' && $value === 'className') { continue; } $decodedValue = ParseClient::_decode($value); if (is_array($decodedValue)) { if (isset($decodedValue['__type'])) { if ($decodedValue['__type'] === 'Relation') { $className = $decodedValue['className']; $decodedValue = new ParseRelation($this, $key, $className); } } if ($key == 'ACL') { $decodedValue = ParseACL::_createACLFromJSON($decodedValue); } } $this->serverData[$key] = $decodedValue; $this->dataAvailability[$key] = true; } if (!$this->updatedAt && $this->createdAt) { $this->updatedAt = $this->createdAt; } }
/** * 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) { $response = ParseClient::_request('POST', '/1/functions/' . $name, null, json_encode(ParseClient::_encode($data, null, false)), $useMasterKey); return ParseClient::_decode($response['result']); }