1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* GenericResult Result superclass. |
4
|
|
|
* |
5
|
|
|
* @package Elgg.Core |
6
|
|
|
* @subpackage WebServicesAPI |
7
|
|
|
*/ |
8
|
|
|
abstract class GenericResult { |
9
|
|
|
/** |
10
|
|
|
* The status of the result. |
11
|
|
|
* @var int |
12
|
|
|
*/ |
13
|
|
|
private $status_code; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Message returned along with the status which is almost always an error message. |
17
|
|
|
* This must be human readable, understandable and localised. |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $message; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Result store. |
24
|
|
|
* Attach result specific informaton here. |
25
|
|
|
* |
26
|
|
|
* @var mixed. Should probably be an object of some sort. |
27
|
|
|
*/ |
|
|
|
|
28
|
|
|
private $result; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Set a status code and optional message. |
32
|
|
|
* |
33
|
|
|
* @param int $status The status code. |
34
|
|
|
* @param string $message The message. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
2 |
|
protected function setStatusCode($status, $message = "") { |
39
|
2 |
|
$this->status_code = $status; |
40
|
2 |
|
$this->message = $message; |
41
|
2 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Set the result. |
45
|
|
|
* |
46
|
|
|
* @param mixed $result The result |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
2 |
|
protected function setResult($result) { |
51
|
2 |
|
$this->result = $result; |
52
|
2 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Return the current status code |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
2 |
|
protected function getStatusCode() { |
60
|
2 |
|
return $this->status_code; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Return the current status message |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
2 |
|
protected function getStatusMessage() { |
69
|
2 |
|
return $this->message; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Return the current result |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
2 |
|
protected function getResult() { |
78
|
2 |
|
return $this->result; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Serialise to a standard class. |
83
|
|
|
* |
84
|
|
|
* DEVNOTE: The API is only interested in data, we can not easily serialise |
85
|
|
|
* custom classes without the need for 1) the other side being PHP, 2) you need to have the class |
86
|
|
|
* definition installed, 3) its the right version! |
87
|
|
|
* |
88
|
|
|
* Therefore, I'm not bothering. |
89
|
|
|
* |
90
|
|
|
* Override this to include any more specific information, however api results |
91
|
|
|
* should be attached to the class using setResult(). |
92
|
|
|
* |
93
|
|
|
* if ELGG_DEBUG is set then additional information about the runtime environment and |
94
|
|
|
* authentication will be returned. |
95
|
|
|
* |
96
|
|
|
* @return stdClass Object containing the serialised result. |
97
|
|
|
*/ |
98
|
2 |
|
public function export() { |
99
|
2 |
|
global $ERRORS, $_PAM_HANDLERS_MSG; |
100
|
|
|
|
101
|
2 |
|
$result = new stdClass; |
102
|
|
|
|
103
|
2 |
|
$result->status = $this->getStatusCode(); |
104
|
2 |
|
if ($this->getStatusMessage() != "") { |
105
|
|
|
$result->message = $this->getStatusMessage(); |
106
|
|
|
} |
107
|
|
|
|
108
|
2 |
|
$resultdata = $this->getResult(); |
109
|
2 |
|
if (isset($resultdata)) { |
110
|
2 |
|
$result->result = $resultdata; |
111
|
|
|
} |
112
|
|
|
|
113
|
2 |
|
if (elgg_get_config('debug')) { |
114
|
2 |
|
if (!empty($ERRORS)) { |
115
|
|
|
$result->runtime_errors = $ERRORS; |
116
|
|
|
} |
117
|
|
|
|
118
|
2 |
|
if (!empty($_PAM_HANDLERS_MSG)) { |
119
|
|
|
$result->pam = $_PAM_HANDLERS_MSG; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
2 |
|
return $result; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|