2020-04-24 16:37:05 +00:00
|
|
|
<?php
|
2020-04-24 16:58:00 +00:00
|
|
|
class ApiCOntroller {
|
2020-04-24 16:37:05 +00:00
|
|
|
private $data = [];
|
|
|
|
public $httpCode = 200;
|
|
|
|
public $autenticated = false;
|
|
|
|
|
|
|
|
|
2020-04-24 16:58:00 +00:00
|
|
|
function __construct() {
|
|
|
|
$this->headers = $_SERVER;
|
2020-04-24 16:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function requireAuth(){
|
|
|
|
if (isset($this->headers['HTTP_AUTHORIZATION'])) {
|
|
|
|
$this->autenticated = $this->apiManager->validateToken(explode(' ', $this->headers['HTTP_AUTHORIZATION'])[1]);
|
|
|
|
} else {
|
|
|
|
$error = new ApiError();
|
|
|
|
$error->code = "missing_token_header";
|
|
|
|
$error->message = "Missing Token in Header";
|
|
|
|
$error->hint = "check paiload header for 'token'";
|
|
|
|
echo json_encode($error);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 17:05:18 +00:00
|
|
|
function response($data = [], $httpCode = '200'){
|
|
|
|
http_response_code($httpCode);
|
|
|
|
echo json_encode($data);
|
2020-04-24 16:37:05 +00:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|