-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCompose.php
72 lines (69 loc) · 2.01 KB
/
Compose.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
<?php
namespace Luracast\Restler;
/**
* Default Composer to provide standard structure for all HTTP responses
*
* @category Framework
* @package Restler
* @subpackage result
* @author R.Arul Kumaran <[email protected]>
* @copyright 2010 Luracast
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://luracast.com/products/restler/
*
*/
class Compose implements iCompose
{
/**
* @var bool When restler is not running in production mode, this value will
* be checked to include the debug information on error response
*/
public static $includeDebugInfo = true;
/**
* Current Restler instance
* Injected at runtime
*
* @var Restler
*/
public $restler;
/**
* Result of an api call is passed to this method
* to create a standard structure for the data
*
* @param mixed $result can be a primitive or array or object
*
* @return mixed
*/
public function response($result)
{
//TODO: check Defaults::language and change result accordingly
return $result;
}
/**
* When the api call results in RestException this method
* will be called to return the error message
*
* @param RestException $exception exception that has reasons for failure
*
* @return array
*/
public function message(RestException $exception)
{
//TODO: check Defaults::language and change result accordingly
$r = array(
'error' => array(
'code' => $exception->getCode(),
'message' => $exception->getErrorMessage(),
) + $exception->getDetails()
);
if (!Scope::get('Restler')->getProductionMode() && self::$includeDebugInfo) {
$r += array(
'debug' => array(
'source' => $exception->getSource(),
'stages' => $exception->getStages(),
)
);
}
return $r;
}
}