本文整理汇总了PHP中Parse\ParseClient::getMountPath方法的典型用法代码示例。如果您正苦于以下问题:PHP ParseClient::getMountPath方法的具体用法?PHP ParseClient::getMountPath怎么用?PHP ParseClient::getMountPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parse\ParseClient
的用法示例。
在下文中一共展示了ParseClient::getMountPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deepSave
/**
* Save object and unsaved children within.
*
* @param ParseObject|array $target
* @param bool $useMasterKey Whether to use the Master Key.
*
* @throws Exception
* @throws ParseAggregateException
* @throws ParseException
*/
private static function deepSave($target, $useMasterKey = false)
{
$unsavedChildren = [];
$unsavedFiles = [];
static::findUnsavedChildren($target, $unsavedChildren, $unsavedFiles);
$sessionToken = null;
if (ParseUser::getCurrentUser()) {
$sessionToken = ParseUser::getCurrentUser()->getSessionToken();
}
foreach ($unsavedFiles as &$file) {
$file->save();
}
$objects = [];
// 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 = [];
$newRemaining = [];
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 = [];
foreach ($batch as $obj) {
$json = $obj->getSaveJSON();
$method = 'POST';
$path = 'classes/' . $obj->getClassName();
if ($obj->getObjectId()) {
$path .= '/' . $obj->getObjectId();
$method = 'PUT';
}
$requests[] = ['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 {
foreach ($requests as &$r) {
$r['path'] = '/' . ParseClient::getMountPath() . $r['path'];
}
$result = ParseClient::_request('POST', 'batch', $sessionToken, json_encode(['requests' => $requests]), $useMasterKey);
$errorCollection = [];
foreach ($batch as $key => &$obj) {
if (isset($result[$key]['success'])) {
$obj->mergeAfterSave($result[$key]['success']);
} elseif (isset($result[$key]['error'])) {
$response = $result[$key];
$error = $response['error']['error'];
$code = isset($response['error']['code']) ? $response['error']['code'] : -1;
$errorCollection[] = ['error' => $error, 'code' => $code, 'object' => $obj];
} else {
$errorCollection[] = ['error' => 'Unknown error in batch save.', 'code' => -1, 'object' => $obj];
}
}
if (count($errorCollection)) {
throw new ParseAggregateException('Errors during batch save.', $errorCollection);
}
}
}
}