-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrest.php.dist
60 lines (55 loc) · 2.11 KB
/
rest.php.dist
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
<?php
header('Content-Type: application/json; charset=utf-8');
// initialization script
require_once 'init.php';
class AdiantiRestServer
{
public static function run($request)
{
$input = json_decode(file_get_contents("php://input"));
$class = isset($request['class']) ? $request['class'] : '';
$method = isset($request['method']) ? $request['method'] : '';
$request = array_merge($request, (array) $input);
$response = NULL;
// aqui implementar mecanismo de controle !!
if (get_parent_class($class) !== 'Adianti\Service\AdiantiRecordService')
{
return json_encode( array('status' => 'error',
'data' => _t('Permission denied')));
}
try
{
if (class_exists($class))
{
if (method_exists($class, $method))
{
$rf = new ReflectionMethod($class, $method);
if ($rf->isStatic())
{
$response = call_user_func(array($class, $method), $request);
}
else
{
$response = call_user_func(array(new $class($request), $method), $request);
}
return json_encode( array('status' => 'success', 'data' => $response));
}
else
{
$error_message = AdiantiCoreTranslator::translate('Method ^1 not found', "$class::$method");
return json_encode( array('status' => 'error', 'data' => $error_message));
}
}
else
{
$error_message = AdiantiCoreTranslator::translate('Class ^1 not found', $class);
return json_encode( array('status' => 'error', 'data' => $error_message));
}
}
catch (Exception $e)
{
return json_encode( array('status' => 'error', 'data' => $e->getMessage()));
}
}
}
print AdiantiRestServer::run($_REQUEST);