-
Notifications
You must be signed in to change notification settings - Fork 2
/
apiconsultas.php
42 lines (36 loc) · 1.33 KB
/
apiconsultas.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
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type, Current");
header('Access-Control-Allow-Credentials: false');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header("Content-type: application/json");
define('APP_PATH', realpath(dirname(__FILE__)));
//error_log('path : '.APP_PATH);
require_once APP_PATH.'/classes/api/APIFactory.php';
$method = $_SERVER['REQUEST_METHOD'];
$info = (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != "") ? $_SERVER['PATH_INFO'] : $_SERVER['REQUEST_URI'];
if($info == NULL || $info == ""){
http_response_code(404);
$message = "Requisição inválida"; //array("message" => "Requisição inválida");
echo json_encode($message);
}
else {
require_once APP_PATH.'/classes/base/main/Logger.php';
Logger::startLogger();
$requestPaths = explode('/', trim($info,'/'));
/*
* Remove versão de url de 0 até 255 (/vn/). Exemplos:
* /v1/consultas => /consultas
* /v255/members => /members
*/
function removeVersion($pathItem) {
preg_match('/^[v][0-9]?[0-9]?[0-9]$/', $pathItem, $matches); // v1, v2, ..., v999
if ( count($matches) > 0 ) return;
else return $pathItem;
}
$request = array_filter($requestPaths, 'removeVersion');
$result = NULL;
$result = APIFactory::executeRequest($method, $request, TRUE);
echo $result;
}
?>