File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,30 @@ function ($object) use (&$result) {
306
306
return $ result ;
307
307
}
308
308
309
+ /**
310
+ * Returns true if this object exists on the Server
311
+ *
312
+ * @param bool $useMasterKey Whether to use the Master Key.
313
+ *
314
+ * @return bool
315
+ */
316
+ public function exists ($ useMasterKey = false )
317
+ {
318
+ if (!$ this ->objectId ) {
319
+ return false ;
320
+ }
321
+ try {
322
+ $ query = new ParseQuery ($ this ->className );
323
+ $ query ->get ($ this ->objectId , $ useMasterKey );
324
+ return true ;
325
+ } catch (Exception $ e ) {
326
+ if ($ e ->getCode () === 101 ) {
327
+ return false ;
328
+ }
329
+ throw $ e ;
330
+ }
331
+ }
332
+
309
333
/**
310
334
* Validate and set a value for an object key.
311
335
*
Original file line number Diff line number Diff line change @@ -1775,4 +1775,19 @@ public function testUnrecognizedOp()
1775
1775
];
1776
1776
ParseObject::decode ($ encoded );
1777
1777
}
1778
+
1779
+ /**
1780
+ * Tests if object exists
1781
+ *
1782
+ * @group object-exists
1783
+ */
1784
+ public function testObjectExists ()
1785
+ {
1786
+ $ obj = new ParseObject ('TestClass ' );
1787
+ $ this ->assertEquals ($ obj ->exists (), false );
1788
+ $ obj ->save ();
1789
+ $ this ->assertEquals ($ obj ->exists (), true );
1790
+ $ obj ->destroy ();
1791
+ $ this ->assertEquals ($ obj ->exists (), false );
1792
+ }
1778
1793
}
You can’t perform that action at this time.
0 commit comments