2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
|
|
|
|
2020-07-28 16:37:44 +02:00
|
|
|
use API\Response;
|
|
|
|
|
2017-08-28 18:15:52 +02:00
|
|
|
function serverError()
|
|
|
|
{
|
2017-08-29 12:42:42 +02:00
|
|
|
$error = error_get_last();
|
|
|
|
if ($error['type'] == E_ERROR) {
|
|
|
|
ob_end_clean();
|
2019-07-19 15:23:00 +02:00
|
|
|
echo Response::error('serverError');
|
2017-08-28 18:24:45 +02:00
|
|
|
}
|
2017-08-28 18:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Gestione degli errori
|
|
|
|
set_error_handler('serverError');
|
2017-08-28 18:24:45 +02:00
|
|
|
register_shutdown_function('serverError');
|
|
|
|
|
|
|
|
include_once __DIR__.'/../core.php';
|
|
|
|
|
2020-07-17 16:59:03 +02:00
|
|
|
// Disabilita la sessione per l'API
|
2017-08-28 18:24:45 +02:00
|
|
|
session_write_close();
|
2017-08-28 18:15:52 +02:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Permesso di accesso all'API da ogni dispositivo
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
2018-08-01 15:15:14 +02:00
|
|
|
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
try {
|
2019-07-19 15:23:00 +02:00
|
|
|
$response = Response::manage();
|
2017-08-04 16:28:16 +02:00
|
|
|
} catch (Exception $e) {
|
2018-07-27 12:17:17 +02:00
|
|
|
// Log dell'errore
|
|
|
|
$logger = logger();
|
|
|
|
$logger->addRecord(\Monolog\Logger::ERROR, $e);
|
|
|
|
|
2019-07-19 15:23:00 +02:00
|
|
|
$response = Response::error('serverError');
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2018-08-01 15:15:14 +02:00
|
|
|
// Richiesta OPTIONS (controllo da parte del dispositivo)
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
2019-07-19 15:23:00 +02:00
|
|
|
$response = Response::error('ok');
|
2018-08-01 15:15:14 +02:00
|
|
|
}
|
|
|
|
|
2018-08-09 15:33:01 +02:00
|
|
|
json_decode($response);
|
2018-06-29 15:57:12 +02:00
|
|
|
|
|
|
|
// Impostazioni di Content-Type e Charset Header
|
|
|
|
if (json_last_error() == JSON_ERROR_NONE) {
|
|
|
|
header('Content-Type: application/json; charset=UTF-8');
|
|
|
|
} else {
|
|
|
|
header('Content-Type: text/plain; charset=UTF-8');
|
|
|
|
}
|
|
|
|
|
2018-01-12 16:23:26 +01:00
|
|
|
// Stampa dei risultati
|
2018-08-09 15:33:01 +02:00
|
|
|
echo $response;
|