This repository has been archived by the owner on Feb 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
/
parseObject.php
87 lines (70 loc) · 1.74 KB
/
parseObject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
class parseObject extends parseRestClient{
public $_includes = array();
private $_className = '';
public function __construct($class=''){
if($class != ''){
$this->_className = $class;
}
else{
$this->throwError('include the className when creating a parseObject');
}
parent::__construct();
}
public function __set($name,$value){
if($name != '_className'){
$this->data[$name] = $value;
}
}
public function save(){
if(count($this->data) > 0 && $this->_className != ''){
$request = $this->request(array(
'method' => 'POST',
'requestUrl' => 'classes/'.$this->_className,
'data' => $this->data,
));
return $request;
}
}
public function get($id){
if($this->_className != '' || !empty($id)){
$request = $this->request(array(
'method' => 'GET',
'requestUrl' => 'classes/'.$this->_className.'/'.$id
));
if(!empty($this->_includes)){
$request['include'] = implode(',', $this->_includes);
}
return $request;
}
}
public function update($id){
if($this->_className != '' || !empty($id)){
$request = $this->request(array(
'method' => 'PUT',
'requestUrl' => 'classes/'.$this->_className.'/'.$id,
'data' => $this->data,
));
return $request;
}
}
public function increment($field,$amount){
$this->data[$field] = $this->dataType('increment', $amount);
}
public function decrement($id){
$this->data[$field] = $this->dataType('decrement', $amount);
}
public function delete($id){
if($this->_className != '' || !empty($id)){
$request = $this->request(array(
'method' => 'DELETE',
'requestUrl' => 'classes/'.$this->_className.'/'.$id
));
return $request;
}
}
public function addInclude($name){
$this->_includes[] = $name;
}
}
?>