-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.php
More file actions
26 lines (24 loc) · 1.06 KB
/
Copy pathapi.php
File metadata and controls
26 lines (24 loc) · 1.06 KB
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
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/src/includes.php');
if(!isset($_GET['endpoint']) || !$_GET['endpoint']){
http_response_code(400);
exit(1);
// throw new exception('Status code: 400');//Raise 400 error, bad request
}
$serializer = SerializerFactory::getSerializer($_GET['endpoint']);
if($serializer && is_callable(array($serializer, 'getData'))){ //TODO: create abstract serializer class and to check that $serializer is instanceOf it
$data = $serializer->getData($_GET);//get is actually supoer global, but nvm that, it is probper to pass the request as parameter to the serializer
}
else{
http_response_code(400);
exit(1);
// throw new exception('Status code: 400');//raid 400, bad request, TODO: catch this exception and uncomment
}
if(isset($data) && isset($data['list']) && sizeof($data['list']) > 0){
Router::Render($_GET['endpoint'], $data);
}
else{
$fullName = isset($data, $data['__fullName']) ? $data['__fullName'] : null;
Router::RenderEmptyResultSet($_GET['endpoint'], $fullName );
}
?>