Skip to content

Commit 64f3f0f

Browse files
committed
Merge pull request #68 from lucianocn/master
Added enable/disable Parse curl exceptions
2 parents 8ea0a9a + c55465c commit 64f3f0f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/Parse/ParseClient.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ final class ParseClient
3434
*/
3535
private static $masterKey;
3636

37+
/**
38+
* @var - Boolean for Enable/Disable curl exceptions.
39+
*/
40+
private static $enableCurlExceptions;
41+
3742
/**
3843
* @var ParseStorageInterface Object for managing persistence
3944
*/
@@ -48,20 +53,22 @@ final class ParseClient
4853
/**
4954
* Parse\Client::initialize, must be called before using Parse features.
5055
*
51-
* @param string $app_id Parse Application ID
52-
* @param string $rest_key Parse REST API Key
53-
* @param string $master_key Parse Master Key
56+
* @param string $app_id Parse Application ID
57+
* @param string $rest_key Parse REST API Key
58+
* @param string $master_key Parse Master Key
59+
* @param string $enableCurlExceptions Enable or disable Parse curl exceptions
5460
*
5561
* @return null
5662
*/
57-
public static function initialize($app_id, $rest_key, $master_key)
63+
public static function initialize($app_id, $rest_key, $master_key, $enableCurlExceptions = true)
5864
{
5965
ParseUser::registerSubclass();
6066
ParseRole::registerSubclass();
6167
ParseInstallation::registerSubclass();
6268
self::$applicationId = $app_id;
6369
self::$restKey = $rest_key;
6470
self::$masterKey = $master_key;
71+
self::$enableCurlExceptions = $enableCurlExceptions;
6572
if (!static::$storage) {
6673
if (session_status() === PHP_SESSION_ACTIVE) {
6774
self::setStorage(new ParseSessionStorage());
@@ -247,7 +254,11 @@ public static function _request($method, $relativeUrl, $sessionToken = null,
247254
$status = curl_getinfo($rest, CURLINFO_HTTP_CODE);
248255
$contentType = curl_getinfo($rest, CURLINFO_CONTENT_TYPE);
249256
if (curl_errno($rest)) {
250-
throw new ParseException(curl_error($rest), curl_errno($rest));
257+
if (self::$enableCurlExceptions) {
258+
throw new ParseException(curl_error($rest), curl_errno($rest));
259+
} else {
260+
return false;
261+
}
251262
}
252263
curl_close($rest);
253264
if (strpos($contentType, 'text/html') !== false) {
@@ -280,7 +291,7 @@ public static function setStorage(ParseStorageInterface $storageObject)
280291
/**
281292
* ParseClient::getStorage, will return the storage object used for
282293
* persistence.
283-
294+
*
284295
* @return ParseStorageInterface
285296
*/
286297
public static function getStorage()

0 commit comments

Comments
 (0)