@@ -198,6 +198,20 @@ Since the version has been explicitly specified using options, the call will be
198
198
Since the version has been explicitly specified, the call will be made against version ` 3 ` .
199
199
200
200
$api->v3->user->login(array("login" => "test", "password" => "test"));
201
+
202
+ ## Events
203
+
204
+ This library emits the following events:
205
+
206
+ * ** success** Emitted when a call succeeds.
207
+ * ** error** Emitted when a call results in an error.
208
+ * ** unauthorized** Emitted when a call results in an authentication error. Emitted before emitting the * error* event.
209
+
210
+ ### Listening to events
211
+
212
+ $api->on('success', function($sender, $call_context, $result){
213
+ echo(sprintf("Call to %s.%s resulted in %s", $call_context->service, $call_context->method, json_encode($result)));
214
+ });
201
215
202
216
## Error handling
203
217
@@ -235,6 +249,21 @@ Setting `throw_errors` to `false` is more of a way to tell the client to be sile
235
249
}
236
250
}
237
251
252
+ ### Intercepting errors with events
253
+
254
+ #### All errors
255
+
256
+ $api->on('error', function($sender, $call_context, $error){
257
+ echo(sprintf("Call to %s.%s resulted in error %s (%s)", $call_context->service, $call_context->method, $error->message, $error->error_code)));
258
+ });
259
+
260
+ #### Only unauthorized events
261
+
262
+ $api->on('unauthorized', function($sender, $call_context, $error){
263
+ header("Location: /login.php");
264
+ die();
265
+ });
266
+
238
267
## Solving issues
239
268
240
269
### See what is being sent to/from UserApp
@@ -285,6 +314,7 @@ Is exactly the same as:
285
314
286
315
* PHP >= 5.3.2
287
316
* [ cURL] ( http://php.net/manual/en/book.curl.php )
317
+ * [ sabre/event] ( https://github.com/fruux/sabre-event )
288
318
289
319
## License
290
320
0 commit comments