@@ -24,14 +24,14 @@ final class ParseClient
24
24
*
25
25
* @var string
26
26
*/
27
- private static $ serverURL = ' https://api.parse.com/ ' ;
27
+ private static $ serverURL = null ;
28
28
29
29
/**
30
30
* The mount path for the current parse server
31
31
*
32
32
* @var string
33
33
*/
34
- private static $ mountPath = " 1/ " ;
34
+ private static $ mountPath = null ;
35
35
36
36
/**
37
37
* The application id.
@@ -193,6 +193,24 @@ public static function setServerURL($serverURL, $mountPath)
193
193
}
194
194
}
195
195
196
+ /**
197
+ * Clears the existing server url.
198
+ * Used primarily for testing purposes.
199
+ */
200
+ public static function _clearServerURL ()
201
+ {
202
+ self ::$ serverURL = null ;
203
+ }
204
+
205
+ /**
206
+ * Clears the existing mount path.
207
+ * Used primarily for testing purposes.
208
+ */
209
+ public static function _clearMountPath ()
210
+ {
211
+ self ::$ mountPath = null ;
212
+ }
213
+
196
214
/**
197
215
* Sets the Http client to use for requests
198
216
*
@@ -408,6 +426,9 @@ public static function _request(
408
426
$ httpClient ->setCAFile (self ::$ caFile );
409
427
}
410
428
429
+ // verify the server url and mount path have been set
430
+ self ::assertServerInitialized ();
431
+
411
432
if ($ appRequest ) {
412
433
// ** 'app' requests are not available in open source parse-server
413
434
self ::assertAppInitialized ();
@@ -570,6 +591,30 @@ public static function _unsetStorage()
570
591
self ::$ storage = null ;
571
592
}
572
593
594
+ /**
595
+ * Asserts that the server and mount path have been initialized
596
+ *
597
+ * @throws Exception
598
+ */
599
+ private static function assertServerInitialized ()
600
+ {
601
+ if (self ::$ serverURL === null ) {
602
+ throw new Exception (
603
+ 'Missing a valid server url. ' .
604
+ 'You must call ParseClient::setServerURL( \'https://your.parse-server.com \', \'/parse \') ' .
605
+ ' before making any requests. '
606
+ );
607
+ }
608
+
609
+ if (self ::$ mountPath === null ) {
610
+ throw new Exception (
611
+ 'Missing a valid mount path. ' .
612
+ 'You must call ParseClient::setServerURL( \'https://your.parse-server.com \', \'/parse \') ' .
613
+ ' before making any requests. '
614
+ );
615
+ }
616
+ }
617
+
573
618
/**
574
619
* Asserts that the sdk has been initialized with a valid application id
575
620
*
@@ -579,7 +624,7 @@ private static function assertParseInitialized()
579
624
{
580
625
if (self ::$ applicationId === null ) {
581
626
throw new Exception (
582
- 'You must call Parse ::initialize() before making any requests. '
627
+ 'You must call ParseClient ::initialize() before making any requests. '
583
628
);
584
629
}
585
630
}
@@ -593,7 +638,7 @@ private static function assertAppInitialized()
593
638
{
594
639
if (self ::$ accountKey === null || empty (self ::$ accountKey )) {
595
640
throw new Exception (
596
- 'You must call Parse ::initialize(..., $accountKey) before making any app requests. ' .
641
+ 'You must call ParseClient ::initialize(..., $accountKey) before making any app requests. ' .
597
642
'Your account key must not be null or empty. '
598
643
);
599
644
}
0 commit comments