@@ -24,14 +24,14 @@ final class ParseClient
2424 *
2525 * @var string
2626 */
27- private static $ serverURL = ' https://api.parse.com/ ' ;
27+ private static $ serverURL = null ;
2828
2929 /**
3030 * The mount path for the current parse server
3131 *
3232 * @var string
3333 */
34- private static $ mountPath = " 1/ " ;
34+ private static $ mountPath = null ;
3535
3636 /**
3737 * The application id.
@@ -193,6 +193,24 @@ public static function setServerURL($serverURL, $mountPath)
193193 }
194194 }
195195
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+
196214 /**
197215 * Sets the Http client to use for requests
198216 *
@@ -408,6 +426,9 @@ public static function _request(
408426 $ httpClient ->setCAFile (self ::$ caFile );
409427 }
410428
429+ // verify the server url and mount path have been set
430+ self ::assertServerInitialized ();
431+
411432 if ($ appRequest ) {
412433 // ** 'app' requests are not available in open source parse-server
413434 self ::assertAppInitialized ();
@@ -570,6 +591,30 @@ public static function _unsetStorage()
570591 self ::$ storage = null ;
571592 }
572593
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+
573618 /**
574619 * Asserts that the sdk has been initialized with a valid application id
575620 *
@@ -579,7 +624,7 @@ private static function assertParseInitialized()
579624 {
580625 if (self ::$ applicationId === null ) {
581626 throw new Exception (
582- 'You must call Parse ::initialize() before making any requests. '
627+ 'You must call ParseClient ::initialize() before making any requests. '
583628 );
584629 }
585630 }
@@ -593,7 +638,7 @@ private static function assertAppInitialized()
593638 {
594639 if (self ::$ accountKey === null || empty (self ::$ accountKey )) {
595640 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. ' .
597642 'Your account key must not be null or empty. '
598643 );
599644 }
0 commit comments